diff --git a/config b/config index bee03b2f..59d97fb3 100644 --- a/config +++ b/config @@ -24,6 +24,7 @@ Export("env", "use_package", "CONFIG_DEBUG", "CONFIG_VERSION") include = SConscript("include/Sconscript") + lib = SConscript("lib/Sconscript") tests = SConscript("tests/Sconscript") diff --git a/tests/Sconscript b/tests/Sconscript index f0a20aec..8567594a 100644 --- a/tests/Sconscript +++ b/tests/Sconscript @@ -2,10 +2,20 @@ Import("env") src = SConscript("src/Sconscript") -test = Command("tests.out", [], "./tests/test") -AlwaysBuild(test) -Depends(test, src) +tests = [ "version" ] + + +def Test(name): + return Command("%s.out" % name, [], "./tests/%s" % name) + +for test in tests: + t = Test(test) + Depends(t, src) + AlwaysBuild(t) + +#AlwaysBuild(test) +#Depends(test, src) #scripts = [ "print", "file", "database", "index", "filter", "idle", "playlist", # "library", "playqueue", "deck", "audio", "gui" ] diff --git a/tests/_functions b/tests/_functions new file mode 100644 index 00000000..fd4e3643 --- /dev/null +++ b/tests/_functions @@ -0,0 +1,33 @@ +#!/bin/bash +# Copyright 2014 (c) Anna Schumaker + +function read_config +{ + cat ../config | grep ^$1 | awk -F= '{print $2}' | tr -d ' ' +} + +function config_version +{ + read_config CONFIG_VERSION +} + +function config_debug +{ + read_config CONFIG_DEBUG +} + +function test_success +{ + echo "Success!" + exit 0 +} + +function test_failed +{ + echo "FAILED =(" + on_failed + exit 1 +} + +cd $(dirname $0) +echo -n "Testing $(basename $0) ... " diff --git a/tests/run_test b/tests/run_test deleted file mode 100755 index 7a7b19b4..00000000 --- a/tests/run_test +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/bash -# Copyright (c) Anna Schumaker. - -VERSION=$(cat ../config | grep ^CONFIG_VERSION | awk -F= '{print $2}' | tr -d ' ') -DEBUG=$(cat ../config | grep ^CONFIG_DEBUG | awk -F= '{print $2}' | tr -d ' ') - -function utility -{ - echo src/$1 -} - -echo -n "Running test '$1' ... " -. tests/$1 diff --git a/tests/test b/tests/test deleted file mode 100755 index 616dd660..00000000 --- a/tests/test +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/bash -# Copyright 2014 (c) Anna Schumaker. - -cd $(dirname $0) - -[ $? == 0 ] && tests=$(ls tests/) || tests="$*" - -for t in $tests; do - ./run_test $t -done diff --git a/tests/tests/version b/tests/tests/version deleted file mode 100755 index 34a2dc2c..00000000 --- a/tests/tests/version +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/bash -# Copyright 2014 (c) Anna Schumaker. - -expected=$VERSION -[ $DEBUG == "True" ] && expected="$expected-debug" - -cmd=$(utility version) -actual=$($cmd) - -if [ $expected == $actual ]; then - echo "Success!" - exit 0 -fi - -echo "FAILED =(" -echo "Expected output: $expected" -echo "Actual output: $actual" diff --git a/tests/version b/tests/version new file mode 100755 index 00000000..73762f76 --- /dev/null +++ b/tests/version @@ -0,0 +1,24 @@ +#!/bin/bash +# Copyright 2014 (c) Anna Schumaker. + +. $(dirname $0)/_functions + + +# Find version +version=$(config_version) +[ $(config_debug) == "True" ] && version="$version-debug" + + +# Run test +out=$(./src/version) + + +# Analyze result +[ "$version" == "$out" ] && test_success + +function on_failed +{ + echo " Expected version: $version" + echo " Actual version: $out" +} +test_failed