5 # Permission is hereby granted, free of charge, to any person obtaining
6 # a copy of this software and associated documentation files (the
7 # "Software"), to deal in the Software without restriction, including
8 # without limitation the rights to use, copy, modify, merge, publish,
9 # distribute, sublicense, and/or sell copies of the Software, and to
10 # permit persons to whom the Software is furnished to do so, subject to
11 # the following conditions:
13 # The above copyright notice and this permission notice shall be included
14 # in all copies or substantial portions of the Software.
16 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
17 # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
18 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
35 test = TestSCons.TestSCons()
37 python = TestSCons.python
39 test.write('build.py', r"""
41 contents = open(sys.argv[2], 'rb').read()
42 file = open(sys.argv[1], 'wb')
47 test.write('SConstruct', """
48 B = Builder(action=r'%s build.py $TARGET $SOURCES')
49 env = Environment(BUILDERS = { 'B' : B })
50 env.B(target = 'aaa.out', source = 'aaa.in')
51 env.B(target = 'bbb.out', source = 'bbb.in')
54 test.write('aaa.in', "aaa.in\n")
55 test.write('bbb.in', "bbb.in\n")
57 test.run(arguments = '-q aaa.out', status = 1)
59 test.fail_test(os.path.exists(test.workpath('aaa.out')))
61 test.run(arguments = 'aaa.out')
63 test.fail_test(test.read('aaa.out') != "aaa.in\n")
65 test.run(arguments = '-q aaa.out', status = 0)
67 test.run(arguments = '--question bbb.out', status = 1)
69 test.fail_test(os.path.exists(test.workpath('bbb.out')))
71 test.run(arguments = 'bbb.out')
73 test.fail_test(test.read('bbb.out') != "bbb.in\n")
75 test.run(arguments = '--question bbb.out', status = 0)
78 # test -q in conjunction with Configure Tests
79 # mostly copy&paste from test/option-n.py
80 test.subdir('configure')
81 test.match_func = TestCmd.match_re_dotall
82 test.write('configure/aaa.in', 'Hello world')
83 test.write('configure/SConstruct',
84 """def userAction(target,source,env):
86 shutil.copyfile( str(source[0]), str(target[0]))
88 def strAction(target,source,env):
89 return "cp " + str(source[0]) + " " + str(target[0])
91 def CustomTest(context):
92 context.Message("Executing Custom Test ... " )
93 (ok, msg) = context.TryAction(Action(userAction,strAction),
98 env = Environment(BUILDERS={'B' : Builder(action=Action(userAction,strAction))})
100 conf = Configure( env,
101 custom_tests={'CustomTest':CustomTest},
102 conf_dir="config.test",
103 log_file="config.log")
104 if not conf.CustomTest():
109 env.B(target='aaa.out', source='aaa.in')
111 # test that conf_dir isn't created and an error is raised
113 scons: \*\*\* Cannot create configure directory "config\.test" within a dry-run\.
114 File \S+, line \S+, in \S+
116 test.run(arguments="-q aaa.out",stderr=stderr,status=2,
117 chdir=test.workpath("configure"))
118 test.fail_test(os.path.exists(test.workpath("configure", "config.test")))
119 test.fail_test(os.path.exists(test.workpath("configure", "config.log")))
121 # test that targets are not built, if conf_dir exists.
122 # verify that .cache and config.log are not created.
123 # an error should be raised
125 scons: \*\*\* Cannot update configure test "%s" within a dry-run\.
126 File \S+, line \S+, in \S+
127 """ % re.escape(os.path.join("config.test", "conftest_0.in"))
128 test.subdir(['configure','config.test'])
129 test.run(arguments="-q aaa.out",stderr=stderr,status=2,
130 chdir=test.workpath("configure"))
131 test.fail_test(os.path.exists(test.workpath("configure", "config.test",
133 test.fail_test(os.path.exists(test.workpath("configure", "config.test",
135 test.fail_test(os.path.exists(test.workpath("configure", "config.test",
137 test.fail_test(os.path.exists(test.workpath("configure", "config.log")))
139 # test that no error is raised, if all targets are up-to-date. In this
140 # case .cache and config.log shouldn't be created
141 stdout=test.wrap_stdout(build_str='cp aaa.in aaa.out\n',
142 read_str="""Executing Custom Test ... yes
144 test.run(stdout=stdout,arguments="aaa.out",status=0,chdir=test.workpath("configure"))
145 log1_mtime = os.path.getmtime(test.workpath("configure","config.log"))
146 test.run(arguments="-q aaa.out",status=0,
147 chdir=test.workpath("configure"))
148 log2_mtime = os.path.getmtime(test.workpath("configure","config.log"))
149 test.fail_test( log1_mtime != log2_mtime )