From 7c4af0626c66051722ef3e4e987bf975658fdb2a Mon Sep 17 00:00:00 2001 From: rubenwardy Date: Thu, 28 Jan 2016 01:26:32 +0000 Subject: [PATCH] Add unit testing for rufunge example scripts --- .../{hello_world.txt => hello_world.rf.txt} | 0 .../{hello_world2.txt => hello_world2.rf.txt} | 0 src/main.cpp | 12 ++++++++++-- test.sh | 19 +++++++++++++++++++ 4 files changed, 29 insertions(+), 2 deletions(-) rename examples/{hello_world.txt => hello_world.rf.txt} (100%) rename examples/{hello_world2.txt => hello_world2.rf.txt} (100%) create mode 100755 test.sh diff --git a/examples/hello_world.txt b/examples/hello_world.rf.txt similarity index 100% rename from examples/hello_world.txt rename to examples/hello_world.rf.txt diff --git a/examples/hello_world2.txt b/examples/hello_world2.rf.txt similarity index 100% rename from examples/hello_world2.txt rename to examples/hello_world2.rf.txt diff --git a/src/main.cpp b/src/main.cpp index 5b2b5e3..d334e2c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -63,7 +63,7 @@ bool run_tests() return true; } -int main() +int main(int n, char **args) { if (!run_tests()) { std::cerr << "A test failed!" << std::endl; @@ -72,9 +72,17 @@ int main() std::cerr << "All tests passed!" << std::endl; + if (n < 2) { + std::cerr << "USAGE: a path/to/rufunge/file.rf" << std::endl; + return 1; + } + + std::cerr << "Running " << args[1] << std::endl; + const char *filepath = args[1]; Canvas d; - TEST(d.readFromFile("examples/hello_world2.rf")); + if (!d.readFromFile(filepath)) + return 1; VM vm; vm.init(&d); diff --git a/test.sh b/test.sh new file mode 100755 index 0000000..1509c68 --- /dev/null +++ b/test.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +rm -rf /tmp/rufunge +mkdir /tmp/rufunge +mkdir /tmp/rufunge/examples + +for name in examples/*.rf; do + ./bin/a $name > /tmp/rufunge/$name.txt + + echo Result for $name: + cat /tmp/rufunge/$name.txt + + if cmp --silent $name.txt /tmp/rufunge/$name.txt; then + echo "Test passed: $name" + else + echo "Test failed: $name" + exit -1 + fi +done