diff --git a/src/casperjs.cs b/src/casperjs.cs old mode 100644 new mode 100755 index edb08ab0e..355a7e601 --- a/src/casperjs.cs +++ b/src/casperjs.cs @@ -3,6 +3,7 @@ using System.ComponentModel; using System.Diagnostics; using System.IO; +using System.Text.RegularExpressions; interface engine { string env_varname(); @@ -120,7 +121,7 @@ class casperjs { string CASPER_PATH = Path.GetFullPath(Path.Combine(Path.Combine(EXE_FILE, ".."), "..")); foreach(string arg in args) { - if(arg.StartsWith("--engine")) { + if(arg.StartsWith("--engine=")) { ENGINE = arg.Substring(9); break; } @@ -136,12 +137,18 @@ class casperjs { Environment.Exit(1); } + Regex arg_regex = new Regex("^--([^=]+)(?:=(.*))?$"); + foreach(string arg in args) { bool found = false; - foreach(string native in ENGINE_NATIVE_ARGS) { - if(arg.StartsWith("--" + native)) { - ENGINE_ARGS.Add(arg); - found = true; + Match arg_match = arg_regex.Match(arg); + if (arg_match.Success) { + string arg_name = arg_match.Groups[0].Captures[0].ToString(); + foreach(string native in ENGINE_NATIVE_ARGS) { + if (arg_name == native) { + ENGINE_ARGS.Add(arg); + found = true; + } } } diff --git a/tests/clitests/runtests.py b/tests/clitests/runtests.py index 0f1ae27b7..e7d62f321 100644 --- a/tests/clitests/runtests.py +++ b/tests/clitests/runtests.py @@ -173,6 +173,16 @@ def assertCommandOutputContains(self, cmd, what, **kwargs): else: self.assertIn(what, self.runCommand(cmd)) + def assertCommandOutputDoesNotContain(self, cmd, what, **kwargs): + if not what: + raise AssertionError('Empty lookup') + if isinstance(what, (list, tuple)): + output = self.runCommand(cmd, **kwargs) + for entry in what: + self.assertNotIn(entry, output) + else: + self.assertNotIn(what, self.runCommand(cmd)) + class BasicCommandsTest(CasperExecTestBase): def test_version(self): @@ -292,6 +302,30 @@ def test_simple_script(self): self.assertCommandOutputEquals(script_path, 'it works') +class ScriptOptionsTest(CasperExecTestBase): + def test_script_options(self): + script_path = os.path.join(TEST_ROOT, 'scripts', 'options.js') + # Specify a mix of engine and script options. + # --whoops is special in that it starts with --w, which is a phantomjs engine command. + # At one time was mishandled in src/casperjs.cs. + script_path_script_args = script_path + ' --debug=no --load-images=no --whoops --this-is-a=test' + self.assertCommandOutputContains(script_path_script_args, [ + ' "whoops": true,', + ' "this-is-a": "test"', + ]) + + def test_engine_options(self): + script_path = os.path.join(TEST_ROOT, 'scripts', 'options.js') + # Specify a mix of engine and script options. + # --whoops is special in that it starts with --w, which is a phantomjs engine command. + # At one time was mishandled in src/casperjs.cs. + script_path_script_args = script_path + ' --debug=no --load-images=no --whoops --this-is-a=test' + self.assertCommandOutputDoesNotContain(script_path_script_args, [ + ' "debug": false,', + ' "load-images": false,', + ]) + + class ScriptErrorTest(CasperExecTestBase): def test_syntax_error(self): # phantomjs and slimerjs 'SyntaxError: Parse error' diff --git a/tests/clitests/scripts/options.js b/tests/clitests/scripts/options.js new file mode 100644 index 000000000..1167b70cd --- /dev/null +++ b/tests/clitests/scripts/options.js @@ -0,0 +1,5 @@ +var require = patchRequire(require); +var casper = require('casper').create(); +var utils = require('utils'); +utils.dump(casper.cli.options); +casper.exit();