Merge pull request #4553 from mwichmann/clone-variables
[scons.git] / test / exitfns.py
blobee2ada19452fdc382a81293e708aff477527319b
1 #!/usr/bin/env python
3 # __COPYRIGHT__
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:
13 # The above copyright notice and this permission notice shall be included
14 # in all copies or substantial portions of the Software.
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.
25 __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
27 import TestSCons
28 test = TestSCons.TestSCons()
30 # also exclude these tests since it overides the exit function which doesnt work with coverage
31 # # more info here: https://coverage.readthedocs.io/en/coverage-4.4.2/subprocess.html#
32 # TODO: figure out how to cover tests which use exit functions
33 if test.coverage_run():
34 test.skip_test("This test replaces the exit function which is needed by coverage to write test data; skipping test.")
36 sconstruct = """
37 from SCons.exitfuncs import register
39 def x1():
40 print("running x1")
41 def x2(n):
42 print("running x2(%s)" % repr(n))
43 def x3(n, kwd=None):
44 print("running x3(%s, kwd=%s)" % (repr(n), repr(kwd)))
46 register(x3, "no kwd args")
47 register(x1)
48 register(x2, 12)
49 register(x3, 5, kwd="bar")
50 register(x3, "no kwd args")
52 """
54 expected_output = test.wrap_stdout("scons: `.' is up to date.\n") + \
55 """running x3('no kwd args', kwd=None)
56 running x3(5, kwd='bar')
57 running x2(12)
58 running x1
59 running x3('no kwd args', kwd=None)
60 """
62 test.write('SConstruct', sconstruct)
64 test.run(arguments='-f SConstruct .', stdout = expected_output)
66 test.write('SConstruct', """import sys
67 def f():
68 pass
70 sys.exitfunc = f
71 """ + sconstruct)
73 test.run(arguments='-f SConstruct .', stdout = expected_output)
75 test.pass_test()
77 # Local Variables:
78 # tab-width:4
79 # indent-tabs-mode:nil
80 # End:
81 # vim: set expandtab tabstop=4 shiftwidth=4: