diff --git a/.gitignore b/.gitignore index b30a728..1fa929a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ *.o bin +*.d.out diff --git a/makefile b/makefile index e7f53a6..4650bd7 100644 --- a/makefile +++ b/makefile @@ -6,3 +6,5 @@ FLAGS := -g -w $(INCLUDE_PATHS) all: $(SRC) $(COMPILER) $(FLAGS) $(SRC) -ofbin/dfmt +test: bin/dfmt + cd tests && ./test.sh diff --git a/tests/frontpage.d b/tests/frontpage.d new file mode 100644 index 0000000..e0062a6 --- /dev/null +++ b/tests/frontpage.d @@ -0,0 +1,15 @@ +// Computes average line length for standard input. +import std.stdio; + +void main() +{ + ulong lines = 0; + double sumLength = 0; + foreach (line; stdin.byLine()) + { + ++lines; + sumLength += line.length; + } + writeln("Average line length: ", + lines ? sumLength / lines : 0); +} diff --git a/tests/frontpage.d.ref b/tests/frontpage.d.ref new file mode 100644 index 0000000..654056d --- /dev/null +++ b/tests/frontpage.d.ref @@ -0,0 +1,15 @@ +// Computes average line length for standard input. +import std.stdio; + +void main() +{ + ulong lines = 0; + double sumLength = 0; + foreach (line; stdin.byLine()) + { + ++lines; + sumLength += line.length; + } + writeln("Average line length: ", lines ? sumLength / lines:0); +} + diff --git a/tests/hello.d b/tests/hello.d new file mode 100644 index 0000000..f04ca6d --- /dev/null +++ b/tests/hello.d @@ -0,0 +1 @@ +import std.stdio; void main() { writeln("Hello, world without explicit compilations!"); } diff --git a/tests/hello.d.ref b/tests/hello.d.ref new file mode 100644 index 0000000..3894114 --- /dev/null +++ b/tests/hello.d.ref @@ -0,0 +1,7 @@ +import std.stdio; + +void main() +{ + writeln("Hello, world without explicit compilations!"); +} + diff --git a/tests/test.sh b/tests/test.sh new file mode 100755 index 0000000..ea46ff2 --- /dev/null +++ b/tests/test.sh @@ -0,0 +1,8 @@ +#!/usr/bin/env bash +set -e + +for source in *.d +do + ../bin/dfmt "${source}" >"${source}.out" + diff -u "${source}.ref" "${source}.out" || echo "fail ${source}" +done