Clean up and simplify logic. TODO: scons -c isn't removing the .di files. Mainly...
[scons.git] / test / VariantDir / removed-files.py
blob113f667601f5262bdc03c18f97c26678c519f184
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 """
28 Test VariantDir handling of removal of source files.
30 A C++ Program is created and compiled. First, a header is missing. Then
31 the header is added and the compilation should succeed, then the header
32 is removed and the compilation should fail again.
34 Previous versions of SCons did not remove the header from the build
35 directory after the source directory's header was removed, which caused
36 the compilation to succeed even after the source file was removed.
38 Test case supplied by Patrick Mezard--many thanks.
39 """
41 import TestSCons
43 test = TestSCons.TestSCons()
45 #-------------------------------------------------------------------------------
46 #1- Create dep.cpp and the SConstruct. dep.h is missing and the build is
47 #expected to fail with 2.
48 #-------------------------------------------------------------------------------
50 test.subdir('src')
52 test.write(['src', 'dep.cpp'], """\
53 #include "dep.h"
55 int main(int argc, char* argv[])
57 return test_dep();
59 """)
61 test.write('SConstruct', """
62 env = Environment()
63 env.VariantDir('bin', 'src')
64 o = env.Object('bin/dep', 'bin/dep.cpp')
65 env.Program('bin/dep', o)
66 """)
68 test.run(arguments = '.', stderr=None, status=2)
71 #-------------------------------------------------------------------------------
72 #2- Add dep.h and check the build is OK.
73 #-------------------------------------------------------------------------------
75 test.write(['src', 'dep.h'], """\
76 #ifndef DEP_H
77 #define DEP_H
79 inline int test_dep()
81 return 1;
84 #endif //DEP_H
85 """)
87 test.run(arguments = '.')
90 #-------------------------------------------------------------------------------
91 #3- Remove dep.h. The build is expected to fail again like in [1].
92 #-------------------------------------------------------------------------------
94 test.unlink(['src', 'dep.h'])
96 test.run(arguments = '.', stderr=None, status=2)
99 test.pass_test()
101 # Local Variables:
102 # tab-width:4
103 # indent-tabs-mode:nil
104 # End:
105 # vim: set expandtab tabstop=4 shiftwidth=4: