Add a test for unknown options (both short and long).
authorstevenknight <stevenknight@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Sat, 29 Sep 2001 03:04:07 +0000 (03:04 +0000)
committerstevenknight <stevenknight@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Sat, 29 Sep 2001 03:04:07 +0000 (03:04 +0000)
git-svn-id: http://scons.tigris.org/svn/scons/trunk@73 fdb21ef1-2011-0410-befe-b5e4ea1792b1

src/script/scons.py
test/option-unknown.py [new file with mode: 0644]

index d1cffbf40793e88378b876f944a02c548c9d3b6d..85f869c2cc706244f656e15dd157a801e95378a6 100644 (file)
@@ -496,6 +496,8 @@ def UsageString():
 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:
@@ -515,10 +517,13 @@ def main():
        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']:
diff --git a/test/option-unknown.py b/test/option-unknown.py
new file mode 100644 (file)
index 0000000..28d3ceb
--- /dev/null
@@ -0,0 +1,20 @@
+#!/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()