A test case for my last commit.
[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     source = map(str, source)
79     f = open(target, "wb")
80     for src in source:
81         f.write(open(src, "rb").read())
82     f.close()
83 env = Environment(BUILDERS={'Cat':Builder(action=cat)})
84 env.Cat('aaa.out', 'foo/aaa.in')
85 env.Cat('bbb.out', 'foo/bbb.in')
86 env.Cat('ccc.out', 'foo/ccc.in')
87 env.Cat('all', ['aaa.out', 'bbb.out', 'ccc.out'])
88 env.SourceCode('.', env.Subversion(r'%s'))
89 SConscript('foo/sub/SConscript', "env")
90 """ % svnrooturl)
91
92 test.subdir(['work1', 'foo'])
93 test.write(['work1', 'foo', 'bbb.in'], "work1/foo/bbb.in\n")
94
95 test.subdir(['work1', 'foo', 'sub'])
96 test.write(['work1', 'foo', 'sub', 'eee.in'], "work1/foo/sub/eee.in\n")
97
98 test.run(chdir = 'work1',
99          arguments = '.',
100          stdout = test.wrap_stdout(read_str = """\
101 svn cat %s/foo/sub/SConscript > foo/sub/SConscript
102 """ % (svnrooturl),
103                                    build_str = """\
104 svn cat %s/foo/aaa.in > foo/aaa.in
105 cat("aaa.out", "foo/aaa.in")
106 cat("bbb.out", "foo/bbb.in")
107 svn cat %s/foo/ccc.in > foo/ccc.in
108 cat("ccc.out", "foo/ccc.in")
109 cat("all", ["aaa.out", "bbb.out", "ccc.out"])
110 svn cat %s/foo/sub/ddd.in > foo/sub/ddd.in
111 cat("foo/sub/ddd.out", "foo/sub/ddd.in")
112 cat("foo/sub/eee.out", "foo/sub/eee.in")
113 svn cat %s/foo/sub/fff.in > foo/sub/fff.in
114 cat("foo/sub/fff.out", "foo/sub/fff.in")
115 cat("foo/sub/all", ["foo/sub/ddd.out", "foo/sub/eee.out", "foo/sub/fff.out"])
116 """ % (svnrooturl, svnrooturl, svnrooturl, svnrooturl)))
117
118 test.fail_test(test.read(['work1', 'all']) != "import/aaa.in\nwork1/foo/bbb.in\nimport/ccc.in\n")
119
120 test.fail_test(test.read(['work1', 'foo', 'sub', 'all']) != "import/sub/ddd.in\nwork1/foo/sub/eee.in\nimport/sub/fff.in\n")
121
122 # Test Subversion checkouts when the module name is specified.
123 test.write(['work2', 'SConstruct'], """
124 def cat(env, source, target):
125     target = str(target[0])
126     source = map(str, source)
127     f = open(target, "wb")
128     for src in source:
129         f.write(open(src, "rb").read())
130     f.close()
131 env = Environment(BUILDERS={'Cat':Builder(action=cat)})
132 env.Cat('aaa.out', 'aaa.in')
133 env.Cat('bbb.out', 'bbb.in')
134 env.Cat('ccc.out', 'ccc.in')
135 env.Cat('all', ['aaa.out', 'bbb.out', 'ccc.out'])
136 env.SourceCode('.', env.Subversion(r'%s', 'foo'))
137 SConscript('sub/SConscript', "env")
138 """ % svnrooturl)
139
140 test.write(['work2', 'bbb.in'], "work2/bbb.in\n")
141
142 test.subdir(['work2', 'sub'])
143 test.write(['work2', 'sub', 'eee.in'], "work2/sub/eee.in\n")
144
145 test.run(chdir = 'work2',
146          arguments = '.',
147          stdout = test.wrap_stdout(read_str = """\
148 svn cat %s/foo/sub/SConscript > sub/SConscript
149 """ % (svnrooturl),
150                                    build_str = """\
151 svn cat %s/foo/aaa.in > aaa.in
152 cat("aaa.out", "aaa.in")
153 cat("bbb.out", "bbb.in")
154 svn cat %s/foo/ccc.in > ccc.in
155 cat("ccc.out", "ccc.in")
156 cat("all", ["aaa.out", "bbb.out", "ccc.out"])
157 svn cat %s/foo/sub/ddd.in > sub/ddd.in
158 cat("sub/ddd.out", "sub/ddd.in")
159 cat("sub/eee.out", "sub/eee.in")
160 svn cat %s/foo/sub/fff.in > sub/fff.in
161 cat("sub/fff.out", "sub/fff.in")
162 cat("sub/all", ["sub/ddd.out", "sub/eee.out", "sub/fff.out"])
163 """ % (svnrooturl, svnrooturl, svnrooturl, svnrooturl)))
164
165 test.fail_test(test.read(['work2', 'all']) != "import/aaa.in\nwork2/bbb.in\nimport/ccc.in\n")
166
167 test.fail_test(test.read(['work2', 'sub', 'all']) != "import/sub/ddd.in\nwork2/sub/eee.in\nimport/sub/fff.in\n")
168
169 test.pass_test()