Skip to content
This repository has been archived by the owner on Jun 19, 2020. It is now read-only.

Commit

Permalink
Merge pull request #1389 from mepard/fix-windows-cl-options
Browse files Browse the repository at this point in the history
Fix assignment of options to engine vs script
  • Loading branch information
hexid committed Feb 4, 2016
2 parents 3aa6f76 + c51d700 commit b2c2621
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/casperjs.cs
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Text.RegularExpressions;

interface engine {
string env_varname();
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
}
}
}

Expand Down
34 changes: 34 additions & 0 deletions tests/clitests/runtests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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'
Expand Down
5 changes: 5 additions & 0 deletions tests/clitests/scripts/options.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
var require = patchRequire(require);
var casper = require('casper').create();
var utils = require('utils');
utils.dump(casper.cli.options);
casper.exit();

0 comments on commit b2c2621

Please sign in to comment.