Applied Benoit Belley's patch in ticket 1957 improve the robustness of
[scons.git] / test / Configure / ConfigureDryRunError.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 """
28 Verify the ConfigureDryRunError.
29 """
30
31 import os.path
32
33 import TestSCons
34
35 _obj = TestSCons._obj
36
37 test = TestSCons.TestSCons()
38
39 lib = test.Configure_lib
40
41 NCR = test.NCR  # non-cached rebuild
42 CR  = test.CR   # cached rebuild (up to date)
43 NCF = test.NCF  # non-cached build failure
44 CF  = test.CF   # cached build failure
45
46 SConstruct_path = test.workpath('SConstruct')
47
48 test.write(SConstruct_path, """
49 env = Environment()
50 import os
51 env.AppendENVPath('PATH', os.environ['PATH'])
52 conf = Configure(env)
53 r1 = conf.CheckLib('%s') # will pass
54 r2 = conf.CheckLib('hopefullynolib') # will fail
55 env = conf.Finish()
56 if not (r1 and not r2):
57  Exit(1)
58 """ % (lib))
59
60 expect = """
61 scons: *** Cannot create configure directory ".sconf_temp" within a dry-run.
62 """ + test.python_file_line(SConstruct_path, 5)
63
64 test.run(arguments='-n', status=2, stderr=expect)
65
66 test.must_not_exist('config.log')
67 test.subdir('.sconf_temp')
68
69 conftest_0_c = os.path.join(".sconf_temp", "conftest_0.c")
70 SConstruct_file_line = test.python_file_line(SConstruct_path, 6)[:-1]
71
72 expect = """
73 scons: *** Cannot update configure test "%(conftest_0_c)s" within a dry-run.
74 %(SConstruct_file_line)s
75 """ % locals()
76
77 test.run(arguments='-n', status=2, stderr=expect)
78
79 test.run()
80 test.checkLogAndStdout( ["Checking for C library %s... " % lib,
81                     "Checking for C library hopefullynolib... "],
82                     ["yes", "no"],
83                     [[((".c", NCR), (_obj, NCR))],
84                      [((".c", NCR), (_obj, NCF))]],
85                     "config.log", ".sconf_temp", "SConstruct")
86
87 oldLog = test.read(test.workpath('config.log'))
88
89 test.run(arguments='-n')
90 test.checkLogAndStdout( ["Checking for C library %s... " % lib,
91                     "Checking for C library hopefullynolib... "],
92                     ["yes", "no"],
93                     [[((".c", CR), (_obj, CR))],
94                      [((".c", CR), (_obj, CF))]],
95                     "config.log", ".sconf_temp", "SConstruct",
96                     doCheckLog=0)
97
98 newLog = test.read(test.workpath('config.log'))
99 if newLog != oldLog:
100     print "Unexpected update of log file within a dry run"
101     test.fail_test()
102
103 test.pass_test()