Merge pull request #4655 from bdbaddog/fix_new_ninja_package
[scons.git] / test / Repository / option-n.py
blobd99e92ade7f5e740ea090f30badeb36052de3bba
1 #!/usr/bin/env python
3 # __COPYRIGHT__
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 """
26 This test verifies that building using the -n option doesn't create a
27 local copy of a file specified as Local() in the SConstruct.
28 """
30 __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
32 import os.path
34 import TestSCons
36 test = TestSCons.TestSCons()
38 test.subdir('repository', ['repository', 'src'],
39 'work', ['work', 'src'])
41 repository_aaa_out = test.workpath('repository', 'aaa.out')
42 work_aaa_out = test.workpath('work', 'aaa.out')
44 opts = "-Y " + test.workpath('repository')
47 test.write(['repository', 'SConstruct'], r"""
48 def copy(env, source, target):
49 source = str(source[0])
50 target = str(target[0])
51 print('copy() < %s > %s' % (source, target))
52 with open(target, "w") as ofp, open(source, "r") as ifp:
53 ofp.write(ifp.read())
55 Build = Builder(action=copy)
56 env = Environment(BUILDERS={'Build':Build})
57 env.Build('aaa.out', 'aaa.in')
58 Local('aaa.out')
59 """)
61 test.write(['repository', 'aaa.in'], "repository/aaa.in\n")
64 test.run(chdir = 'repository', options = opts, arguments = '.')
66 test.must_match(repository_aaa_out,"repository/aaa.in\n", mode='r')
68 test.up_to_date(chdir = 'repository', options = opts, arguments = '.')
70 # Make the entire repository non-writable, so we'll detect
71 # if we try to write into it accidentally.
72 test.writable('repository', 0)
75 expect = test.wrap_stdout("""\
76 Local copy of aaa.out from %s
77 scons: `aaa.out' is up to date.
78 """ % repository_aaa_out)
80 test.run(chdir = 'work',
81 options = opts,
82 arguments = '-n aaa.out',
83 stdout = expect)
85 test.fail_test(os.path.exists(work_aaa_out))
87 test.run(chdir = 'work',
88 options = opts,
89 arguments = 'aaa.out',
90 stdout = expect)
92 test.must_match(work_aaa_out, "repository/aaa.in\n", mode='r')
95 test.pass_test()
97 # Local Variables:
98 # tab-width:4
99 # indent-tabs-mode:nil
100 # End:
101 # vim: set expandtab tabstop=4 shiftwidth=4: