~shugyousha/public-inbox

This thread contains a patchset. You're looking at the original emails, but you may wish to use the patch review UI. Review patch
1

[PATCH unixtoolstesting 1/2] Initial commit

Silvan Jegen <s.jegen@gmail.com>
Details
Message ID
<20181216102347.2260-1-s.jegen@gmail.com>
Sender timestamp
1544955826
DKIM signature
missing
Download raw message
Patch: +74 -0
---
 dirname.test   | 20 ++++++++++++++++++++
 runalltests    | 12 ++++++++++++
 test-common.sh | 42 ++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 74 insertions(+)
 create mode 100755 dirname.test
 create mode 100755 runalltests
 create mode 100644 test-common.sh

diff --git a/dirname.test b/dirname.test
new file mode 100755
index 0000000..3bc45ca
--- /dev/null
+++ b/dirname.test
@@ -0,0 +1,20 @@
#!/bin/sh

. ./test-common.sh

#            "test name"       "command to execute" "expected output"
check_stdout "dirname-noarg"   "../dirname"         "" && \
check_stderr "dirname-noarg-stderr" "../dirname" "usage: ../dirname path\n" && \
check_stdout "dirname-non-existing" "../dirname a b c" "" && \
check_stdout "dirname-slash" "../dirname /" "/\n" && \
check_stdout "dirname-dashes-slash" "../dirname -- /" "/\n" && \
check_stdout "dirname-dashes-slash-a" "../dirname -- /a" "/\n"  && \
check_stdout "dirname-doublequotes" "../dirname \"\"" ".\n" && \
check_stdout "dirname-slashes" "../dirname ///" "/\n" && \
check_stdout "dirname-a/b" "../dirname a/b" "a\n" && \
check_stdout "dirname-a/b/" "../dirname a/b/" "a\n" && \
check_stdout "dirname-a/b//" "../dirname a/b//" "a\n" && \
check_stdout "dirname-a" "../dirname a" ".\n" && \
check_stdout "dirname-a/" "../dirname a/" ".\n" && \
check_stdout "dirname-/a/b/c" "../dirname /a/b/c" "/a/b\n" && \
check_stdout "dirname-//a/b/c" "../dirname //a/b/c" "//a/b\n"
diff --git a/runalltests b/runalltests
new file mode 100755
index 0000000..99270c8
--- /dev/null
+++ b/runalltests
@@ -0,0 +1,12 @@
#!/bin/sh

for testfile in *.test; do
	./$testfile
	ret=$(expr $ret + $?)
done

if [ $ret -gt 0 ]; then
	printf "%d tests failed\n" $ret
fi

exit $ret
diff --git a/test-common.sh b/test-common.sh
new file mode 100644
index 0000000..b1d7572
--- /dev/null
+++ b/test-common.sh
@@ -0,0 +1,42 @@
check_output() {
	testname=$1
	cmdtorun=$2
	expectedoutput=$3
	usestdout=$4
	expoutfile=$(mktemp)
	actualoutfile=$(mktemp)
	ret=0

	printf "$expectedoutput" > $expoutfile
	if [ $usestdout -eq 1 ]; then
		eval $cmdtorun > $actualoutfile 2> /dev/null
	else
		eval $cmdtorun 2> $actualoutfile 1> /dev/null
	fi

	cmp $expoutfile $actualoutfile  2>&1 > /dev/null
	if [ $? -eq 1 ]; then
		printf "$testname:\n"
		printf "\tWanted:\n"
		cat $expoutfile
		printf "\n\tGot:\n"
		cat $actualoutfile
		printf "\n\n"
		ret=1
	fi
	if [ $? -eq 2 ]; then
		printf "cmp error\n"
		ret=1
	fi

	rm $expoutfile $actualoutfile
	return $ret
}

check_stdout() {
	check_output "$1" "$2" "$3" 1
}

check_stderr() {
	check_output "$1" "$2" "$3" 0
}
-- 
2.20.0

[PATCH 2/2] Add README

Silvan Jegen <s.jegen@gmail.com>
Details
Message ID
<20181216102347.2260-2-s.jegen@gmail.com>
In-Reply-To
<20181216102347.2260-1-s.jegen@gmail.com> (view parent)
Sender timestamp
1544955827
DKIM signature
missing
Download raw message
Patch: +19 -0
---
 README.md | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
 create mode 100644 README.md

diff --git a/README.md b/README.md
new file mode 100644
index 0000000..f88417d
--- /dev/null
+++ b/README.md
@@ -0,0 +1,19 @@
Unix tools testing
==================

This repo was created to contain some simple functional tests for unix tools
implementations (mostly for testing sbase[0]).


Run the tests
-------------

The "./runalltests" shell script runs all files ending with ".test". Those
files are shell scripts themselves which expect the binaries to test to
be in the parent directory.

To add more tests, simply follow the basic example in "dirname.test"
and preferrably add one "{unix-tool-to-test}.test" file for each tool
you want to write tests for.

[0] https://core.suckless.org/sbase/
-- 
2.20.0
Reply to thread Export thread (mbox)