5 # Copyright The SCons Foundation
7 # Permission is hereby granted, free of charge, to any person obtaining
8 # a copy of this software and associated documentation files (the
9 # "Software"), to deal in the Software without restriction, including
10 # without limitation the rights to use, copy, modify, merge, publish,
11 # distribute, sublicense, and/or sell copies of the Software, and to
12 # permit persons to whom the Software is furnished to do so, subject to
13 # the following conditions:
15 # The above copyright notice and this permission notice shall be included
16 # in all copies or substantial portions of the Software.
18 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
19 # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
20 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE
27 Verify execution of custom test cases.
35 _python_
= TestSCons
._python
_
37 test
= TestSCons
.TestSCons()
39 NCR
= test
.NCR
# non-cached rebuild
40 CR
= test
.CR
# cached rebuild (up to date)
41 NCF
= test
.NCF
# non-cached build failure
42 CF
= test
.CF
# cached build failure
44 compileOK
= '#include <stdio.h>\\nint main(void) {printf("Hello");return 0;}'
45 compileFAIL
= "syntax error"
47 linkFAIL
= "void myFunc(); int main(void) { myFunc(); }"
49 runFAIL
= "int main(void) { return 1; }"
51 test
.write('pyAct.py', """\
54 sys.exit(int(sys.argv[1]))
57 test
.write('SConstruct', """\
58 DefaultEnvironment(tools=[])
59 def CheckCustom(test):
60 test.Message( 'Executing MyTest ... ' )
61 retCompileOK = test.TryCompile( '%(compileOK)s', '.c' )
62 retCompileFAIL = test.TryCompile( '%(compileFAIL)s', '.c' )
63 retLinkOK = test.TryLink( '%(linkOK)s', '.c' )
64 retLinkFAIL = test.TryLink( '%(linkFAIL)s', '.c' )
65 (retRunOK, outputRunOK) = test.TryRun( '%(runOK)s', '.c' )
66 (retRunFAIL, outputRunFAIL) = test.TryRun( '%(runFAIL)s', '.c' )
67 (retActOK, outputActOK) = test.TryAction( r'%(_python_)s pyAct.py 0 > $TARGET' )
68 (retActFAIL, outputActFAIL) = test.TryAction( r'%(_python_)s pyAct.py 1 > $TARGET' )
69 resOK = retCompileOK and retLinkOK and retRunOK and outputRunOK=="Hello"
70 resOK = resOK and retActOK and int(outputActOK)==0
71 resFAIL = retCompileFAIL or retLinkFAIL or retRunFAIL or outputRunFAIL!=""
72 resFAIL = resFAIL or retActFAIL or outputActFAIL!=""
73 test.Result( resOK and not resFAIL )
74 return resOK and not resFAIL
78 env.AppendENVPath('PATH', os.environ['PATH'])
79 conf = Configure( env, custom_tests={'CheckCustom' : CheckCustom} )
86 test
.checkLogAndStdout(["Executing MyTest ... "],
88 [[(('.c', NCR
), (_obj
, NCR
)),
89 (('.c', NCR
), (_obj
, NCF
)),
90 (('.c', NCR
), (_obj
, NCR
), (_exe
, NCR
)),
91 (('.c', NCR
), (_obj
, NCR
), (_exe
, NCF
)),
92 (('.c', NCR
), (_obj
, NCR
), (_exe
, NCR
), (_exe
+ '.out', NCR
)),
93 (('.c', NCR
), (_obj
, NCR
), (_exe
, NCR
), (_exe
+ '.out', NCF
)),
96 "config.log", ".sconf_temp", "SConstruct")
100 # Try again to check caching
101 test
.checkLogAndStdout(["Executing MyTest ... "],
103 [[(('.c', CR
), (_obj
, CR
)),
104 (('.c', CR
), (_obj
, CF
)),
105 (('.c', CR
), (_obj
, CR
), (_exe
, CR
)),
106 (('.c', CR
), (_obj
, CR
), (_exe
, CF
)),
107 (('.c', CR
), (_obj
, CR
), (_exe
, CR
), (_exe
+ '.out', CR
)),
108 (('.c', CR
), (_obj
, CR
), (_exe
, CR
), (_exe
+ '.out', CF
)),
111 "config.log", ".sconf_temp", "SConstruct")
113 # Test other customs:
114 test
.write('SConstruct', """\
116 test.Message( 'Display of list ...' )
121 def CheckEmptyList(test):
122 test.Message( 'Display of empty list ...' )
127 def CheckRandomStr(test):
128 test.Message( 'Display of random string ...' )
129 res = "a random string"
133 def CheckEmptyStr(test):
134 test.Message( 'Display of empty string ...' )
140 test.Message( 'Display of dictionary ...' )
141 res = {"key1" : 1, "key2" : "text"}
145 def CheckEmptyDict(test):
146 test.Message( 'Display of empty dictionary ...' )
153 env.AppendENVPath('PATH', os.environ['PATH'])
154 conf = Configure( env, custom_tests={'CheckList' : CheckList,
155 'CheckEmptyList' : CheckEmptyList,
156 'CheckRandomStr' : CheckRandomStr,
157 'CheckEmptyStr' : CheckEmptyStr,
158 'CheckDict' : CheckDict,
159 'CheckEmptyDict' : CheckEmptyDict} )
161 conf.CheckEmptyList()
162 conf.CheckRandomStr()
165 conf.CheckEmptyDict()
171 test
.must_match('config.log',
174 scons: Configure: Display of list ...
175 scons: Configure: \(cached\) yes
177 scons: Configure: Display of empty list ...
178 scons: Configure: \(cached\) no
180 scons: Configure: Display of random string ...
181 scons: Configure: \(cached\) a random string
183 scons: Configure: Display of empty string ...
184 scons: Configure: \(cached\) *
186 scons: Configure: Display of dictionary ...
187 scons: Configure: \(cached\) yes
189 scons: Configure: Display of empty dictionary ...
190 scons: Configure: \(cached\) yes
194 match
=TestSCons
.match_re
)
200 # indent-tabs-mode:nil
202 # vim: set expandtab tabstop=4 shiftwidth=4: