Add emacs and vim editing settings to the bottom of *.py files.
[scons.git] / test / Configure / custom-tests.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 execution of custom test cases.
29 """
30
31 import TestSCons
32
33 _exe = TestSCons._exe
34 _obj = TestSCons._obj
35 _python_ = TestSCons._python_
36
37 test = TestSCons.TestSCons()
38
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
43
44 compileOK = '#include <stdio.h>\\nint main() {printf("Hello");return 0;}'
45 compileFAIL = "syntax error"
46 linkOK = compileOK
47 linkFAIL = "void myFunc(); int main() { myFunc(); }"
48 runOK = compileOK
49 runFAIL = "int main() { return 1; }"
50
51 test.write('pyAct.py', """\
52 import sys
53 print sys.argv[1]
54 sys.exit(int(sys.argv[1]))
55 """)
56
57 test.write('SConstruct', """\
58 def CheckCustom(test):
59     test.Message( 'Executing MyTest ... ' )
60     retCompileOK                = test.TryCompile( '%(compileOK)s', '.c' )
61     retCompileFAIL              = test.TryCompile( '%(compileFAIL)s', '.c' )
62     retLinkOK                   = test.TryLink( '%(linkOK)s', '.c' )
63     retLinkFAIL                 = test.TryLink( '%(linkFAIL)s', '.c' )
64     (retRunOK, outputRunOK)     = test.TryRun( '%(runOK)s', '.c' )
65     (retRunFAIL, outputRunFAIL) = test.TryRun( '%(runFAIL)s', '.c' )
66     (retActOK, outputActOK) = test.TryAction( '%(_python_)s pyAct.py 0 > $TARGET' )
67     (retActFAIL, outputActFAIL) = test.TryAction( '%(_python_)s pyAct.py 1 > $TARGET' )
68     resOK = retCompileOK and retLinkOK and retRunOK and outputRunOK=="Hello"
69     resOK = resOK and retActOK and int(outputActOK)==0
70     resFAIL = retCompileFAIL or retLinkFAIL or retRunFAIL or outputRunFAIL!=""
71     resFAIL = resFAIL or retActFAIL or outputActFAIL!=""
72     test.Result( int(resOK and not resFAIL) )
73     return resOK and not resFAIL
74
75 env = Environment()
76 import os
77 env.AppendENVPath('PATH', os.environ['PATH'])
78 conf = Configure( env, custom_tests={'CheckCustom' : CheckCustom} )
79 conf.CheckCustom()
80 env = conf.Finish()
81 """ % locals())
82
83 test.run()
84
85 test.checkLogAndStdout(["Executing MyTest ... "],
86                       ["yes"],
87                       [[(('.c', NCR), (_obj, NCR)),
88                         (('.c', NCR), (_obj, NCF)),
89                         (('.c', NCR), (_obj, NCR), (_exe, NCR)),
90                         (('.c', NCR), (_obj, NCR), (_exe, NCF)),
91                         (('.c', NCR), (_obj, NCR), (_exe, NCR), (_exe + '.out', NCR)),
92                         (('.c', NCR), (_obj, NCR), (_exe, NCR), (_exe + '.out', NCF)),
93                         (('', NCR),),
94                         (('', NCF),)]],
95                        "config.log", ".sconf_temp", "SConstruct")
96
97 test.run()
98
99 test.checkLogAndStdout(["Executing MyTest ... "],
100                       ["yes"],
101                       [[(('.c', CR), (_obj, CR)),
102                         (('.c', CR), (_obj, CF)),
103                         (('.c', CR), (_obj, CR), (_exe, CR)),
104                         (('.c', CR), (_obj, CR), (_exe, CF)),
105                         (('.c', CR), (_obj, CR), (_exe, CR), (_exe + '.out', CR)),
106                         (('.c', CR), (_obj, CR), (_exe, CR), (_exe + '.out', CF)),
107                         (('', CR),),
108                         (('', CF),)]],
109                        "config.log", ".sconf_temp", "SConstruct")
110
111 test.pass_test()
112
113 # Local Variables:
114 # tab-width:4
115 # indent-tabs-mode:nil
116 # End:
117 # vim: set expandtab tabstop=4 shiftwidth=4: