Revision: e3b7223f6c79
Author:   Pekka Klärck
Date:     Thu Aug 30 03:53:56 2012
Log: ArgumentParser: Reverting earlier change to check argument counts after custom validation.

For example libdoc's validator expected that there is a correct number of arguments and crashed with IndexError when there wasn't. Robot's and rebot's validator now needs to verify arg counts separately after filtering invalid args.

Update issue 1184
Still tuning argument count validation a little.
http://code.google.com/p/robotframework/source/detail?r=e3b7223f6c79

Modified:
 /atest/robot/cli/rebot/invalid_usage.txt
 /atest/robot/cli/runner/multisource.txt
 /src/robot/run.py
 /src/robot/utils/argumentparser.py

=======================================
--- /atest/robot/cli/rebot/invalid_usage.txt    Thu Aug 30 02:11:08 2012
+++ /atest/robot/cli/rebot/invalid_usage.txt    Thu Aug 30 03:53:56 2012
@@ -26,7 +26,7 @@
     Run Rebot Without Processing Output  ${EMPTY}  nönex1  nönex2
     ${nönex} =  Normalize Path  ${DATADIR}/nönex
Check Stderr Contains [ WARN ] Arguments '${nönex}1' and '${nönex}2' did not exist and were ignored. Validate the used command line syntax
-    Check Stderr Contains  [ ERROR ] Expected at least 1 argument, got 0.
+    Check Stderr Contains  [ ERROR ] No valid arguments given.

 Non-XML Input
     Create File  ${MYOUTDIR}/invalid.txt  Hello, world
=======================================
--- /atest/robot/cli/runner/multisource.txt     Thu Aug 30 02:11:08 2012
+++ /atest/robot/cli/runner/multisource.txt     Thu Aug 30 03:53:56 2012
@@ -58,4 +58,4 @@
     Run Tests Without Processing Output  ${EMPTY}  nönex1  nönex2
     ${nönex} =  Normalize Path  ${DATADIR}/nönex
Check Stderr Contains [ WARN ] Arguments '${nönex}1' and '${nönex}2' did not exist and were ignored. Validate the used command line syntax.
-    Check Stderr Contains  [ ERROR ] Expected at least 1 argument, got 0.
+    Check Stderr Contains  [ ERROR ] No valid arguments given.
=======================================
--- /src/robot/run.py   Thu Aug 30 02:11:08 2012
+++ /src/robot/run.py   Thu Aug 30 03:53:56 2012
@@ -329,6 +329,7 @@
     import pythonpathsetter

 from robot.conf import RobotSettings
+from robot.errors import DataError
 from robot.output import LOGGER, Output, pyloggingconf
 from robot.reporting import ResultWriter
 from robot.running import TestSuite, STOP_SIGNAL_MONITOR, namespace
@@ -376,6 +377,8 @@
             LOGGER.warn("Argument%s %s did not exist and %s ignored. "
                         "Validate the used command line syntax."
                         % (s, seq2str(nonex), were))
+            if not valid:
+                raise DataError('No valid arguments given.')
         return valid


=======================================
--- /src/robot/utils/argumentparser.py  Thu Aug 30 02:11:08 2012
+++ /src/robot/utils/argumentparser.py  Thu Aug 30 03:53:56 2012
@@ -126,9 +126,9 @@
             args_list = self._process_possible_argfile(args_list)
         opts, args = self._parse_args(args_list)
         opts, args = self._handle_special_options(opts, args)
+        self._arg_limit_validator(args)
         if self._validator:
             opts, args = self._validator(opts, args)
-        self._arg_limit_validator(args)
         return opts, args

     def _handle_special_options(self, opts, args):

Reply via email to