Issue 2505: fix use of pre-compiled headers when the source .cpp
[scons.git] / test / option--random.py
index b1dae0113c2624de40a4ba08505fb1ccf4073968..0e5cc6686f68b5987279c6c19f5f9292c122f378 100644 (file)
@@ -1,6 +1,6 @@
 #!/usr/bin/env python
 #
-# Copyright (c) 2001, 2002, 2003 Steven Knight
+# __COPYRIGHT__
 #
 # Permission is hereby granted, free of charge, to any person obtaining
 # a copy of this software and associated documentation files (the
 
 __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
 
+"""
+Verify that we build correctly using the --random option.
+"""
+
+import os.path
+
 import TestSCons
-import string
-import sys
 
 test = TestSCons.TestSCons()
 
-test.write('SConstruct', "")
+test.write('SConscript', """\
+def cat(env, source, target):
+    target = str(target[0])
+    source = map(str, source)
+    f = open(target, "wb")
+    for src in source:
+        f.write(open(src, "rb").read())
+    f.close()
+env = Environment(BUILDERS={'Cat':Builder(action=cat)})
+env.Cat('aaa.out', 'aaa.in')
+env.Cat('bbb.out', 'bbb.in')
+env.Cat('ccc.out', 'ccc.in')
+env.Cat('all', ['aaa.out', 'bbb.out', 'ccc.out'])
+""")
+
+test.write('aaa.in', "aaa.in\n")
+test.write('bbb.in', "bbb.in\n")
+test.write('ccc.in', "ccc.in\n")
+
+
+
+test.write('SConstruct', """\
+SetOption('random', 1)
+SConscript('SConscript')
+""")
+
+test.run(arguments = '-n -Q')
+non_random_output = test.stdout()
+
+tries = 0
+max_tries = 10
+while test.stdout() == non_random_output:
+    if tries >= max_tries:
+        print "--random generated the non-random output %s times!" % max_tries
+        test.fail_test()
+    tries = tries + 1
+    test.run(arguments = '-n -Q --random')
+
+
+
+test.write('SConstruct', """\
+SConscript('SConscript')
+""")
+
+test.run(arguments = '-n -Q')
+non_random_output = test.stdout()
+
+tries = 0
+max_tries = 10
+while test.stdout() == non_random_output:
+    if tries >= max_tries:
+        print "--random generated the non-random output %s times!" % max_tries
+        test.fail_test()
+    tries = tries + 1
+    test.run(arguments = '-n -Q --random')
+
+
+
+test.run(arguments = '-Q --random')
+
+test.must_match('all', "aaa.in\nbbb.in\nccc.in\n")
+
+test.run(arguments = '-q --random .')
+
+test.run(arguments = '-c --random .')
+
+test.must_not_exist(test.workpath('aaa.out'))
+test.must_not_exist(test.workpath('bbb.out'))
+test.must_not_exist(test.workpath('ccc.out'))
+test.must_not_exist(test.workpath('all'))
+
+test.run(arguments = '-q --random .', status = 1)
+
+test.run(arguments = '--random .')
+
+test.must_match('all', "aaa.in\nbbb.in\nccc.in\n")
+
+test.run(arguments = '-c --random .')
+
 
-test.run(arguments = '--random .',
-        stderr = "Warning:  the --random option is not yet implemented\n")
 
 test.pass_test()
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4: