diff options
-rw-r--r-- | test/ESCAPE.py | 65 | ||||
-rw-r--r-- | test/SHELL.py | 81 | ||||
-rw-r--r-- | test/SPAWN.py | 62 |
3 files changed, 208 insertions, 0 deletions
diff --git a/test/ESCAPE.py b/test/ESCAPE.py new file mode 100644 index 0000000..bee55bc --- /dev/null +++ b/test/ESCAPE.py @@ -0,0 +1,65 @@ +#!/usr/bin/env python +# +# __COPYRIGHT__ +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject to +# the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY +# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE +# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +# + +__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" + +""" +Test the ESCAPE construction variable. +""" + +import TestSCons + +python = TestSCons.python + +test = TestSCons.TestSCons() + +test.write('cat.py', """\ +import sys +ofp = open(sys.argv[1], 'wb') +for s in sys.argv[2:]: + ofp.write(open(s, 'rb').read()) +ofp.close() +""") + +test.write('SConstruct', """\ +import string +# We still need to run this through the original ESCAPE function, +# because that's set up to work in tandem with the existing SHELL, +# which we're not replacing. +orig_escape = Environment()['ESCAPE'] +def my_escape(s): + s = string.replace(s, 'file.in', 'file.xxx') + return orig_escape(s) +env = Environment(ESCAPE = my_escape) +env.Command('file.out', 'file.in', "%(python)s cat.py $TARGET $SOURCES") +""" % locals()) + +test.write('file.in', "file.in\n") +test.write('file.xxx', "file.xxx\n") + +test.run() + +test.must_match('file.out', "file.xxx\n") + +test.pass_test() diff --git a/test/SHELL.py b/test/SHELL.py new file mode 100644 index 0000000..9082dbd --- /dev/null +++ b/test/SHELL.py @@ -0,0 +1,81 @@ +#!/usr/bin/env python +# +# __COPYRIGHT__ +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject to +# the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY +# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE +# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +# + +__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" + +""" +Test the SHELL construction variable. +""" + +import os +import sys + + +import TestSCons + +python = TestSCons.python + +test = TestSCons.TestSCons() + +if sys.platform == 'win32': + sys.stderr.write('Cannot set SHELL separately from other variables on win32.\n') + test.no_result(1) + +my_shell = test.workpath('my_shell.py') + +test.write(my_shell, """\ +#!%(python)s +import os +import string +import sys +cmd = sys.argv[2] +def stripquote(s): + if s[0] == '"' and s[-1] == '"' or \ + s[0] == "'" and s[-1] == "'": + s = s[1:-1] + return s +args = string.split(stripquote(sys.argv[2])) +args = map(stripquote, args) +ofp = open(args[2], 'wb') +for f in args[3:] + ['extra.txt']: + ofp.write(open(f, 'rb').read()) +ofp.close() +sys.exit(0) +""" % locals()) + +os.chmod(my_shell, 0755) + +test.write('SConstruct', """\ +env = Environment(SHELL = r'%(my_shell)s') +env.Command('file.out', 'file.in', "%(python)s fake_cat_program $TARGET $SOURCES") +""" % locals()) + +test.write('file.in', "file.in\n") +test.write('extra.txt', "extra.txt\n") + +test.run() + +test.must_match('file.out', "file.in\nextra.txt\n") + +test.pass_test() diff --git a/test/SPAWN.py b/test/SPAWN.py new file mode 100644 index 0000000..e6eb65e --- /dev/null +++ b/test/SPAWN.py @@ -0,0 +1,62 @@ +#!/usr/bin/env python +# +# __COPYRIGHT__ +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject to +# the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY +# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE +# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +# + +__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" + +""" +Test the SPAWN construction variable. +""" + +import TestSCons + +python = TestSCons.python + +test = TestSCons.TestSCons() + +test.write('cat.py', """\ +import sys +ofp = open(sys.argv[1], 'wb') +for s in sys.argv[2:]: + ofp.write(open(s, 'rb').read()) +ofp.close() +""") + +test.write('SConstruct', """ +import os +import string +def my_spawn(sh, escape, cmd, args, env): + os.system(string.join(args + ['extra.txt'])) +env = Environment(SPAWN = my_spawn) +env.Command('file.out', 'file.in', "%(python)s cat.py $TARGET $SOURCES") +env = Environment() +""" % locals()) + +test.write('file.in', "file.in\n") +test.write('extra.txt', "extra.txt\n") + +test.run(arguments = '.') + +test.must_match('file.out', "file.in\nextra.txt\n") + +test.pass_test() |