Eliminate unnecessary WIN32/Win32/win32 references in tests, too.
[scons.git] / test / option-q.py
1 #!/usr/bin/env python
2 #
3 # __COPYRIGHT__
4 #
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:
12 #
13 # The above copyright notice and this permission notice shall be included
14 # in all copies or substantial portions of the Software.
15 #
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.
23 #
24
25 __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
26
27 import os.path
28 import re
29 import string
30 import sys
31
32 import TestCmd
33 import TestSCons
34
35 test = TestSCons.TestSCons()
36
37 python = TestSCons.python
38
39 test.write('build.py', r"""
40 import sys
41 contents = open(sys.argv[2], 'rb').read()
42 file = open(sys.argv[1], 'wb')
43 file.write(contents)
44 file.close()
45 """)
46
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')
52 """ % python)
53
54 test.write('aaa.in', "aaa.in\n")
55 test.write('bbb.in', "bbb.in\n")
56
57 test.run(arguments = '-q aaa.out', status = 1)
58
59 test.fail_test(os.path.exists(test.workpath('aaa.out')))
60
61 test.run(arguments = 'aaa.out')
62
63 test.fail_test(test.read('aaa.out') != "aaa.in\n")
64
65 test.run(arguments = '-q aaa.out', status = 0)
66
67 test.run(arguments = '--question bbb.out', status = 1)
68
69 test.fail_test(os.path.exists(test.workpath('bbb.out')))
70
71 test.run(arguments = 'bbb.out')
72
73 test.fail_test(test.read('bbb.out') != "bbb.in\n")
74
75 test.run(arguments = '--question bbb.out', status = 0)
76
77
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):
85     import shutil
86     shutil.copyfile( str(source[0]), str(target[0]))
87
88 def strAction(target,source,env):
89     return "cp " + str(source[0]) + " " + str(target[0])
90
91 def CustomTest(context):
92     context.Message("Executing Custom Test ... " )
93     (ok, msg) = context.TryAction(Action(userAction,strAction),
94                                   "Hello World", ".in")
95     context.Result(ok)
96     return ok
97
98 env = Environment(BUILDERS={'B' : Builder(action=Action(userAction,strAction))})
99
100 conf = Configure( env,
101                   custom_tests={'CustomTest':CustomTest},
102                   conf_dir="config.test",
103                   log_file="config.log")
104 if not conf.CustomTest():
105     Exit(1)
106 else:
107     env = conf.Finish()
108
109 env.B(target='aaa.out', source='aaa.in')
110 """)
111 # test that conf_dir isn't created and an error is raised
112 stderr=r"""
113 scons: \*\*\* Cannot create configure directory "config\.test" within a dry-run\.
114 File \S+, line \S+, in \S+
115 """
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")))
120
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
124 stderr=r"""
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",
132                                             ".cache")))
133 test.fail_test(os.path.exists(test.workpath("configure", "config.test",
134                                             "conftest_0")))
135 test.fail_test(os.path.exists(test.workpath("configure", "config.test",
136                                             "conftest_0.in")))
137 test.fail_test(os.path.exists(test.workpath("configure", "config.log")))
138
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
143 """)
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 )
150
151 test.pass_test()