Remove more unnecessary imports from test scripts.
[scons.git] / test / Repository / link-object.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 sys
28 import TestSCons
29
30 if sys.platform == 'win32':
31     _exe = '.exe'
32 else:
33     _exe = ''
34
35
36
37 test = TestSCons.TestSCons()
38
39 #
40 test.subdir('repository', 'work')
41
42 #
43 workpath_repository = test.workpath('repository')
44 repository_foo = test.workpath('repository', 'foo' + _exe)
45 work_foo = test.workpath('work', 'foo' + _exe)
46
47 #
48 test.write(['repository', 'SConstruct'], """
49 Repository(r'%s')
50 env = Environment()
51 env.Program(target = 'foo', source = ['aaa.c', 'bbb.c', 'foo.c'])
52 """ % workpath_repository)
53
54 test.write(['repository', 'aaa.c'], r"""
55 #include <stdio.h>
56 #include <stdlib.h>
57 void
58 aaa(void)
59 {
60         printf("repository/aaa.c\n");
61 }
62 """)
63
64 test.write(['repository', 'bbb.c'], r"""
65 #include <stdio.h>
66 #include <stdlib.h>
67 void
68 bbb(void)
69 {
70         printf("repository/bbb.c\n");
71 }
72 """)
73
74 test.write(['repository', 'foo.c'], r"""
75 #include <stdio.h>
76 #include <stdlib.h>
77 extern void aaa(void);
78 extern void bbb(void);
79 int
80 main(int argc, char *argv[])
81 {
82         argv[argc++] = "--";
83         aaa();
84         bbb();
85         printf("repository/foo.c\n");
86         exit (0);
87 }
88 """)
89
90 #
91 test.run(chdir = 'repository', arguments = ".")
92
93 test.run(program = repository_foo, stdout =
94 """repository/aaa.c
95 repository/bbb.c
96 repository/foo.c
97 """)
98
99 test.up_to_date(chdir = 'repository', arguments = ".")
100
101 # Make the repository non-writable,
102 # so we'll detect if we try to write into it accidentally.
103 test.writable('repository', 0)
104
105 #
106 test.write(['work', 'SConstruct'], """
107 Repository(r'%s')
108 env = Environment()
109 env.Program(target = 'foo', source = ['aaa.c', 'bbb.c', 'foo.c'])
110 """ % workpath_repository)
111
112 test.up_to_date(chdir = 'work', arguments = ".")
113
114 #
115 test.write(['work', 'bbb.c'], r"""
116 #include <stdio.h>
117 #include <stdlib.h>
118 void
119 bbb(void)
120 {
121         printf("work/bbb.c\n");
122 }
123 """)
124
125 #
126 test.run(chdir = 'work', arguments = ".")
127
128 test.run(program = work_foo, stdout =
129 """repository/aaa.c
130 work/bbb.c
131 repository/foo.c
132 """)
133
134 test.up_to_date(chdir = 'work', arguments = ".")
135
136 #
137 test.unlink(['work', 'bbb.c'])
138
139 #
140 test.run(chdir = 'work', arguments = ".")
141
142 test.run(program = work_foo, stdout =
143 """repository/aaa.c
144 repository/bbb.c
145 repository/foo.c
146 """)
147
148 test.up_to_date(chdir = 'work', arguments = ".")
149
150 #
151 test.writable('repository', 1)
152
153 #
154 test.up_to_date(chdir = 'repository', arguments = ".")
155
156 #
157 test.pass_test()
158
159 # Local Variables:
160 # tab-width:4
161 # indent-tabs-mode:nil
162 # End:
163 # vim: set expandtab tabstop=4 shiftwidth=4: