Beginnings of a testsuite
authorBenjamin Smedberg <benjamin@smedbergs.us>
Fri, 23 Jan 2009 16:14:06 -0500
changeset 1 816a91c3caf5
parent 0 f5ab154deef2
child 2 f423decb7ebd
push id2
push userbsmedberg@mozilla.com
push date2009-01-23 22:23 +0000
Beginnings of a testsuite
tests/runtests.py
tests/var-change-flavor.mk
new file mode 100644
--- /dev/null
+++ b/tests/runtests.py
@@ -0,0 +1,47 @@
+"""
+Run the test(s) listed on the command line. If a directory is listed,
+we'll recursively walk the directory for files named .mk and run each.
+
+For each test, we simply run gmake -f test.mk. By default, make must exit
+with an exit code of 0, and must print 'TEST-PASS'.
+"""
+
+from subprocess import Popen, PIPE, STDOUT
+from optparse import OptionParser
+import os
+
+o = OptionParser()
+opts, args = o.parse_args()
+
+if len(args) == 0:
+    args = ['.']
+
+makefiles = []
+for a in args:
+    if os.path.isfile(a):
+        makefiles.append(a)
+    elif os.path.isdir(a):
+        for path, dirnames, filenames in os.walk(a):
+            for f in filenames:
+                if f.endswith('.mk'):
+                    makefiles.append('%s/%s' % (path, f))
+    else:
+        print >>sys.stderr, "Error: Unknown file on command line"
+        sys.exit(1)
+
+for makefile in makefiles:
+    print "Running: %s" % makefile,
+
+    p = Popen(['gmake', '-f', makefile], stdout=PIPE, stderr=STDOUT)
+    stdout, d = p.communicate()
+    if p.returncode != 0:
+        print "FAIL"
+        print stdout
+    if stdout.find('TEST-FAIL') != -1:
+        print "FAIL"
+        print stdout
+    elif stdout.find('TEST-PASS') != -1:
+        print "PASS"
+    else:
+        print "FAIL (no passing output)"
+        print stdout
new file mode 100644
--- /dev/null
+++ b/tests/var-change-flavor.mk
@@ -0,0 +1,12 @@
+VAR = value1
+VAR := value2
+
+VAR2 := val1
+VAR2 = val2
+
+default:
+	@test "$(flavor VAR)" = "simple"
+	@test "$(VAR)" = "value2"
+	@test "$(flavor VAR2)" = "recursive"
+	@test "$(VAR2)" = "val2"
+	@echo "TEST-PASS"