http://scons.tigris.org/issues/show_bug.cgi?id=2329
[scons.git] / test / Glob / Repository.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 that the Glob() function finds files in repositories.
29 """
30
31 import TestSCons
32
33 test = TestSCons.TestSCons()
34
35 test.subdir('work',
36             'repository',
37             ['repository', 'src'],
38             ['repository', 'src', 'sub1'],
39             ['repository', 'src', 'sub2'])
40
41 work_aaa = test.workpath('work', 'aaa')
42 work_bbb = test.workpath('work', 'bbb')
43 work_ccc = test.workpath('work', 'ccc')
44 work_src_xxx = test.workpath('work', 'src', 'xxx')
45 work_src_yyy = test.workpath('work', 'src', 'yyy')
46
47 opts = "-Y " + test.workpath('repository')
48
49 test.write(['repository', 'SConstruct'], """\
50 def cat(env, source, target):
51     target = str(target[0])
52     f = open(target, "wb")
53     for src in source:
54         f.write(open(str(src), "rb").read())
55     f.close()
56
57 # Verify that we can glob a repository-only Node that exists
58 # only in memory, not on disk.
59 File('../repository/mmm.in')
60 m = Glob('m*.in')
61 assert str(m[0]) == 'mmm.in'
62
63 env = Environment(BUILDERS={'Build':Builder(action=cat)})
64 env.Build('aaa.out', Glob('a*.in'))
65 env.Build('bbb.out', Glob('b*.in'))
66 env.Build('ccc.out', Glob('c*.in'))
67 SConscript('src/SConscript', "env")
68 """)
69
70 test.write(['repository', 'aaa.in'], "repository/aaa.in\n")
71 test.write(['repository', 'bbb.in'], "repository/bbb.in\n")
72 test.write(['repository', 'ccc.in'], "repository/ccc.in\n")
73
74 test.write(['repository', 'src', 'SConscript'], """
75 Import("env")
76 env.Build('xxx.out', Glob('x*.in'))
77 env.Build('yyy.out', Glob('yy?.in'))
78 env.Build('zzz.out', sorted(Glob('*/zzz.in'), key=lambda t: t.abspath))
79 """)
80
81 test.write(['repository', 'src', 'xxx.in'], "repository/src/xxx.in\n")
82 test.write(['repository', 'src', 'yyy.in'], "repository/src/yyy.in\n")
83 test.write(['repository', 'src', 'sub1', 'zzz.in'], "repository/src/sub1/zzz.in\n")
84 test.write(['repository', 'src', 'sub2', 'zzz.in'], "repository/src/sub2/zzz.in\n")
85
86 #
87 # Make the repository non-writable,
88 # so we'll detect if we try to write into it accidentally.
89 test.writable('repository', 0)
90
91 #
92 test.run(chdir = 'work', options = opts, arguments = 'aaa.out')
93
94 test.must_match(['work', 'aaa.out'], "repository/aaa.in\n")
95 test.must_not_exist(test.workpath('work', 'bbb.out'))
96 test.must_not_exist(test.workpath('work', 'ccc.out'))
97 test.must_not_exist(test.workpath('work', 'src', 'xxx.out'))
98 test.must_not_exist(test.workpath('work', 'src', 'yyy.out'))
99
100 test.run(chdir = 'work', options = opts, arguments = 'bbb.out src')
101
102 test.must_match(['work', 'bbb.out'], "repository/bbb.in\n")
103 test.must_not_exist(test.workpath('work', 'ccc.out'))
104 test.must_match(['work', 'src', 'xxx.out'], "repository/src/xxx.in\n")
105 test.must_match(['work', 'src', 'yyy.out'], "repository/src/yyy.in\n")
106
107 expect = """\
108 repository/src/sub1/zzz.in
109 repository/src/sub2/zzz.in
110 """
111
112 test.must_match(['work', 'src', 'zzz.out'], expect)
113
114 #
115 test.run(chdir = 'work', options = opts, arguments = '.')
116
117 test.must_match(['work', 'ccc.out'], "repository/ccc.in\n")
118
119 #
120 test.pass_test()
121
122 # Local Variables:
123 # tab-width:4
124 # indent-tabs-mode:nil
125 # End:
126 # vim: set expandtab tabstop=4 shiftwidth=4: