Add implementation, demo and tests for `make clean'.
[mgear/mgear.git] / testsuite
index 210274e..a0dc8aa 100755 (executable)
--- a/testsuite
+++ b/testsuite
@@ -70,6 +70,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,13 +113,20 @@ 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)
+
+clean:
+       $(call mg-clean-cmd,.)
+.PHONY: clean
 EOF
+
 cat >hc-rule.mk <<'EOF'
 $(call mg-define-rule,%,%.hc,sed -e 's_#.*$$$$__' $$< >$$t)
 EOF
@@ -232,6 +248,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 <<<NEWCONTENT # and contents still correct.
+
+# Test rebuild and clean after override removal.
+
+start_section "Rebuild after override removal"
+rm bar
+do_mgear bar
+assert_generated bar
+assert_contents bar <<'EOF' # contents of bar restored according to rule
+the bar file has a different personality
+
+# I slip through
+warn: tell me about it!
+EOF
+
+start_section "Clean after override removal"
+do_mgear clean
+assert_saw 'rm.*bar'
+assert ! [ -f bar ] # bar finally deleted
+
+# Override bar again.  Make sure an override works if bar.g doesn't exist just
+# as well as if bar.g is older than bar.
+
+start_section "Override bar before it is ever built"
+echo NEWERCONTENT >bar
+do_mgear bar
+
+assert_saw -i overrid
+assert_contents bar <<<NEWERCONTENT
+
 cd ..
 rm -rf test-zone
 echo