diff options
Diffstat (limited to 'test/Variables')
| -rw-r--r-- | test/Variables/BoolVariable.py | 89 | ||||
| -rw-r--r-- | test/Variables/EnumVariable.py | 110 | ||||
| -rw-r--r-- | test/Variables/ListVariable.py | 181 | ||||
| -rw-r--r-- | test/Variables/PackageVariable.py | 92 | ||||
| -rw-r--r-- | test/Variables/PathVariable.py | 293 | ||||
| -rw-r--r-- | test/Variables/Variables.py | 366 | ||||
| -rw-r--r-- | test/Variables/chdir.py | 76 | ||||
| -rw-r--r-- | test/Variables/help.py | 148 | ||||
| -rw-r--r-- | test/Variables/import.py | 74 |
9 files changed, 1429 insertions, 0 deletions
diff --git a/test/Variables/BoolVariable.py b/test/Variables/BoolVariable.py new file mode 100644 index 0000000..365567e --- /dev/null +++ b/test/Variables/BoolVariable.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__" + +""" +Test the BoolVariable canned Variable type. +""" + +import os + +import TestSCons + +test = TestSCons.TestSCons() + +SConstruct_path = test.workpath('SConstruct') + +def check(expect): + result = test.stdout().split('\n') + assert result[1:len(expect)+1] == expect, (result[1:len(expect)+1], expect) + + + +test.write(SConstruct_path, """\ +from SCons.Variables.BoolVariable import BoolVariable +BV = BoolVariable + +from SCons.Variables import BoolVariable + +opts = Variables(args=ARGUMENTS) +opts.AddVariables( + BoolVariable('warnings', 'compilation with -Wall and similiar', 1), + BV('profile', 'create profiling informations', 0), + ) + +env = Environment(variables=opts) +Help(opts.GenerateHelpText(env)) + +print env['warnings'] +print env['profile'] + +Default(env.Alias('dummy', None)) +""") + + + +test.run() +check([str(True), str(False)]) + +test.run(arguments='warnings=0 profile=no profile=true') +check([str(False), str(True)]) + +expect_stderr = """ +scons: *** Error converting option: warnings +Invalid value for boolean option: irgendwas +""" + test.python_file_line(SConstruct_path, 12) + +test.run(arguments='warnings=irgendwas', stderr = expect_stderr, status=2) + + + +test.pass_test() + +# Local Variables: +# tab-width:4 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=4 shiftwidth=4: diff --git a/test/Variables/EnumVariable.py b/test/Variables/EnumVariable.py new file mode 100644 index 0000000..c04b396 --- /dev/null +++ b/test/Variables/EnumVariable.py @@ -0,0 +1,110 @@ +#!/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 EnumVariable canned Variable type. +""" + +import os.path + +import TestSCons + +test = TestSCons.TestSCons() + +SConstruct_path = test.workpath('SConstruct') + +def check(expect): + result = test.stdout().split('\n') + assert result[1:len(expect)+1] == expect, (result[1:len(expect)+1], expect) + + + +test.write(SConstruct_path, """\ +from SCons.Variables.EnumVariable import EnumVariable +EV = EnumVariable + +from SCons.Variables import EnumVariable + +list_of_libs = Split('x11 gl qt ical') + +opts = Variables(args=ARGUMENTS) +opts.AddVariables( + EnumVariable('debug', 'debug output and symbols', 'no', + allowed_values=('yes', 'no', 'full'), + map={}, ignorecase=0), # case sensitive + EnumVariable('guilib', 'gui lib to use', 'gtk', + allowed_values=('motif', 'gtk', 'kde'), + map={}, ignorecase=1), # case insensitive + EV('some', 'some option', 'xaver', + allowed_values=('xaver', 'eins'), + map={}, ignorecase=2), # make lowercase + ) + +env = Environment(variables=opts) +Help(opts.GenerateHelpText(env)) + +print env['debug'] +print env['guilib'] +print env['some'] + +Default(env.Alias('dummy', None)) +""") + + +test.run(); check(['no', 'gtk', 'xaver']) + +test.run(arguments='debug=yes guilib=Motif some=xAVER') +check(['yes', 'Motif', 'xaver']) + +test.run(arguments='debug=full guilib=KdE some=EiNs') +check(['full', 'KdE', 'eins']) + +expect_stderr = """ +scons: *** Invalid value for option debug: FULL. Valid values are: ('yes', 'no', 'full') +""" + test.python_file_line(SConstruct_path, 21) + +test.run(arguments='debug=FULL', stderr=expect_stderr, status=2) + +expect_stderr = """ +scons: *** Invalid value for option guilib: irgendwas. Valid values are: ('motif', 'gtk', 'kde') +""" + test.python_file_line(SConstruct_path, 21) + +test.run(arguments='guilib=IrGeNdwas', stderr=expect_stderr, status=2) + +expect_stderr = """ +scons: *** Invalid value for option some: irgendwas. Valid values are: ('xaver', 'eins') +""" + test.python_file_line(SConstruct_path, 21) + +test.run(arguments='some=IrGeNdwas', stderr=expect_stderr, status=2) + + +test.pass_test() + +# Local Variables: +# tab-width:4 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=4 shiftwidth=4: diff --git a/test/Variables/ListVariable.py b/test/Variables/ListVariable.py new file mode 100644 index 0000000..e5be625 --- /dev/null +++ b/test/Variables/ListVariable.py @@ -0,0 +1,181 @@ +#!/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 ListVariable canned Variable type. +""" + +import os + +import TestSCons + +test = TestSCons.TestSCons() + +SConstruct_path = test.workpath('SConstruct') + +def check(expect): + result = test.stdout().split('\n') + r = result[1:len(expect)+1] + assert r == expect, (r, expect) + + + +test.write(SConstruct_path, """\ +from SCons.Variables.ListVariable import ListVariable +LV = ListVariable + +from SCons.Variables import ListVariable + +list_of_libs = Split('x11 gl qt ical') + +optsfile = 'scons.variables' +opts = Variables(optsfile, args=ARGUMENTS) +opts.AddVariables( + ListVariable('shared', + 'libraries to build as shared libraries', + 'all', + names = list_of_libs, + map = {'GL':'gl', 'QT':'qt'}), + LV('listvariable', 'listvariable help', 'all', names=['l1', 'l2', 'l3']) + ) + +env = Environment(variables=opts) +opts.Save(optsfile, env) +Help(opts.GenerateHelpText(env)) + +print env['shared'] +if 'ical' in env['shared']: print '1' +else: print '0' +for x in env['shared']: + print x, +print +print env.subst('$shared') +# Test subst_path() because it's used in $CPPDEFINES expansions. +print env.subst_path('$shared') +Default(env.Alias('dummy', None)) +""") + +test.run() +check(['all', '1', 'gl ical qt x11', 'gl ical qt x11', + "['gl ical qt x11']"]) + +expect = "shared = 'all'"+os.linesep+"listvariable = 'all'"+os.linesep +test.must_match(test.workpath('scons.variables'), expect) + +check(['all', '1', 'gl ical qt x11', 'gl ical qt x11', + "['gl ical qt x11']"]) + +test.run(arguments='shared=none') +check(['none', '0', '', '', "['']"]) + +test.run(arguments='shared=') +check(['none', '0', '', '', "['']"]) + +test.run(arguments='shared=x11,ical') +check(['ical,x11', '1', 'ical x11', 'ical x11', + "['ical x11']"]) + +test.run(arguments='shared=x11,,ical,,') +check(['ical,x11', '1', 'ical x11', 'ical x11', + "['ical x11']"]) + +test.run(arguments='shared=GL') +check(['gl', '0', 'gl', 'gl']) + +test.run(arguments='shared=QT,GL') +check(['gl,qt', '0', 'gl qt', 'gl qt', "['gl qt']"]) + + +expect_stderr = """ +scons: *** Error converting option: shared +Invalid value(s) for option: foo +""" + test.python_file_line(SConstruct_path, 19) + +test.run(arguments='shared=foo', stderr=expect_stderr, status=2) + +# be paranoid in testing some more combinations + +expect_stderr = """ +scons: *** Error converting option: shared +Invalid value(s) for option: foo +""" + test.python_file_line(SConstruct_path, 19) + +test.run(arguments='shared=foo,ical', stderr=expect_stderr, status=2) + +expect_stderr = """ +scons: *** Error converting option: shared +Invalid value(s) for option: foo +""" + test.python_file_line(SConstruct_path, 19) + +test.run(arguments='shared=ical,foo', stderr=expect_stderr, status=2) + +expect_stderr = """ +scons: *** Error converting option: shared +Invalid value(s) for option: foo +""" + test.python_file_line(SConstruct_path, 19) + +test.run(arguments='shared=ical,foo,x11', stderr=expect_stderr, status=2) + +expect_stderr = """ +scons: *** Error converting option: shared +Invalid value(s) for option: foo,bar +""" + test.python_file_line(SConstruct_path, 19) + +test.run(arguments='shared=foo,x11,,,bar', stderr=expect_stderr, status=2) + + + +test.write('SConstruct', """ +from SCons.Variables import ListVariable + +opts = Variables(args=ARGUMENTS) +opts.AddVariables( + ListVariable('gpib', + 'comment', + ['ENET', 'GPIB'], + names = ['ENET', 'GPIB', 'LINUX_GPIB', 'NO_GPIB']), + ) + +env = Environment(variables=opts) +Help(opts.GenerateHelpText(env)) + +print env['gpib'] +Default(env.Alias('dummy', None)) +""") + +test.run(stdout=test.wrap_stdout(read_str="ENET,GPIB\n", build_str="""\ +scons: Nothing to be done for `dummy'. +""")) + + + +test.pass_test() + +# Local Variables: +# tab-width:4 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=4 shiftwidth=4: diff --git a/test/Variables/PackageVariable.py b/test/Variables/PackageVariable.py new file mode 100644 index 0000000..322bc9b --- /dev/null +++ b/test/Variables/PackageVariable.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 the PackageVariable canned Variable type. +""" + +import os + +import TestSCons + +test = TestSCons.TestSCons() + +SConstruct_path = test.workpath('SConstruct') + +def check(expect): + result = test.stdout().split('\n') + assert result[1:len(expect)+1] == expect, (result[1:len(expect)+1], expect) + + + +test.write(SConstruct_path, """\ +from SCons.Variables.PackageVariable import PackageVariable +PV = PackageVariable + +from SCons.Variables import PackageVariable + +opts = Variables(args=ARGUMENTS) +opts.AddVariables( + PackageVariable('x11', + 'use X11 installed here (yes = search some places', + 'yes'), + PV('package', 'help for package', 'yes'), + ) + +env = Environment(variables=opts) +Help(opts.GenerateHelpText(env)) + +print env['x11'] +Default(env.Alias('dummy', None)) +""") + +test.run() +check([str(True)]) + +test.run(arguments='x11=no') +check([str(False)]) + +test.run(arguments='x11=0') +check([str(False)]) + +test.run(arguments=['x11=%s' % test.workpath()]) +check([test.workpath()]) + +expect_stderr = """ +scons: *** Path does not exist for option x11: /non/existing/path/ +""" + test.python_file_line(SConstruct_path, 14) + +test.run(arguments='x11=/non/existing/path/', stderr=expect_stderr, status=2) + + + +test.pass_test() + +# Local Variables: +# tab-width:4 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=4 shiftwidth=4: diff --git a/test/Variables/PathVariable.py b/test/Variables/PathVariable.py new file mode 100644 index 0000000..bfe82ba --- /dev/null +++ b/test/Variables/PathVariable.py @@ -0,0 +1,293 @@ +#!/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 PathVariable canned option type, with tests for its +various canned validators. +""" + +import os.path + +import TestSCons + +test = TestSCons.TestSCons() + +SConstruct_path = test.workpath('SConstruct') + +def check(expect): + result = test.stdout().split('\n') + assert result[1:len(expect)+1] == expect, (result[1:len(expect)+1], expect) + +#### test PathVariable #### + +test.subdir('lib', 'qt', ['qt', 'lib'], 'nolib' ) +workpath = test.workpath() +libpath = os.path.join(workpath, 'lib') + +test.write(SConstruct_path, """\ +from SCons.Variables.PathVariable import PathVariable +PV = PathVariable + +from SCons.Variables import PathVariable + +qtdir = r'%s' + +opts = Variables(args=ARGUMENTS) +opts.AddVariables( + PathVariable('qtdir', 'where the root of Qt is installed', qtdir), + PV('qt_libraries', 'where the Qt library is installed', r'%s'), + ) + +env = Environment(variables=opts) +Help(opts.GenerateHelpText(env)) + +print env['qtdir'] +print env['qt_libraries'] +print env.subst('$qt_libraries') + +Default(env.Alias('dummy', None)) +""" % (workpath, os.path.join('$qtdir', 'lib') )) + +qtpath = workpath +libpath = os.path.join(qtpath, 'lib') +test.run() +check([qtpath, os.path.join('$qtdir', 'lib'), libpath]) + +qtpath = os.path.join(workpath, 'qt') +libpath = os.path.join(qtpath, 'lib') +test.run(arguments=['qtdir=%s' % qtpath]) +check([qtpath, os.path.join('$qtdir', 'lib'), libpath]) + +qtpath = workpath +libpath = os.path.join(qtpath, 'nolib') +test.run(arguments=['qt_libraries=%s' % libpath]) +check([qtpath, libpath, libpath]) + +qtpath = os.path.join(workpath, 'qt') +libpath = os.path.join(workpath, 'nolib') +test.run(arguments=['qtdir=%s' % qtpath, 'qt_libraries=%s' % libpath]) +check([qtpath, libpath, libpath]) + +qtpath = os.path.join(workpath, 'non', 'existing', 'path') +SConstruct_file_line = test.python_file_line(test.workpath('SConstruct'), 14)[:-1] + +expect_stderr = """ +scons: *** Path for option qtdir does not exist: %(qtpath)s +%(SConstruct_file_line)s +""" % locals() + +test.run(arguments=['qtdir=%s' % qtpath], stderr=expect_stderr, status=2) + +expect_stderr = """ +scons: *** Path for option qt_libraries does not exist: %(qtpath)s +%(SConstruct_file_line)s +""" % locals() + +test.run(arguments=['qt_libraries=%s' % qtpath], stderr=expect_stderr, status=2) + + + +default_file = test.workpath('default_file') +default_subdir = test.workpath('default_subdir') + +existing_subdir = test.workpath('existing_subdir') +test.subdir(existing_subdir) + +existing_file = test.workpath('existing_file') +test.write(existing_file, "existing_file\n") + +non_existing_subdir = test.workpath('non_existing_subdir') +non_existing_file = test.workpath('non_existing_file') + + + +test.write('SConstruct', """\ +opts = Variables(args=ARGUMENTS) +opts.AddVariables( + PathVariable('X', 'X variable', r'%s', validator=PathVariable.PathAccept), + ) + +env = Environment(variables=opts) + +print env['X'] + +Default(env.Alias('dummy', None)) +""" % default_subdir) + +test.run() +check([default_subdir]) + +test.run(arguments=['X=%s' % existing_file]) +check([existing_file]) + +test.run(arguments=['X=%s' % non_existing_file]) +check([non_existing_file]) + +test.run(arguments=['X=%s' % existing_subdir]) +check([existing_subdir]) + +test.run(arguments=['X=%s' % non_existing_subdir]) +check([non_existing_subdir]) + +test.must_not_exist(non_existing_file) +test.must_not_exist(non_existing_subdir) + + + +test.write(SConstruct_path, """\ +opts = Variables(args=ARGUMENTS) +opts.AddVariables( + PathVariable('X', 'X variable', r'%s', validator=PathVariable.PathIsFile), + ) + +env = Environment(variables=opts) + +print env['X'] + +Default(env.Alias('dummy', None)) +""" % default_file) + +SConstruct_file_line = test.python_file_line(test.workpath('SConstruct'), 6)[:-1] + +expect_stderr = """ +scons: *** File path for option X does not exist: %(default_file)s +%(SConstruct_file_line)s +""" % locals() + +test.run(status=2, stderr=expect_stderr) + +test.write(default_file, "default_file\n") + +test.run() +check([default_file]) + +expect_stderr = """ +scons: *** File path for option X is a directory: %(existing_subdir)s +%(SConstruct_file_line)s +""" % locals() + +test.run(arguments=['X=%s' % existing_subdir], status=2, stderr=expect_stderr) + +test.run(arguments=['X=%s' % existing_file]) +check([existing_file]) + +expect_stderr = """ +scons: *** File path for option X does not exist: %(non_existing_file)s +%(SConstruct_file_line)s +""" % locals() + +test.run(arguments=['X=%s' % non_existing_file], status=2, stderr=expect_stderr) + + + +test.write('SConstruct', """\ +opts = Variables(args=ARGUMENTS) +opts.AddVariables( + PathVariable('X', 'X variable', r'%s', validator=PathVariable.PathIsDir), + ) + +env = Environment(variables=opts) + +print env['X'] + +Default(env.Alias('dummy', None)) +""" % default_subdir) + +expect_stderr = """ +scons: *** Directory path for option X does not exist: %(default_subdir)s +%(SConstruct_file_line)s +""" % locals() + +test.run(status=2, stderr=expect_stderr) + +test.subdir(default_subdir) + +test.run() +check([default_subdir]) + +expect_stderr = """ +scons: *** Directory path for option X is a file: %(existing_file)s +%(SConstruct_file_line)s +""" % locals() + +test.run(arguments=['X=%s' % existing_file], + status=2, + stderr=expect_stderr) + +test.run(arguments=['X=%s' % existing_subdir]) +check([existing_subdir]) + +expect_stderr = """ +scons: *** Directory path for option X does not exist: %(non_existing_subdir)s +%(SConstruct_file_line)s +""" % locals() + +test.run(arguments=['X=%s' % non_existing_subdir], + status=2, + stderr=expect_stderr) + + + +test.write('SConstruct', """\ +opts = Variables(args=ARGUMENTS) +opts.AddVariables( + PathVariable('X', 'X variable', r'%s', validator=PathVariable.PathIsDirCreate), + ) + +env = Environment(variables=opts) + +print env['X'] + +Default(env.Alias('dummy', None)) +""" % default_subdir) + +test.run() +check([default_subdir]) + +expect_stderr = """ +scons: *** Path for option X is a file, not a directory: %(existing_file)s +%(SConstruct_file_line)s +""" % locals() + +test.run(arguments=['X=%s' % existing_file], status=2, stderr=expect_stderr) + +test.run(arguments=['X=%s' % existing_subdir]) +check([existing_subdir]) + +test.run(arguments=['X=%s' % non_existing_subdir]) +check([non_existing_subdir]) + +test.must_exist(non_existing_subdir) + + + +test.pass_test() + +# Local Variables: +# tab-width:4 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=4 shiftwidth=4: diff --git a/test/Variables/Variables.py b/test/Variables/Variables.py new file mode 100644 index 0000000..454e32e --- /dev/null +++ b/test/Variables/Variables.py @@ -0,0 +1,366 @@ +#!/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 TestSCons + +test = TestSCons.TestSCons() + +test.write('SConstruct', """ +env = Environment() +print env['CC'] +print " ".join(env['CCFLAGS']) +Default(env.Alias('dummy', None)) +""") +test.run() +cc, ccflags = test.stdout().split('\n')[1:3] + +test.write('SConstruct', """ +# test validator. Change a key and add a new one to the environment +def validator(key, value, environ): + environ[key] = "v" + environ["valid_key"] = "v" + + +def old_converter (value): + return "old_converter" + +def new_converter (value, env): + return "new_converter" + + +opts = Variables('custom.py') +opts.Add('RELEASE_BUILD', + 'Set to 1 to build a release build', + 0, + None, + int) + +opts.Add('DEBUG_BUILD', + 'Set to 1 to build a debug build', + 1, + None, + int) + +opts.Add('CC', + 'The C compiler') + +opts.Add('VALIDATE', + 'An option for testing validation', + "notset", + validator, + None) + +opts.Add('OLD_CONVERTER', + 'An option for testing converters that take one parameter', + "foo", + None, + old_converter) + +opts.Add('NEW_CONVERTER', + 'An option for testing converters that take two parameters', + "foo", + None, + new_converter) + +opts.Add('UNSPECIFIED', + 'An option with no value') + +def test_tool(env): + if env['RELEASE_BUILD']: + env.Append(CCFLAGS = '-O') + if env['DEBUG_BUILD']: + env.Append(CCFLAGS = '-g') + + +env = Environment(variables=opts, tools=['default', test_tool]) + +Help('Variables settable in custom.py or on the command line:\\n' + opts.GenerateHelpText(env)) + +print env['RELEASE_BUILD'] +print env['DEBUG_BUILD'] +print env['CC'] +print " ".join(env['CCFLAGS']) +print env['VALIDATE'] +print env['valid_key'] + +# unspecified variables should not be set: +assert 'UNSPECIFIED' not in env + +# undeclared variables should be ignored: +assert 'UNDECLARED' not in env + +# calling Update() should not effect variables that +# are not declared on the variables object: +r = env['RELEASE_BUILD'] +opts = Variables() +opts.Update(env) +assert env['RELEASE_BUILD'] == r + +Default(env.Alias('dummy', None)) + +""") + +def check(expect): + result = test.stdout().split('\n') + assert result[1:len(expect)+1] == expect, (result[1:len(expect)+1], expect) + +test.run() +check(['0', '1', cc, (ccflags + ' -g').strip(), 'v', 'v']) + +test.run(arguments='RELEASE_BUILD=1') +check(['1', '1', cc, (ccflags + ' -O -g').strip(), 'v', 'v']) + +test.run(arguments='RELEASE_BUILD=1 DEBUG_BUILD=0') +check(['1', '0', cc, (ccflags + ' -O').strip(), 'v', 'v']) + +test.run(arguments='CC=not_a_c_compiler') +check(['0', '1', 'not_a_c_compiler', (ccflags + ' -g').strip(), 'v', 'v']) + +test.run(arguments='UNDECLARED=foo') +check(['0', '1', cc, (ccflags + ' -g').strip(), 'v', 'v']) + +test.run(arguments='CCFLAGS=--taco') +check(['0', '1', cc, (ccflags + ' -g').strip(), 'v', 'v']) + +test.write('custom.py', """ +DEBUG_BUILD=0 +RELEASE_BUILD=1 +""") + +test.run() +check(['1', '0', cc, (ccflags + ' -O').strip(), 'v', 'v']) + +test.run(arguments='DEBUG_BUILD=1') +check(['1', '1', cc, (ccflags + ' -O -g').strip(), 'v', 'v']) + +test.run(arguments='-h', + stdout = """\ +scons: Reading SConscript files ... +1 +0 +%s +%s +v +v +scons: done reading SConscript files. +Variables settable in custom.py or on the command line: + +RELEASE_BUILD: Set to 1 to build a release build + default: 0 + actual: 1 + +DEBUG_BUILD: Set to 1 to build a debug build + default: 1 + actual: 0 + +CC: The C compiler + default: None + actual: %s + +VALIDATE: An option for testing validation + default: notset + actual: v + +OLD_CONVERTER: An option for testing converters that take one parameter + default: foo + actual: old_converter + +NEW_CONVERTER: An option for testing converters that take two parameters + default: foo + actual: new_converter + +UNSPECIFIED: An option with no value + default: None + actual: None + +Use scons -H for help about command-line options. +"""%(cc, ccflags and ccflags + ' -O' or '-O', cc)) + +# Test saving of variables and multi loading +# +test.write('SConstruct', """ +opts = Variables(['custom.py', 'variables.saved']) +opts.Add('RELEASE_BUILD', + 'Set to 1 to build a release build', + 0, + None, + int) + +opts.Add('DEBUG_BUILD', + 'Set to 1 to build a debug build', + 1, + None, + int) + +opts.Add('UNSPECIFIED', + 'An option with no value') + +env = Environment(variables = opts) + +print env['RELEASE_BUILD'] +print env['DEBUG_BUILD'] + +opts.Save('variables.saved', env) +""") + +# Check the save file by executing and comparing against +# the expected dictionary +def checkSave(file, expected): + gdict = {} + ldict = {} + exec open(file, 'rU').read() in gdict, ldict + assert expected == ldict, "%s\n...not equal to...\n%s" % (expected, ldict) + +# First test with no command line variables +# This should just leave the custom.py settings +test.run() +check(['1','0']) +checkSave('variables.saved', { 'RELEASE_BUILD':1, 'DEBUG_BUILD':0}) + +# Override with command line arguments +test.run(arguments='DEBUG_BUILD=3') +check(['1','3']) +checkSave('variables.saved', {'RELEASE_BUILD':1, 'DEBUG_BUILD':3}) + +# Now make sure that saved variables are overridding the custom.py +test.run() +check(['1','3']) +checkSave('variables.saved', {'DEBUG_BUILD':3, 'RELEASE_BUILD':1}) + +# Load no variables from file(s) +# Used to test for correct output in save option file +test.write('SConstruct', """ +opts = Variables() +opts.Add('RELEASE_BUILD', + 'Set to 1 to build a release build', + '0', + None, + int) + +opts.Add('DEBUG_BUILD', + 'Set to 1 to build a debug build', + '1', + None, + int) + +opts.Add('UNSPECIFIED', + 'An option with no value') + +opts.Add('LISTOPTION_TEST', + 'testing list option persistence', + 'none', + names = ['a','b','c',]) + +env = Environment(variables = opts) + +print env['RELEASE_BUILD'] +print env['DEBUG_BUILD'] +print env['LISTOPTION_TEST'] + +opts.Save('variables.saved', env) +""") + +# First check for empty output file when nothing is passed on command line +test.run() +check(['0','1']) +checkSave('variables.saved', {}) + +# Now specify one option the same as default and make sure it doesn't write out +test.run(arguments='DEBUG_BUILD=1') +check(['0','1']) +checkSave('variables.saved', {}) + +# Now specify same option non-default and make sure only it is written out +test.run(arguments='DEBUG_BUILD=0 LISTOPTION_TEST=a,b') +check(['0','0']) +checkSave('variables.saved',{'DEBUG_BUILD':0, 'LISTOPTION_TEST':'a,b'}) + +test.write('SConstruct', """ +opts = Variables('custom.py') +opts.Add('RELEASE_BUILD', + 'Set to 1 to build a release build', + 0, + None, + int) + +opts.Add('DEBUG_BUILD', + 'Set to 1 to build a debug build', + 1, + None, + int) + +opts.Add('CC', + 'The C compiler') + +opts.Add('UNSPECIFIED', + 'An option with no value') + +env = Environment(variables=opts) + +Help('Variables settable in custom.py or on the command line:\\n' + opts.GenerateHelpText(env,sort=cmp)) + +""") + +test.run(arguments='-h', + stdout = """\ +scons: Reading SConscript files ... +scons: done reading SConscript files. +Variables settable in custom.py or on the command line: + +CC: The C compiler + default: None + actual: %s + +DEBUG_BUILD: Set to 1 to build a debug build + default: 1 + actual: 0 + +RELEASE_BUILD: Set to 1 to build a release build + default: 0 + actual: 1 + +UNSPECIFIED: An option with no value + default: None + actual: None + +Use scons -H for help about command-line options. +"""%cc) + +test.write('SConstruct', """ +import SCons.Variables +env1 = Environment(variables = Variables()) +env2 = Environment(variables = SCons.Variables.Variables()) +""") + +test.run() + +test.pass_test() + +# Local Variables: +# tab-width:4 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=4 shiftwidth=4: diff --git a/test/Variables/chdir.py b/test/Variables/chdir.py new file mode 100644 index 0000000..621e166 --- /dev/null +++ b/test/Variables/chdir.py @@ -0,0 +1,76 @@ +#!/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__" + +""" +Verify that we can chdir() to the directory in which an Variables +file lives by using the __name__ value. +""" + +import TestSCons + +test = TestSCons.TestSCons() + +test.subdir('bin', 'subdir') + +test.write('SConstruct', """\ +opts = Variables('../bin/opts.cfg', ARGUMENTS) +opts.Add('VARIABLE') +Export("opts") +SConscript('subdir/SConscript') +""") + +SConscript_contents = """\ +Import("opts") +env = Environment() +opts.Update(env) +print "VARIABLE =", repr(env['VARIABLE']) +""" + +test.write(['bin', 'opts.cfg'], """\ +import os +os.chdir(os.path.split(__name__)[0]) +exec(open('opts2.cfg', 'rU').read()) +""") + +test.write(['bin', 'opts2.cfg'], """\ +VARIABLE = 'opts2.cfg value' +""") + +test.write(['subdir', 'SConscript'], SConscript_contents) + +expect = """\ +VARIABLE = 'opts2.cfg value' +""" + +test.run(arguments = '-q -Q .', stdout=expect) + +test.pass_test() + +# Local Variables: +# tab-width:4 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=4 shiftwidth=4: diff --git a/test/Variables/help.py b/test/Variables/help.py new file mode 100644 index 0000000..f04f962 --- /dev/null +++ b/test/Variables/help.py @@ -0,0 +1,148 @@ +#!/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 Variables help messages. +""" + +import os + +import TestSCons + +str_True = str(True) +str_False = str(False) + +test = TestSCons.TestSCons() + +workpath = test.workpath() +qtpath = os.path.join(workpath, 'qt') +libpath = os.path.join(qtpath, 'lib') +libdirvar = os.path.join('$qtdir', 'lib') + +test.subdir(qtpath) +test.subdir(libpath) + +test.write('SConstruct', """ +from SCons.Variables import BoolVariable, EnumVariable, ListVariable, \ + PackageVariable, PathVariable + +list_of_libs = Split('x11 gl qt ical') +qtdir = r'%(qtpath)s' + +opts = Variables(args=ARGUMENTS) +opts.AddVariables( + BoolVariable('warnings', 'compilation with -Wall and similiar', 1), + BoolVariable('profile', 'create profiling informations', 0), + EnumVariable('debug', 'debug output and symbols', 'no', + allowed_values=('yes', 'no', 'full'), + map={}, ignorecase=0), # case sensitive + EnumVariable('guilib', 'gui lib to use', 'gtk', + allowed_values=('motif', 'gtk', 'kde'), + map={}, ignorecase=1), # case insensitive + EnumVariable('some', 'some option', 'xaver', + allowed_values=('xaver', 'eins'), + map={}, ignorecase=2), # make lowercase + ListVariable('shared', + 'libraries to build as shared libraries', + 'all', + names = list_of_libs), + PackageVariable('x11', + 'use X11 installed here (yes = search some places)', + 'yes'), + PathVariable('qtdir', 'where the root of Qt is installed', qtdir), + PathVariable('qt_libraries', + 'where the Qt library is installed', + r'%(libdirvar)s'), + ) + +env = Environment(variables=opts) +Help(opts.GenerateHelpText(env)) + +print env['warnings'] +print env['profile'] + +Default(env.Alias('dummy', None)) +""" % locals()) + + +test.run(arguments='-h', + stdout = """\ +scons: Reading SConscript files ... +%(str_True)s +%(str_False)s +scons: done reading SConscript files. + +warnings: compilation with -Wall and similiar (yes|no) + default: 1 + actual: %(str_True)s + +profile: create profiling informations (yes|no) + default: 0 + actual: %(str_False)s + +debug: debug output and symbols (yes|no|full) + default: no + actual: no + +guilib: gui lib to use (motif|gtk|kde) + default: gtk + actual: gtk + +some: some option (xaver|eins) + default: xaver + actual: xaver + +shared: libraries to build as shared libraries + (all|none|comma-separated list of names) + allowed names: x11 gl qt ical + default: all + actual: x11 gl qt ical + +x11: use X11 installed here (yes = search some places) + ( yes | no | /path/to/x11 ) + default: yes + actual: %(str_True)s + +qtdir: where the root of Qt is installed ( /path/to/qtdir ) + default: %(qtpath)s + actual: %(qtpath)s + +qt_libraries: where the Qt library is installed ( /path/to/qt_libraries ) + default: %(libdirvar)s + actual: %(libpath)s + +Use scons -H for help about command-line options. +""" % locals()) + + + +test.pass_test() + +# Local Variables: +# tab-width:4 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=4 shiftwidth=4: diff --git a/test/Variables/import.py b/test/Variables/import.py new file mode 100644 index 0000000..7cdd274 --- /dev/null +++ b/test/Variables/import.py @@ -0,0 +1,74 @@ +#!/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__" + +""" +Verify that an Variables file in a different directory can import +a module in that directory. +""" + +import TestSCons + +test = TestSCons.TestSCons() + +workpath = test.workpath('') + +test.subdir('bin', 'subdir') + +test.write('SConstruct', """\ +opts = Variables('../bin/opts.cfg', ARGUMENTS) +opts.Add('VARIABLE') +Export("opts") +SConscript('subdir/SConscript') +""") + +SConscript_contents = """\ +Import("opts") +env = Environment() +opts.Update(env) +print "VARIABLE =", env.get('VARIABLE') +""" + +test.write(['bin', 'opts.cfg'], """\ +from local_options import VARIABLE +""" % locals()) + +test.write(['bin', 'local_options.py'], """\ +VARIABLE = 'bin/local_options.py' +""") + +test.write(['subdir', 'SConscript'], SConscript_contents) + +expect = "VARIABLE = bin/local_options.py\n" + +test.run(arguments = '-q -Q .', stdout = expect) + +test.pass_test() + +# Local Variables: +# tab-width:4 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=4 shiftwidth=4: |
