Update regression tests to match changes in runtest.py
[scons.git] / test / Libs / Library.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 TestSCons
28
29 test = TestSCons.TestSCons()
30
31 test.write('SConstruct', """
32 env = Environment(LIBS = [ 'foo1', 'libfoo2' ],
33                   LIBPATH = [ '.' ])
34 env.Library(target = 'foo1', source = 'f1.c')
35 Library(target = 'libfoo2', source = Split('f2a.c f2b.c f2c.c'))
36 libtgt=env.Library(target = 'foo3', source = ['f3a.c', 'f3b.c', 'f3c.cpp'])
37 env.Program(target = 'prog', source = [ 'prog.cpp', libtgt ])
38 """)
39
40 test.write('f1.c', r"""
41 #include <stdio.h>
42 void
43 f1(void)
44 {
45         printf("f1.c\n");
46 }
47 """)
48
49 test.write('f2a.c', r"""
50 #include <stdio.h>
51 void
52 f2a(void)
53 {
54         printf("f2a.c\n");
55 }
56 """)
57
58 test.write('f2b.c', r"""
59 #include <stdio.h>
60 void
61 f2b(void)
62 {
63         printf("f2b.c\n");
64 }
65 """)
66
67 test.write('f2c.c', r"""
68 #include <stdio.h>
69 void
70 f2c(void)
71 {
72         printf("f2c.c\n");
73 }
74 """)
75
76 test.write('f3a.c', r"""
77 #include <stdio.h>
78 void
79 f3a(void)
80 {
81         printf("f3a.c\n");
82 }
83 """)
84
85 test.write('f3b.c', r"""
86 #include <stdio.h>
87 void
88 f3b(void)
89 {
90         printf("f3b.c\n");
91 }
92 """)
93
94 test.write('f3c.cpp', r"""
95 #include <stdio.h>
96 extern "C" void
97 f3c(void)
98 {
99         printf("f3c.cpp\n");
100 }
101 """)
102
103 test.write('prog.cpp', r"""
104 #include <stdio.h>
105 extern "C" {
106 void f1(void);
107 void f2a(void);
108 void f2b(void);
109 void f2c(void);
110 void f3a(void);
111 void f3b(void);
112 void f3c(void);
113 }
114 int
115 main(int argc, char *argv[])
116 {
117         argv[argc++] = (char *)"--";
118         f1();
119         f2a();
120         f2b();
121         f2c();
122         f3a();
123         f3b();
124         f3c();
125         printf("prog.c\n");
126         return 0;
127 }
128 """)
129
130 test.run(arguments = '.',
131          stderr=TestSCons.noisy_ar,
132          match=TestSCons.match_re_dotall)
133
134 test.run(program = test.workpath('prog'),
135          stdout = "f1.c\nf2a.c\nf2b.c\nf2c.c\nf3a.c\nf3b.c\nf3c.cpp\nprog.c\n")
136
137 # Tests whether you can reference libraries with substitutions.
138
139 test.write('SConstruct', r"""
140 # nrd = not referenced directly :)
141 Library('nrd', 'nrd.c')
142 p = Program('uses-nrd', 'uses-nrd.c', NRD='nrd', LIBPATH=['.'], LIBS=['$NRD'])
143 Default(p)
144 """)
145
146 test.write('nrd.c', r"""
147 #include <stdio.h>
148 void nrd() {
149     puts("nrd");
150 }
151 """)
152
153 test.write('uses-nrd.c', r"""
154 void nrd();
155 int main() {
156     nrd();
157     return 0;
158 }
159 """)
160
161 test.run(stderr=TestSCons.noisy_ar,
162          match=TestSCons.match_re_dotall)
163
164 test.run(program = test.workpath('uses-nrd'),
165          stdout = "nrd\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: