summaryrefslogtreecommitdiffstats
path: root/test/Options
diff options
context:
space:
mode:
authorSteven Knight <knight@baldmt.com>2006-07-25 02:30:45 (GMT)
committerSteven Knight <knight@baldmt.com>2006-07-25 02:30:45 (GMT)
commitdd9bbc79353ae90b2402c16b1613dad4e502d250 (patch)
tree42f857f72bb4dcab6d876d1f9c73e0a1dd70d8c2 /test/Options
parent57fcbbc5d24fb16f988e4fe3294d5d49abef8e2a (diff)
downloadSCons-dd9bbc79353ae90b2402c16b1613dad4e502d250.zip
SCons-dd9bbc79353ae90b2402c16b1613dad4e502d250.tar.gz
SCons-dd9bbc79353ae90b2402c16b1613dad4e502d250.tar.bz2
Merged revisions 1441-1539 via svnmerge from
http://scons.tigris.org/svn/scons/branches/core ........ r1441 | stevenknight | 2006-04-22 23:06:53 -0400 (Sat, 22 Apr 2006) | 1 line 0.96.D397 - The scons command, branch 0.96.91. ........ r1442 | stevenknight | 2006-04-27 00:45:12 -0400 (Thu, 27 Apr 2006) | 1 line 0.96.D398 - The scons command, branch 0.96.92. ........ r1443 | stevenknight | 2006-04-27 00:49:25 -0400 (Thu, 27 Apr 2006) | 1 line 0.96.D399 - Taskmaster clean-ups in anticipation of refactoring speedups. ........ r1450 | stevenknight | 2006-05-02 00:04:55 -0400 (Tue, 02 May 2006) | 1 line 0.96.D400 - Fix VC+++ 2005 Express detection. (Atul Varma) Fix parsing Intel C compiler Li ........ r1451 | stevenknight | 2006-05-02 01:14:24 -0400 (Tue, 02 May 2006) | 1 line 0.96.D401 - Enhance ParseConfig() to understand -arch and -isysroot options. (Gary Oberbrun ........ r1458 | stevenknight | 2006-05-02 23:21:04 -0400 (Tue, 02 May 2006) | 1 line 0.96.D402 - Make strfunction handling consistent. (David Gruener) ........ r1459 | stevenknight | 2006-05-02 23:37:08 -0400 (Tue, 02 May 2006) | 1 line 0.96.D403 - Comment out the test of CVS checkout from the old tigris.org repository. ........ r1460 | stevenknight | 2006-05-03 23:47:54 -0400 (Wed, 03 May 2006) | 1 line 0.96.D404 - Preserve white space in display Action string. (David Gruener) ........ r1461 | stevenknight | 2006-05-04 09:16:15 -0400 (Thu, 04 May 2006) | 1 line 0.96.D405 - Add MergeFlags() and AddFlags() methods. (Greg Noel) Support recognizing compi ........ r1462 | stevenknight | 2006-05-04 23:46:53 -0400 (Thu, 04 May 2006) | 1 line 0.96.D406 - Fix stack trace when ParseFlags has a null string. ........ r1464 | stevenknight | 2006-05-05 17:21:27 -0400 (Fri, 05 May 2006) | 1 line 0.96.D408 - Fix the string displayed by InstallAs() when called through the default construc ........ r1465 | stevenknight | 2006-05-05 18:30:28 -0400 (Fri, 05 May 2006) | 1 line 0.96.D409 - Fix test/ParseConfig.py, broken in the previous checkin by ParseFlags() changes. ........ r1466 | stevenknight | 2006-05-05 20:42:35 -0400 (Fri, 05 May 2006) | 1 line 0.96.D407 - Avoid recursive calls to main() in SConf test programs. (Karol Pietrzak) ........ r1467 | stevenknight | 2006-05-06 00:27:21 -0400 (Sat, 06 May 2006) | 1 line 0.96.D410 - Catch errors from commands that ParseConfig() calls. (John Pye) ........ r1468 | stevenknight | 2006-05-06 10:55:38 -0400 (Sat, 06 May 2006) | 1 line 0.96.D411 - Significant taskmaster speedup by using reference counts, not list manipulation. ........ r1469 | stevenknight | 2006-05-06 18:38:02 -0400 (Sat, 06 May 2006) | 1 line 0.96.D413 - TeX improvements. ........ r1471 | stevenknight | 2006-05-07 09:07:58 -0400 (Sun, 07 May 2006) | 2 lines Delete properties interfering with clean .jpg checkout. ........ r1472 | stevenknight | 2006-05-07 09:23:54 -0400 (Sun, 07 May 2006) | 1 line 0.96.D412 - Windows portability fixes for two tests and ParseConfig() execution. ........ r1473 | stevenknight | 2006-05-07 09:30:11 -0400 (Sun, 07 May 2006) | 1 line 0.96.D414 - Various man page and documentation updates. ........ r1474 | stevenknight | 2006-05-07 23:53:12 -0400 (Sun, 07 May 2006) | 1 line 0.96.D415 - Initial infrastructure for executing tests under QMTest. (Stefan Seefeld) ........ r1476 | stevenknight | 2006-05-09 00:03:47 -0400 (Tue, 09 May 2006) | 1 line 0.96.D416 - Fix QMTest infrastructure to avoid listing directories with no tests and to find ........ r1477 | stevenknight | 2006-05-16 06:47:51 -0400 (Tue, 16 May 2006) | 1 line 0.96.D417 - Fix Alias turning Entries into Nodes or Dirs too soon. ........ r1478 | stevenknight | 2006-05-17 08:32:58 -0400 (Wed, 17 May 2006) | 1 line 0.96.D418 - Next QMTest changes (including fixing copyrights). ........ r1479 | stevenknight | 2006-05-18 05:07:06 -0400 (Thu, 18 May 2006) | 1 line 0.96.D419 - Fix DVIPDF tests after recent changes. ........ r1497 | stevenknight | 2006-05-23 08:47:01 -0400 (Tue, 23 May 2006) | 1 line 0.96.D420 - Better error message when trying to build a file from an unknown sufix. (Gary O ........ r1498 | stevenknight | 2006-05-23 09:38:52 -0400 (Tue, 23 May 2006) | 1 line 0.96.D421 - Suppress duplicate entries in latest TeX patch. (Joel B. Mohler) ........ r1499 | stevenknight | 2006-05-23 22:00:06 -0400 (Tue, 23 May 2006) | 1 line 0.96.D422 - Add tests for tuple variable expansion. (Gary Oberbrunner) ........ r1515 | stevenknight | 2006-06-12 06:44:24 -0400 (Mon, 12 Jun 2006) | 1 line 0.96.D423 - More QMTest work: start giving runtest.py its own tests, more functionality for ........ r1517 | stevenknight | 2006-06-21 07:34:30 -0400 (Wed, 21 Jun 2006) | 1 line 0.96.D424 - Move test/Configure.py and test/Options.py to avoid confusion with similarly-nam ........ r1518 | stevenknight | 2006-06-21 12:40:37 -0400 (Wed, 21 Jun 2006) | 1 line 0.96.D425 - Change the QMTest infrastructure to use File naming, not Python. Rename tests w ........ r1533 | stevenknight | 2006-07-23 20:10:08 -0400 (Sun, 23 Jul 2006) | 1 line 0.96.D426 - Fix ramifications of changing when Node disambiguation happens. ........ r1535 | stevenknight | 2006-07-24 06:40:43 -0400 (Mon, 24 Jul 2006) | 3 lines Initialized merge tracking via "svnmerge" with revisions "1-1534" from http://scons.tigris.org/svn/scons/trunk ........ r1536 | stevenknight | 2006-07-24 21:45:40 -0400 (Mon, 24 Jul 2006) | 2 lines Remove svnmerge-integrated property to start over. ........ r1538 | stevenknight | 2006-07-24 21:51:32 -0400 (Mon, 24 Jul 2006) | 3 lines Initialized merge tracking via "svnmerge" with revisions "1-1440" from http://scons.tigris.org/svn/scons/trunk ........
Diffstat (limited to 'test/Options')
-rw-r--r--test/Options/Options.py336
1 files changed, 336 insertions, 0 deletions
diff --git a/test/Options/Options.py b/test/Options/Options.py
new file mode 100644
index 0000000..bd827d1
--- /dev/null
+++ b/test/Options/Options.py
@@ -0,0 +1,336 @@
+#!/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
+import string
+
+test = TestSCons.TestSCons()
+
+test.write('SConstruct', """
+import string
+env = Environment()
+print env['CC']
+print string.join(env['CCFLAGS'])
+Default(env.Alias('dummy', None))
+""")
+test.run()
+cc, ccflags = string.split(test.stdout(), '\n')[1:3]
+
+test.write('SConstruct', """
+import string
+
+# 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"
+
+opts = Options('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('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(options=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 string.join(env['CCFLAGS'])
+print env['VALIDATE']
+print env['valid_key']
+
+# unspecified options should not be set:
+assert not env.has_key('UNSPECIFIED')
+
+# undeclared options should be ignored:
+assert not env.has_key('UNDECLARED')
+
+# calling Update() should not effect options that
+# are not declared on the options object:
+r = env['RELEASE_BUILD']
+opts = Options()
+opts.Update(env)
+assert env['RELEASE_BUILD'] == r
+
+Default(env.Alias('dummy', None))
+
+""")
+
+def check(expect):
+ result = string.split(test.stdout(), '\n')
+ assert result[1:len(expect)+1] == expect, (result[1:len(expect)+1], expect)
+
+test.run()
+check(['0', '1', cc, string.strip(ccflags + ' -g'), 'v', 'v'])
+
+test.run(arguments='RELEASE_BUILD=1')
+check(['1', '1', cc, string.strip(ccflags + ' -O -g'), 'v', 'v'])
+
+test.run(arguments='RELEASE_BUILD=1 DEBUG_BUILD=0')
+check(['1', '0', cc, string.strip(ccflags + ' -O'), 'v', 'v'])
+
+test.run(arguments='CC=not_a_c_compiler')
+check(['0', '1', 'not_a_c_compiler', string.strip(ccflags + ' -g'), 'v', 'v'])
+
+test.run(arguments='UNDECLARED=foo')
+check(['0', '1', cc, string.strip(ccflags + ' -g'), 'v', 'v'])
+
+test.run(arguments='CCFLAGS=--taco')
+check(['0', '1', cc, string.strip(ccflags + ' -g'), 'v', 'v'])
+
+test.write('custom.py', """
+DEBUG_BUILD=0
+RELEASE_BUILD=1
+""")
+
+test.run()
+check(['1', '0', cc, string.strip(ccflags + ' -O'), 'v', 'v'])
+
+test.run(arguments='DEBUG_BUILD=1')
+check(['1', '1', cc, string.strip(ccflags + ' -O -g'), '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
+
+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 options and multi loading
+#
+test.write('SConstruct', """
+opts = Options(['custom.py', 'options.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(options = opts)
+
+print env['RELEASE_BUILD']
+print env['DEBUG_BUILD']
+
+opts.Save('options.saved', env)
+""")
+
+# Check the save file by executing and comparing against
+# the expected dictionary
+def checkSave(file, expected):
+ gdict = {}
+ ldict = {}
+ execfile(file, gdict, ldict)
+ assert expected == ldict, "%s\n...not equal to...\n%s" % (expected, ldict)
+
+# First test with no command line options
+# This should just leave the custom.py settings
+test.run()
+check(['1','0'])
+checkSave('options.saved', { 'RELEASE_BUILD':1, 'DEBUG_BUILD':0})
+
+# Override with command line arguments
+test.run(arguments='DEBUG_BUILD=3')
+check(['1','3'])
+checkSave('options.saved', {'RELEASE_BUILD':1, 'DEBUG_BUILD':3})
+
+# Now make sure that saved options are overridding the custom.py
+test.run()
+check(['1','3'])
+checkSave('options.saved', {'DEBUG_BUILD':3, 'RELEASE_BUILD':1})
+
+# Load no options from file(s)
+# Used to test for correct output in save option file
+test.write('SConstruct', """
+opts = Options()
+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(options = opts)
+
+print env['RELEASE_BUILD']
+print env['DEBUG_BUILD']
+print env['LISTOPTION_TEST']
+
+opts.Save('options.saved', env)
+""")
+
+# First check for empty output file when nothing is passed on command line
+test.run()
+check(['0','1'])
+checkSave('options.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('options.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('options.saved',{'DEBUG_BUILD':0, 'LISTOPTION_TEST':'a,b'})
+
+test.write('SConstruct', """
+opts = Options('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(options=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.Options
+env1 = Environment(options = Options())
+env2 = Environment(options = SCons.Options.Options())
+""")
+
+test.run()
+
+test.pass_test()