X-Git-Url: https://mattmccutchen.net/mgear/mgear.git/blobdiff_plain/099638eb844d4da0ffba1c238ed3904d90a622bc..b811570b2cb4d27923b09d8b2e286dd234f5fab0:/testsuite diff --git a/testsuite b/testsuite index 210274e..f7ec807 100755 --- a/testsuite +++ b/testsuite @@ -32,7 +32,8 @@ function start_section { function do_mgear { echo "Running: make $*" - make "$@" 2>&1 | tee mgear.log + make --warn-undefined-variables "$@" 2>&1 | tee mgear.log + assert_not_saw 'warning: undefined variable' } function assert_contents { @@ -49,17 +50,15 @@ function assert_saw { if grep -q "$@" mgear.log; then echo "Good, saw '${@:$#}' in build log." else - echo "Expected '${@:$#}' in build log but didn't see it! Log:" - cat mgear.log + echo "Expected '${@:$#}' in build log but didn't see it!" fail fi } function assert_not_saw { if ! grep -q "$@" mgear.log; then - echo "Good, saw '${@:$#}' in build log." + echo "Good, didn't see '${@:$#}' in build log." else - echo "Did not expect '${@:$#}' in build log but saw it! Log:" - cat mgear.log + echo "Did not expect '${@:$#}' in build log but saw it!" fail fi } @@ -70,6 +69,15 @@ function assert_generated { assert_saw "$1.tmp" } +function assert { + if eval $*; then + echo "Good, $* returned true." + else + echo "Expected $* to return true but it returned false!" + fail + fi +} + function remember_mtime { while [ $# != 0 ]; do eval "orig_mtime_${1//[^A-Za-z]/}=$(stat --format=%Y $1)" @@ -104,15 +112,25 @@ function assert_not_touched { # Simple makefile for stripping two kinds of comments. # Tests an implicit rule and two competing explicit rules. # Watch those dollar signs! + cat >Makefile <<'EOF' include mgear.mk .SECONDARY: + include hc-rule.mk -$(call mg-define-rule,%,%.ssc,sleep 1 && grep 'warn' $$< && sed -e 's_//.*$$$$__' $$< >$$t) -$(call mg-define-rule,index,index.in,sort $$< >$$t) +cmd-ssc=sleep 1 && grep 'warn' $< && sed -e 's_//.*$$__' $< >$@ +$(call mg-define-rule,%,%.ssc,cmd-ssc) +cmd-index=sort $< >$@ +$(call mg-define-rule,index,index.in,cmd-index) + +clean: + $(call mg-clean-cmd,.) +.PHONY: clean EOF + cat >hc-rule.mk <<'EOF' -$(call mg-define-rule,%,%.hc,sed -e 's_#.*$$$$__' $$< >$$t) +cmd-hc=sed -e 's_$(hash).*$$__' $< >$@ +$(call mg-define-rule,%,%.hc,cmd-hc) EOF # Input files. @@ -203,10 +221,12 @@ EOF # Change the rule for # comments to strip spaces before a #. # Make sure foo is updated properly. +# Also, make sure commas in commands work properly. start_section "Command change for % <- %.hc" cat >hc-rule.mk <<'EOF' -$(call mg-define-rule,%,%.hc,sed -e 's_ *#.*$$$$__' $$< >$$t) +cmd-hc=sed -e 's, *$(hash).*$$,,' $< >$@ +$(call mg-define-rule,%,%.hc,cmd-hc) EOF do_mgear foo @@ -232,6 +252,45 @@ assert_generated foo assert_touched foo.g assert_not_touched foo +# Test cleaning. Remember, bar is still overridden. + +start_section "Cleaning" +do_mgear clean + +assert_saw 'rm.*foo' # Some sort of indication of foo's deletion +assert ! [ -f foo ] # foo deleted +assert ! [ -f foo.g ] # foo.g deleted +assert [ -f bar ] # bar not actually deleted... +assert_contents bar <<bar +do_mgear bar + +assert_saw -i overrid +assert_contents bar <<