diff options
Diffstat (limited to 'test/YACC')
| -rw-r--r-- | test/YACC/YACC.py | 93 | ||||
| -rw-r--r-- | test/YACC/YACCCOM.py | 72 | ||||
| -rw-r--r-- | test/YACC/YACCCOMSTR.py | 77 | ||||
| -rw-r--r-- | test/YACC/YACCFLAGS.py | 89 | ||||
| -rw-r--r-- | test/YACC/YACCHFILESUFFIX.py | 87 | ||||
| -rw-r--r-- | test/YACC/YACCHXXFILESUFFIX.py | 83 | ||||
| -rw-r--r-- | test/YACC/YACCVCGFILESUFFIX.py | 92 | ||||
| -rw-r--r-- | test/YACC/live-check-output-cleaned.py | 96 | ||||
| -rw-r--r-- | test/YACC/live.py | 175 |
9 files changed, 864 insertions, 0 deletions
diff --git a/test/YACC/YACC.py b/test/YACC/YACC.py new file mode 100644 index 0000000..59067f3 --- /dev/null +++ b/test/YACC/YACC.py @@ -0,0 +1,93 @@ +#!/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__" + +import os +import sys + +import TestSCons + +_python_ = TestSCons._python_ +_exe = TestSCons._exe + +if sys.platform == 'win32': + compiler = 'msvc' + linker = 'mslink' +else: + compiler = 'gcc' + linker = 'gnulink' + +test = TestSCons.TestSCons() + + + +test.write('myyacc.py', """ +import getopt +import sys +cmd_opts, args = getopt.getopt(sys.argv[1:], 'o:', []) +output = None +opt_string = '' +for opt, arg in cmd_opts: + if opt == '-o': output = open(arg, 'wb') + else: opt_string = opt_string + ' ' + opt +for a in args: + contents = open(a, 'rb').read() + output.write(contents.replace('YACC', 'myyacc.py')) +output.close() +sys.exit(0) +""") + + + +test.write('SConstruct', """ +env = Environment(YACC = r'%(_python_)s myyacc.py', tools=['default', 'yacc']) +env.CFile(target = 'aaa', source = 'aaa.y') +env.CFile(target = 'bbb', source = 'bbb.yacc') +env.CXXFile(target = 'ccc', source = 'ccc.yy') +env.CFile(target = 'ddd', source = 'ddd.ym') +""" % locals()) + +test.write('aaa.y', "aaa.y\nYACC\n") +test.write('bbb.yacc', "bbb.yacc\nYACC\n") +test.write('ccc.yy', "ccc.yacc\nYACC\n") +test.write('ddd.ym', "ddd.yacc\nYACC\n") + +test.run(arguments = '.', stderr = None) + +test.must_match('aaa.c', "aaa.y\nmyyacc.py\n") +test.must_match('bbb.c', "bbb.yacc\nmyyacc.py\n") +test.must_match('ccc.cc', "ccc.yacc\nmyyacc.py\n") +test.must_match('ddd.m', "ddd.yacc\nmyyacc.py\n") + + + + +test.pass_test() + +# Local Variables: +# tab-width:4 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=4 shiftwidth=4: diff --git a/test/YACC/YACCCOM.py b/test/YACC/YACCCOM.py new file mode 100644 index 0000000..4e43676 --- /dev/null +++ b/test/YACC/YACCCOM.py @@ -0,0 +1,72 @@ +#!/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 ability to configure the $YACCCOM construction variable. +""" + +import TestSCons + +_python_ = TestSCons._python_ + +test = TestSCons.TestSCons() + + + +test.write('myyacc.py', """ +import sys +outfile = open(sys.argv[1], 'wb') +for f in sys.argv[2:]: + infile = open(f, 'rb') + for l in [l for l in infile.readlines() if l != '/*yacc*/\\n']: + outfile.write(l) +sys.exit(0) +""") + +test.write('SConstruct', """ +env = Environment(tools=['default', 'yacc'], + YACCCOM = r'%(_python_)s myyacc.py $TARGET $SOURCES') +env.CFile(target = 'aaa', source = 'aaa.y') +env.CFile(target = 'bbb', source = 'bbb.yacc') +""" % locals()) + +test.write('aaa.y', "aaa.y\n/*yacc*/\n") +test.write('bbb.yacc', "bbb.yacc\n/*yacc*/\n") + +test.run(arguments = '.') + +test.must_match('aaa.c', "aaa.y\n") +test.must_match('bbb.c', "bbb.yacc\n") + + + +test.pass_test() + +# Local Variables: +# tab-width:4 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=4 shiftwidth=4: diff --git a/test/YACC/YACCCOMSTR.py b/test/YACC/YACCCOMSTR.py new file mode 100644 index 0000000..eaf3fde --- /dev/null +++ b/test/YACC/YACCCOMSTR.py @@ -0,0 +1,77 @@ +#!/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 that the $YACCCOMSTR construction variable allows you to customize +the displayed string when yacc is called. +""" + +import TestSCons + +_python_ = TestSCons._python_ + +test = TestSCons.TestSCons() + + + +test.write('myyacc.py', """ +import sys +outfile = open(sys.argv[1], 'wb') +for f in sys.argv[2:]: + infile = open(f, 'rb') + for l in [l for l in infile.readlines() if l != '/*yacc*/\\n']: + outfile.write(l) +sys.exit(0) +""") + +test.write('SConstruct', """ +env = Environment(tools=['default', 'yacc'], + YACCCOM = r'%(_python_)s myyacc.py $TARGET $SOURCES', + YACCCOMSTR = 'Yaccing $TARGET from $SOURCE') +env.CFile(target = 'aaa', source = 'aaa.y') +env.CFile(target = 'bbb', source = 'bbb.yacc') +""" % locals()) + +test.write('aaa.y', "aaa.y\n/*yacc*/\n") +test.write('bbb.yacc', "bbb.yacc\n/*yacc*/\n") + +test.run(stdout = test.wrap_stdout("""\ +Yaccing aaa.c from aaa.y +Yaccing bbb.c from bbb.yacc +""")) + +test.must_match('aaa.c', "aaa.y\n") +test.must_match('bbb.c', "bbb.yacc\n") + + + +test.pass_test() + +# Local Variables: +# tab-width:4 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=4 shiftwidth=4: diff --git a/test/YACC/YACCFLAGS.py b/test/YACC/YACCFLAGS.py new file mode 100644 index 0000000..f0b698b --- /dev/null +++ b/test/YACC/YACCFLAGS.py @@ -0,0 +1,89 @@ +#!/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__" + +import os +import sys + +import TestSCons + +_python_ = TestSCons._python_ +_exe = TestSCons._exe + +if sys.platform == 'win32': + compiler = 'msvc' + linker = 'mslink' +else: + compiler = 'gcc' + linker = 'gnulink' + +test = TestSCons.TestSCons() + +test.subdir('in') + + + +test.write('myyacc.py', """ +import getopt +import sys +cmd_opts, args = getopt.getopt(sys.argv[1:], 'o:I:x', []) +output = None +opt_string = '' +i_arguments = '' +for opt, arg in cmd_opts: + if opt == '-o': output = open(arg, 'wb') + elif opt == '-I': i_arguments = i_arguments + ' ' + arg + else: opt_string = opt_string + ' ' + opt +for a in args: + contents = open(a, 'rb').read() + contents = contents.replace('YACCFLAGS', opt_string) + contents = contents.replace('I_ARGS', i_arguments) + output.write(contents) +output.close() +sys.exit(0) +""") + +test.write('SConstruct', """ +env = Environment(YACC = r'%(_python_)s myyacc.py', + YACCFLAGS = '-x -I${TARGET.dir} -I${SOURCE.dir}', + tools=['yacc', '%(linker)s', '%(compiler)s']) +env.CFile(target = 'out/aaa', source = 'in/aaa.y') +""" % locals()) + +test.write(['in', 'aaa.y'], "aaa.y\nYACCFLAGS\nI_ARGS\n") + +test.run('.', stderr = None) + +test.must_match(['out', 'aaa.c'], "aaa.y\n -x\n out in\n") + + + +test.pass_test() + +# Local Variables: +# tab-width:4 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=4 shiftwidth=4: diff --git a/test/YACC/YACCHFILESUFFIX.py b/test/YACC/YACCHFILESUFFIX.py new file mode 100644 index 0000000..8801aea --- /dev/null +++ b/test/YACC/YACCHFILESUFFIX.py @@ -0,0 +1,87 @@ +#!/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 that setting the YACCHFILESUFFIX variable can reflect a yacc +utility that writes to an odd +""" + +import TestSCons + +_python_ = TestSCons._python_ + +test = TestSCons.TestSCons() + + + +test.write('myyacc.py', """\ +import getopt +import os.path +import sys +opts, args = getopt.getopt(sys.argv[1:], 'do:') +for o, a in opts: + if o == '-o': + outfile = open(a, 'wb') +for f in args: + infile = open(f, 'rb') + for l in [l for l in infile.readlines() if l != '/*yacc*/\\n']: + outfile.write(l) +outfile.close() +base, ext = os.path.splitext(args[0]) +open(base+'.hsuffix', 'wb').write(" ".join(sys.argv)+'\\n') +sys.exit(0) +""") + +test.write('SConstruct', """ +env = Environment(tools=['default', 'yacc'], + YACC = r'%(_python_)s myyacc.py', + YACCFLAGS = '-d', + YACCHFILESUFFIX = '.hsuffix') +env.CFile(target = 'aaa', source = 'aaa.y') +env.CFile(target = 'bbb', source = 'bbb.yacc') +""" % locals()) + +test.write('aaa.y', "aaa.y\n/*yacc*/\n") +test.write('bbb.yacc', "bbb.yacc\n/*yacc*/\n") + +test.run(arguments = '.') + +test.must_match('aaa.c', "aaa.y\n") +test.must_match('aaa.hsuffix', "myyacc.py -d -o aaa.c aaa.y\n") +test.must_match('bbb.c', "bbb.yacc\n") +test.must_match('bbb.hsuffix', "myyacc.py -d -o bbb.c bbb.yacc\n") + +test.up_to_date(arguments = '.') + + + +test.pass_test() + +# Local Variables: +# tab-width:4 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=4 shiftwidth=4: diff --git a/test/YACC/YACCHXXFILESUFFIX.py b/test/YACC/YACCHXXFILESUFFIX.py new file mode 100644 index 0000000..6664356 --- /dev/null +++ b/test/YACC/YACCHXXFILESUFFIX.py @@ -0,0 +1,83 @@ +#!/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 that setting the YACCHXXFILESUFFIX variable can reflect a yacc +utility that writes to an odd +""" + +import TestSCons + +_python_ = TestSCons._python_ + +test = TestSCons.TestSCons() + + + +test.write('myyacc.py', """\ +import getopt +import os.path +import sys +opts, args = getopt.getopt(sys.argv[1:], 'do:') +for o, a in opts: + if o == '-o': + outfile = open(a, 'wb') +for f in args: + infile = open(f, 'rb') + for l in [l for l in infile.readlines() if l != '/*yacc*/\\n']: + outfile.write(l) +outfile.close() +base, ext = os.path.splitext(args[0]) +open(base+'.hxxsuffix', 'wb').write(" ".join(sys.argv)+'\\n') +sys.exit(0) +""") + +test.write('SConstruct', """ +env = Environment(tools=['default', 'yacc'], + YACC = r'%(_python_)s myyacc.py', + YACCFLAGS = '-d', + YACCHXXFILESUFFIX = '.hxxsuffix') +env.CXXFile(target = 'aaa', source = 'aaa.yy') +""" % locals()) + +test.write('aaa.yy', "aaa.yy\n/*yacc*/\n") + +test.run(arguments = '.') + +test.must_match('aaa.cc', "aaa.yy\n") +test.must_match('aaa.hxxsuffix', "myyacc.py -d -o aaa.cc aaa.yy\n") + +test.up_to_date(arguments = '.') + + + +test.pass_test() + +# Local Variables: +# tab-width:4 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=4 shiftwidth=4: diff --git a/test/YACC/YACCVCGFILESUFFIX.py b/test/YACC/YACCVCGFILESUFFIX.py new file mode 100644 index 0000000..0327d8a --- /dev/null +++ b/test/YACC/YACCVCGFILESUFFIX.py @@ -0,0 +1,92 @@ +#!/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 setting the YACCVCGFILESUFFIX variable. +""" + +import TestSCons + +_python_ = TestSCons._python_ + +test = TestSCons.TestSCons() + + + +test.write('myyacc.py', """\ +import getopt +import os.path +import sys +vcg = None +opts, args = getopt.getopt(sys.argv[1:], 'go:') +for o, a in opts: + if o == '-g': + vcg = 1 + elif o == '-o': + outfile = open(a, 'wb') +for f in args: + infile = open(f, 'rb') + for l in [l for l in infile.readlines() if l != '/*yacc*/\\n']: + outfile.write(l) +outfile.close() +if vcg: + base, ext = os.path.splitext(args[0]) + open(base+'.vcgsuffix', 'wb').write(" ".join(sys.argv)+'\\n') +sys.exit(0) +""") + +test.write('SConstruct', """ +env = Environment(tools=['default', 'yacc'], + YACC = r'%(_python_)s myyacc.py', + YACCVCGFILESUFFIX = '.vcgsuffix') +env.CXXFile(target = 'aaa', source = 'aaa.yy') +env.CXXFile(target = 'bbb', source = 'bbb.yy', YACCFLAGS = '-g') +""" % locals()) + +test.write('aaa.yy', "aaa.yy\n/*yacc*/\n") +test.write('bbb.yy', "bbb.yy\n/*yacc*/\n") + +test.run(arguments = '.') + +test.must_match('aaa.cc', "aaa.yy\n") +test.must_not_exist('aaa.vcg') +test.must_not_exist('aaa.vcgsuffix') + +test.must_match('bbb.cc', "bbb.yy\n") +test.must_not_exist('bbb.vcg') +test.must_match('bbb.vcgsuffix', "myyacc.py -g -o bbb.cc bbb.yy\n") + +test.up_to_date(arguments = '.') + + + +test.pass_test() + +# Local Variables: +# tab-width:4 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=4 shiftwidth=4: diff --git a/test/YACC/live-check-output-cleaned.py b/test/YACC/live-check-output-cleaned.py new file mode 100644 index 0000000..a6240c9 --- /dev/null +++ b/test/YACC/live-check-output-cleaned.py @@ -0,0 +1,96 @@ +#!/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 that .output file is cleaned +""" + +import TestSCons + +_exe = TestSCons._exe + +test = TestSCons.TestSCons() + +yacc = test.where_is('yacc') or test.where_is('bison') + +if not yacc: + test.skip_test('No yacc or bison found; skipping test.\n') + +test.write('SConstruct', """ +foo = Environment(YACCFLAGS='-v -d') +foo.CFile(source = 'foo.y') +""" % locals()) + +yacc = r""" +%%{ +#include <stdio.h> + +main() +{ + yyparse(); +} + +yyerror(s) +char *s; +{ + fprintf(stderr, "%%s\n", s); + return 0; +} + +yylex() +{ + int c; + + c = fgetc(stdin); + return (c == EOF) ? 0 : c; +} +%%} +%%%% +input: letter newline { printf("%s\n"); }; +letter: 'a' | 'b'; +newline: '\n'; +""" + +test.write('foo.y', yacc % 'foo.y') + +test.run('.', stderr = None) + +test.up_to_date(arguments = 'foo.c') + +test.must_exist(test.workpath('foo.output')) +test.must_exist(test.workpath('foo.c')) + +test.run(arguments = '-c .') +test.must_not_exist(test.workpath('foo.output')) +test.must_not_exist(test.workpath('foo.c')) + +test.pass_test() + +# Local Variables: +# tab-width:4 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=4 shiftwidth=4: diff --git a/test/YACC/live.py b/test/YACC/live.py new file mode 100644 index 0000000..d567ec3 --- /dev/null +++ b/test/YACC/live.py @@ -0,0 +1,175 @@ +#!/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 YACC and YACCFLAGS with a live yacc compiler. +""" + +import TestSCons + +_exe = TestSCons._exe +_python_ = TestSCons._python_ + +test = TestSCons.TestSCons() + +yacc = test.where_is('yacc') or test.where_is('bison') + +if not yacc: + test.skip_test('No yacc or bison found; skipping test.\n') + +test.write("wrapper.py", +"""import os +import sys +open('%s', 'wb').write("wrapper.py\\n") +os.system(" ".join(sys.argv[1:])) +""" % test.workpath('wrapper.out').replace('\\', '\\\\')) + +test.write('SConstruct', """ +foo = Environment(YACCFLAGS='-d') +yacc = foo.Dictionary('YACC') +bar = Environment(YACC = r'%(_python_)s wrapper.py ' + yacc) +foo.Program(target = 'foo', source = 'foo.y') +bar.Program(target = 'bar', source = 'bar.y') +foo.Program(target = 'hello', source = ['hello.cpp']) +foo.CXXFile(target = 'file.cpp', source = ['file.yy'], YACCFLAGS='-d') +foo.CFile(target = 'not_foo', source = 'foo.y') +""" % locals()) + +yacc = r""" +%%{ +#include <stdio.h> + +main() +{ + yyparse(); +} + +yyerror(s) +char *s; +{ + fprintf(stderr, "%%s\n", s); + return 0; +} + +yylex() +{ + int c; + + c = fgetc(stdin); + return (c == EOF) ? 0 : c; +} +%%} +%%%% +input: letter newline { printf("%s\n"); }; +letter: 'a' | 'b'; +newline: '\n'; +""" + +test.write("file.yy", """\ +%token GRAPH_T NODE_T EDGE_T DIGRAPH_T EDGEOP_T SUBGRAPH_T + +%% +graph: GRAPH_T + ; + +%% +""") + +# Apparently, OS X now creates file.hpp like everybody else +# I have no idea when it changed; it was fixed in 10.4 +#import sys +#if sys.platform[:6] == 'darwin': +# file_hpp = 'file.cpp.h' +#else: +# file_hpp = 'file.hpp' +file_hpp = 'file.hpp' + +test.write("hello.cpp", """\ +#include "%(file_hpp)s" + +int main() +{ +} +""" % locals()) + +test.write('foo.y', yacc % 'foo.y') + +test.write('bar.y', yacc % 'bar.y') + + + +test.run(arguments = 'foo' + _exe, stderr = None) + +test.up_to_date(arguments = 'foo' + _exe) + +test.must_not_exist(test.workpath('wrapper.out')) + +test.run(program = test.workpath('foo'), stdin = "a\n", stdout = "foo.y\n") + +test.must_exist(test.workpath('foo.h')) + +test.run(arguments = '-c .') + +test.must_not_exist(test.workpath('foo.h')) + + + +test.run(arguments = 'not_foo.c') + +test.up_to_date(arguments = 'not_foo.c') + +test.must_not_exist(test.workpath('foo.h')) +test.must_exist(test.workpath('not_foo.h')) + +test.run(arguments = '-c .') + +test.must_not_exist(test.workpath('not_foo.h')) + + + +test.run(arguments = 'bar' + _exe) + +test.up_to_date(arguments = 'bar' + _exe) + +test.must_match(test.workpath('wrapper.out'), "wrapper.py\n") + +test.run(program = test.workpath('bar'), stdin = "b\n", stdout = "bar.y\n") + + + +test.run(arguments = '.') + +test.up_to_date(arguments = '.') + + + +test.pass_test() + +# Local Variables: +# tab-width:4 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=4 shiftwidth=4: |
