Remove more unnecessary imports from test scripts.
[scons.git] / test / Repository / SConscript.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 Test how we handle SConscript calls when using a Repository.
29 """
30
31 import sys
32 import TestSCons
33
34 if sys.platform == 'win32':
35     _exe = '.exe'
36 else:
37     _exe = ''
38
39 test = TestSCons.TestSCons()
40
41 #
42 test.subdir('work',
43             ['work', 'src'],
44             'rep1',
45             ['rep1', 'src'],
46             'rep2',
47             ['rep2', 'build'],
48             ['rep2', 'src'],
49             ['rep2', 'src', 'sub'])
50
51 #
52 workpath_rep1 = test.workpath('rep1')
53 workpath_rep2 = test.workpath('rep2')
54
55 #
56 test.write(['work', 'SConstruct'], """
57 Repository(r'%s')
58 SConscript('src/SConscript')
59 """ % workpath_rep1)
60
61 test.write(['rep1', 'src', 'SConscript'], """\
62 def cat(env, source, target):
63     target = str(target[0])
64     source = map(str, source)
65     f = open(target, "wb")
66     for src in source:
67         f.write(open(src, "rb").read())
68     f.close()
69 env = Environment(BUILDERS={'Cat':Builder(action=cat)})
70 env.Cat(target = 'foo', source = ['aaa.in', 'bbb.in', 'ccc.in'])
71 """)
72
73 test.write(['rep1', 'src', 'aaa.in'], "rep1/src/aaa.in\n")
74 test.write(['rep1', 'src', 'bbb.in'], "rep1/src/bbb.in\n")
75 test.write(['rep1', 'src', 'ccc.in'], "rep1/src/ccc.in\n")
76
77 # Make the rep1 non-writable,
78 # so we'll detect if we try to write into it accidentally.
79 test.writable('rep1', 0)
80
81 test.run(chdir = 'work', arguments = ".")
82
83 test.fail_test(test.read(['work', 'src', 'foo']) != """\
84 rep1/src/aaa.in
85 rep1/src/bbb.in
86 rep1/src/ccc.in
87 """)
88
89 test.up_to_date(chdir = 'work', arguments = ".")
90
91 #
92 test.write(['rep2', 'build', 'SConstruct'], """
93 env = Environment(REPOSITORY = r'%s')
94 env.Repository('$REPOSITORY')
95 SConscript('src/SConscript')
96 """ % workpath_rep2)
97
98 test.write(['rep2', 'src', 'SConscript'], """\
99 def cat(env, source, target):
100     target = str(target[0])
101     source = map(str, source)
102     f = open(target, "wb")
103     for src in source:
104         f.write(open(src, "rb").read())
105     f.close()
106 env = Environment(BUILDERS={'Cat':Builder(action=cat)})
107 env.Cat(target = 'foo', source = ['aaa.in', 'bbb.in', 'ccc.in'])
108 SConscript('sub/SConscript')
109 """)
110
111 test.write(['rep2', 'src', 'sub', 'SConscript'], """\
112 """)
113
114 test.write(['rep2', 'src', 'aaa.in'], "rep2/src/aaa.in\n")
115 test.write(['rep2', 'src', 'bbb.in'], "rep2/src/bbb.in\n")
116 test.write(['rep2', 'src', 'ccc.in'], "rep2/src/ccc.in\n")
117
118 test.run(chdir = 'rep2/build', arguments = ".")
119
120 test.fail_test(test.read(['rep2', 'build', 'src', 'foo']) != """\
121 rep2/src/aaa.in
122 rep2/src/bbb.in
123 rep2/src/ccc.in
124 """)
125
126 #
127 test.pass_test()
128
129 # Local Variables:
130 # tab-width:4
131 # indent-tabs-mode:nil
132 # End:
133 # vim: set expandtab tabstop=4 shiftwidth=4: