From 1c79cf3cbf2d51f2cf33745a50617009daaf1d63 Mon Sep 17 00:00:00 2001 From: Andreas Zwinkau Date: Tue, 13 Jan 2015 18:10:15 +0100 Subject: [PATCH] add simple test suite --- .gitignore | 1 + makefile | 2 ++ tests/frontpage.d | 15 +++++++++++++++ tests/frontpage.d.ref | 15 +++++++++++++++ tests/hello.d | 1 + tests/hello.d.ref | 7 +++++++ tests/test.sh | 8 ++++++++ 7 files changed, 49 insertions(+) create mode 100644 tests/frontpage.d create mode 100644 tests/frontpage.d.ref create mode 100644 tests/hello.d create mode 100644 tests/hello.d.ref create mode 100755 tests/test.sh 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