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