Anonymous avatar Anonymous committed 6d5ea49

Add a test for unknown options (both short and long).

Comments (0)

Files changed (2)

src/script/scons.py

 def main():
     global scripts, help_option, num_jobs
 
+    targets = []
+
     # It looks like 2.0 changed the name of the exception class
     # raised by getopt.
     try:
 	for opt, arg in cmd_opts:
 	    opt_func[opt](opt, arg)
 
-    cmd_opts, targets = getopt.getopt(sys.argv[1:], short_opts, long_opts)
-
-    for opt, arg in cmd_opts:
-	opt_func[opt](opt, arg)
+    try:
+	cmd_opts, targets = getopt.getopt(sys.argv[1:], short_opts, long_opts)
+    except getopt_err, x:
+	_scons_user_error(x)
+    else:
+	for opt, arg in cmd_opts:
+	    opt_func[opt](opt, arg)
 
     if not scripts:
         for file in ['SConstruct', 'Sconstruct', 'sconstruct']:

test/option-unknown.py

+#!/usr/bin/env python
+
+__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
+
+import TestSCons
+import string
+import sys
+
+test = TestSCons.TestSCons()
+
+test.write('SConstruct', "")
+
+test.run(arguments = '-Z',
+	 stderr = '\nSCons error: option -Z not recognized\nFile "\S+", line \d+, in short_has_arg\n')
+
+test.run(arguments = '--ZizzerZazzerZuzz',
+	 stderr = '\nSCons error: option --ZizzerZazzerZuzz not recognized\nFile "\S+", line \d+, in long_has_args\n')
+
+test.pass_test()
+ 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.