Added fix for TeX includes with same name as subdirs.
[scons.git] / test / Subversion.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 fetching source files from Subversion.
29 """
30
31 import TestSCons
32
33 test = TestSCons.TestSCons()
34
35 svn = test.where_is('svn')
36 if not svn:
37     test.skip_test("Could not find 'svn'; skipping test(s).\n")
38
39 svnadmin = test.where_is('svnadmin')
40 if not svn:
41     test.skip_test("Could not find 'svnadmin'; skipping test(s).\n")
42
43 print "Short-circuiting this test until we support Subversion"
44 test.pass_test()
45
46 test.subdir('Subversion', 'import', ['import', 'sub'], 'work1', 'work2')
47
48 # Set up the Subversion repository.
49 svnrootpath = test.workpath('Subversion')
50 svnrooturl = 'file://' + svnrootpath
51
52 test.run(program = svnadmin, arguments = 'create %s' % svnrootpath)
53
54 test.write(['import', 'aaa.in'], "import/aaa.in\n")
55 test.write(['import', 'bbb.in'], "import/bbb.in\n")
56 test.write(['import', 'ccc.in'], "import/ccc.in\n")
57
58 test.write(['import', 'sub', 'SConscript'], """\
59 Import("env")
60 env.Cat('ddd.out', 'ddd.in')
61 env.Cat('eee.out', 'eee.in')
62 env.Cat('fff.out', 'fff.in')
63 env.Cat('all', ['ddd.out', 'eee.out', 'fff.out'])
64 """)
65
66 test.write(['import', 'sub', 'ddd.in'], "import/sub/ddd.in\n")
67 test.write(['import', 'sub', 'eee.in'], "import/sub/eee.in\n")
68 test.write(['import', 'sub', 'fff.in'], "import/sub/fff.in\n")
69
70 test.run(chdir = 'import',
71          program = svn,
72          arguments = 'import %s . foo -m"import foo"' % svnrooturl)
73
74 # Test the most straightforward Subversion checkouts, using the module name.
75 test.write(['work1', 'SConstruct'], """
76 def cat(env, source, target):
77     target = str(target[0])
78     f = open(target, "wb")
79     for src in source:
80         f.write(open(str(src), "rb").read())
81     f.close()
82 env = Environment(BUILDERS={'Cat':Builder(action=cat)})
83 env.Cat('aaa.out', 'foo/aaa.in')
84 env.Cat('bbb.out', 'foo/bbb.in')
85 env.Cat('ccc.out', 'foo/ccc.in')
86 env.Cat('all', ['aaa.out', 'bbb.out', 'ccc.out'])
87 env.SourceCode('.', env.Subversion(r'%s'))
88 SConscript('foo/sub/SConscript', "env")
89 """ % svnrooturl)
90
91 test.subdir(['work1', 'foo'])
92 test.write(['work1', 'foo', 'bbb.in'], "work1/foo/bbb.in\n")
93
94 test.subdir(['work1', 'foo', 'sub'])
95 test.write(['work1', 'foo', 'sub', 'eee.in'], "work1/foo/sub/eee.in\n")
96
97 test.run(chdir = 'work1',
98          arguments = '.',
99          stdout = test.wrap_stdout(read_str = """\
100 svn cat %s/foo/sub/SConscript > foo/sub/SConscript
101 """ % (svnrooturl),
102                                    build_str = """\
103 svn cat %s/foo/aaa.in > foo/aaa.in
104 cat("aaa.out", "foo/aaa.in")
105 cat("bbb.out", "foo/bbb.in")
106 svn cat %s/foo/ccc.in > foo/ccc.in
107 cat("ccc.out", "foo/ccc.in")
108 cat("all", ["aaa.out", "bbb.out", "ccc.out"])
109 svn cat %s/foo/sub/ddd.in > foo/sub/ddd.in
110 cat("foo/sub/ddd.out", "foo/sub/ddd.in")
111 cat("foo/sub/eee.out", "foo/sub/eee.in")
112 svn cat %s/foo/sub/fff.in > foo/sub/fff.in
113 cat("foo/sub/fff.out", "foo/sub/fff.in")
114 cat("foo/sub/all", ["foo/sub/ddd.out", "foo/sub/eee.out", "foo/sub/fff.out"])
115 """ % (svnrooturl, svnrooturl, svnrooturl, svnrooturl)))
116
117 test.fail_test(test.read(['work1', 'all']) != "import/aaa.in\nwork1/foo/bbb.in\nimport/ccc.in\n")
118
119 test.fail_test(test.read(['work1', 'foo', 'sub', 'all']) != "import/sub/ddd.in\nwork1/foo/sub/eee.in\nimport/sub/fff.in\n")
120
121 # Test Subversion checkouts when the module name is specified.
122 test.write(['work2', 'SConstruct'], """
123 def cat(env, source, target):
124     target = str(target[0])
125     f = open(target, "wb")
126     for src in source:
127         f.write(open(str(src), "rb").read())
128     f.close()
129 env = Environment(BUILDERS={'Cat':Builder(action=cat)})
130 env.Cat('aaa.out', 'aaa.in')
131 env.Cat('bbb.out', 'bbb.in')
132 env.Cat('ccc.out', 'ccc.in')
133 env.Cat('all', ['aaa.out', 'bbb.out', 'ccc.out'])
134 env.SourceCode('.', env.Subversion(r'%s', 'foo'))
135 SConscript('sub/SConscript', "env")
136 """ % svnrooturl)
137
138 test.write(['work2', 'bbb.in'], "work2/bbb.in\n")
139
140 test.subdir(['work2', 'sub'])
141 test.write(['work2', 'sub', 'eee.in'], "work2/sub/eee.in\n")
142
143 test.run(chdir = 'work2',
144          arguments = '.',
145          stdout = test.wrap_stdout(read_str = """\
146 svn cat %s/foo/sub/SConscript > sub/SConscript
147 """ % (svnrooturl),
148                                    build_str = """\
149 svn cat %s/foo/aaa.in > aaa.in
150 cat("aaa.out", "aaa.in")
151 cat("bbb.out", "bbb.in")
152 svn cat %s/foo/ccc.in > ccc.in
153 cat("ccc.out", "ccc.in")
154 cat("all", ["aaa.out", "bbb.out", "ccc.out"])
155 svn cat %s/foo/sub/ddd.in > sub/ddd.in
156 cat("sub/ddd.out", "sub/ddd.in")
157 cat("sub/eee.out", "sub/eee.in")
158 svn cat %s/foo/sub/fff.in > sub/fff.in
159 cat("sub/fff.out", "sub/fff.in")
160 cat("sub/all", ["sub/ddd.out", "sub/eee.out", "sub/fff.out"])
161 """ % (svnrooturl, svnrooturl, svnrooturl, svnrooturl)))
162
163 test.fail_test(test.read(['work2', 'all']) != "import/aaa.in\nwork2/bbb.in\nimport/ccc.in\n")
164
165 test.fail_test(test.read(['work2', 'sub', 'all']) != "import/sub/ddd.in\nwork2/sub/eee.in\nimport/sub/fff.in\n")
166
167 test.pass_test()
168
169 # Local Variables:
170 # tab-width:4
171 # indent-tabs-mode:nil
172 # End:
173 # vim: set expandtab tabstop=4 shiftwidth=4: