Move 2.0 changes collected in branches/pending back to trunk for further
[scons.git] / test / Repository / option-f.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 TestSCons
29
30 test = TestSCons.TestSCons()
31
32 test.subdir('work', 'repository', ['repository', 'src'])
33
34 work_aaa = test.workpath('work', 'aaa')
35 work_bbb = test.workpath('work', 'bbb')
36 work_ccc = test.workpath('work', 'ccc')
37 work_src_xxx = test.workpath('work', 'src', 'xxx')
38 work_src_yyy = test.workpath('work', 'src', 'yyy')
39
40 opts = "-f " + test.workpath('repository', 'SConstruct')
41
42 test.write(['repository', 'SConstruct'], """\
43 Repository(r'%s')
44 def cat(env, source, target):
45     target = str(target[0])
46     f = open(target, "wb")
47     for src in source:
48         f.write(open(str(src), "rb").read())
49     f.close()
50
51 env = Environment(BUILDERS={'Build':Builder(action=cat)})
52 env.Build('aaa.out', 'aaa.in')
53 env.Build('bbb.out', 'bbb.in')
54 env.Build('ccc.out', 'ccc.in')
55 SConscript('src/SConscript', "env")
56 """ % test.workpath('repository'))
57
58 test.write(['repository', 'src', 'SConscript'], """
59 Import("env")
60 env.Build('xxx.out', 'xxx.in')
61 env.Build('yyy.out', 'yyy.in')
62 """)
63
64 test.write(['repository', 'aaa.in'], "repository/aaa.in\n")
65 test.write(['repository', 'bbb.in'], "repository/bbb.in\n")
66 test.write(['repository', 'ccc.in'], "repository/ccc.in\n")
67
68 test.write(['repository', 'src', 'xxx.in'], "repository/src/xxx.in\n")
69 test.write(['repository', 'src', 'yyy.in'], "repository/src/yyy.in\n")
70
71 #
72 # Make the repository non-writable,
73 # so we'll detect if we try to write into it accidentally.
74 test.writable('repository', 0)
75
76 #
77 test.run(chdir = 'work', options = opts, arguments = 'aaa.out')
78
79 test.fail_test(test.read(['work', 'aaa.out']) != "repository/aaa.in\n")
80 test.fail_test(os.path.exists(test.workpath('work', 'bbb.out')))
81 test.fail_test(os.path.exists(test.workpath('work', 'ccc.out')))
82 test.fail_test(os.path.exists(test.workpath('work', 'src', 'xxx.out')))
83 test.fail_test(os.path.exists(test.workpath('work', 'src', 'yyy.out')))
84
85 test.run(chdir = 'work', options = opts, arguments = 'bbb.out src')
86
87 test.fail_test(test.read(['work', 'bbb.out']) != "repository/bbb.in\n")
88 test.fail_test(os.path.exists(test.workpath('work', 'ccc.out')))
89 test.fail_test(test.read(['work', 'src', 'xxx.out']) != "repository/src/xxx.in\n")
90 test.fail_test(test.read(['work', 'src', 'yyy.out']) != "repository/src/yyy.in\n")
91
92 #
93 test.run(chdir = 'work', options = opts, arguments = '.')
94
95 test.fail_test(test.read(['work', 'ccc.out']) != "repository/ccc.in\n")
96
97 #
98 test.pass_test()
99
100 # Local Variables:
101 # tab-width:4
102 # indent-tabs-mode:nil
103 # End:
104 # vim: set expandtab tabstop=4 shiftwidth=4: