Add emacs and vim editing settings to the bottom of *.py files.
[scons.git] / test / Configure / config-h.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 Verify creation of a config.h file from a Configure context.
29 """
30
31 import os
32 import re
33 import string
34
35 import TestSCons
36
37 test = TestSCons.TestSCons(match = TestSCons.match_exact)
38
39 lib = test.Configure_lib
40 LIB = "LIB" + string.upper(lib)
41
42 test.write('SConstruct', """\
43 env = Environment()
44 import os
45 env.AppendENVPath('PATH', os.environ['PATH'])
46 conf = Configure(env, config_h = 'config.h')
47 r1 = conf.CheckFunc('printf')
48 r2 = conf.CheckFunc('noFunctionCall')
49 r3 = conf.CheckType('int')
50 r4 = conf.CheckType('noType')
51 r5 = conf.CheckCHeader('stdio.h', '<>')
52 r6 = conf.CheckCHeader('hopefullynoc-header.h')
53 r7 = conf.CheckCXXHeader('vector', '<>')
54 r8 = conf.CheckCXXHeader('hopefullynocxx-header.h')
55 env = conf.Finish()
56 conf = Configure(env, config_h = 'config.h')
57 r9 = conf.CheckLib('%(lib)s', 'sin')
58 r10 = conf.CheckLib('hopefullynolib', 'sin')
59 r11 = conf.CheckLibWithHeader('%(lib)s', 'math.h', 'c')
60 r12 = conf.CheckLibWithHeader('%(lib)s', 'hopefullynoheader2.h', 'c')
61 r13 = conf.CheckLibWithHeader('hopefullynolib2', 'math.h', 'c')
62 env = conf.Finish()
63 """ % locals())
64
65 expected_read_str = """\
66 Checking for C function printf()... yes
67 Checking for C function noFunctionCall()... no
68 Checking for C type int... yes
69 Checking for C type noType... no
70 Checking for C header file stdio.h... yes
71 Checking for C header file hopefullynoc-header.h... no
72 Checking for C++ header file vector... yes
73 Checking for C++ header file hopefullynocxx-header.h... no
74 Checking for sin() in C library %(lib)s... yes
75 Checking for sin() in C library hopefullynolib... no
76 Checking for C library %(lib)s... yes
77 Checking for C library %(lib)s... no
78 Checking for C library hopefullynolib2... no
79 """ % locals()
80
81 expected_build_str = """\
82 scons: Configure: creating config.h
83 """
84     
85 expected_stdout = test.wrap_stdout(build_str=expected_build_str,
86                                        read_str=expected_read_str)
87
88 expected_config_h = string.replace("""\
89 #ifndef CONFIG_H_SEEN
90 #define CONFIG_H_SEEN
91
92
93 /* Define to 1 if the system has the function `printf'. */
94 #define HAVE_PRINTF 1
95
96 /* Define to 1 if the system has the function `noFunctionCall'. */
97 /* #undef HAVE_NOFUNCTIONCALL */
98
99 /* Define to 1 if the system has the type `int'. */
100 #define HAVE_INT 1
101
102 /* Define to 1 if the system has the type `noType'. */
103 /* #undef HAVE_NOTYPE */
104
105 /* Define to 1 if you have the <stdio.h> header file. */
106 #define HAVE_STDIO_H 1
107
108 /* Define to 1 if you have the <hopefullynoc-header.h> header file. */
109 /* #undef HAVE_HOPEFULLYNOC_HEADER_H */
110
111 /* Define to 1 if you have the <vector> header file. */
112 #define HAVE_VECTOR 1
113
114 /* Define to 1 if you have the <hopefullynocxx-header.h> header file. */
115 /* #undef HAVE_HOPEFULLYNOCXX_HEADER_H */
116
117 /* Define to 1 if you have the `%(lib)s' library. */
118 #define HAVE_%(LIB)s 1
119
120 /* Define to 1 if you have the `hopefullynolib' library. */
121 /* #undef HAVE_LIBHOPEFULLYNOLIB */
122
123 /* Define to 1 if you have the `%(lib)s' library. */
124 #define HAVE_%(LIB)s 1
125
126 /* Define to 1 if you have the `%(lib)s' library. */
127 /* #undef HAVE_%(LIB)s */
128
129 /* Define to 1 if you have the `hopefullynolib2' library. */
130 /* #undef HAVE_LIBHOPEFULLYNOLIB2 */
131
132 #endif /* CONFIG_H_SEEN */
133 """ % locals(), "\n", os.linesep)
134
135 test.run(stdout=expected_stdout)
136
137 config_h = test.read(test.workpath('config.h'))
138 if expected_config_h != config_h:
139     print "Unexpected config.h"
140     print "Expected: "
141     print "---------------------------------------------------------"
142     print repr(expected_config_h)
143     print "---------------------------------------------------------"
144     print "Found: "
145     print "---------------------------------------------------------"
146     print repr(config_h)
147     print "---------------------------------------------------------"
148     print "Stdio: "
149     print "---------------------------------------------------------"
150     print test.stdout()
151     print "---------------------------------------------------------"
152     test.fail_test()
153
154 expected_read_str = re.sub(r'\b((yes)|(no))\b',
155                            r'(cached) \1',
156                            expected_read_str)
157 expected_build_str = "scons: `.' is up to date.\n"
158 expected_stdout = test.wrap_stdout(build_str=expected_build_str,
159                                    read_str=expected_read_str)
160 #expected_stdout = string.replace(expected_stdout, "\n", os.linesep)
161
162 test.run(stdout=expected_stdout)    
163
164 config_h = test.read(test.workpath('config.h'))    
165 if expected_config_h != config_h:
166     print "Unexpected config.h"
167     print "Expected: "
168     print "---------------------------------------------------------"
169     print repr(expected_config_h)
170     print "---------------------------------------------------------"
171     print "Found: "
172     print "---------------------------------------------------------"
173     print repr(config_h)
174     print "---------------------------------------------------------"
175     print "Stdio: "
176     print "---------------------------------------------------------"
177     print test.stdout()
178     print "---------------------------------------------------------"
179     test.fail_test()
180
181 test.pass_test()
182
183 # Local Variables:
184 # tab-width:4
185 # indent-tabs-mode:nil
186 # End:
187 # vim: set expandtab tabstop=4 shiftwidth=4: