Commit 6ce99dd1 6ce99dd171d18157e047320823204b661ea08453 by Nicolas Perriault

added python executable self tests

1 parent 1c9f18e0
......@@ -7,6 +7,7 @@ before_script:
- "export PHANTOMJS_EXECUTABLE='phantomjs --local-to-remote-url-access=yes --ignore-ssl-errors=yes'"
script:
- "./bin/casperjs selftest"
- "./bin/casperjs __selfcommandtest"
after_script:
- "jshint --config=.jshintconfig ."
notifications:
......
#!/usr/bin/env python
import json
import os
import subprocess
import sys
def test_cmd(cmd):
try:
return subprocess.check_output([__file__] + cmd.split(' '))
except subprocess.CalledProcessError as err:
sys.stderr.write('FAIL: %s\n' % ' '.join(err.cmd))
sys.stderr.write(' %s\n' % err.output)
sys.exit(1)
def resolve(path):
if os.path.islink(path):
......@@ -32,9 +41,25 @@ PHANTOMJS_NATIVE_ARGS = [
'web-security',
]
CASPER_ARGS = []
CASPER_PATH = os.path.abspath(os.path.join(os.path.dirname(resolve(__file__)), '..'))
PHANTOMJS_ARGS = []
SYS_ARGS = sys.argv[1:]
if SYS_ARGS[0] == '__selfcommandtest':
print('Starting Python executable tests...')
pkg_version = json.loads(open('package.json').read()).get('version')
scripts_path = os.path.join(CASPER_PATH, 'tests', 'commands')
assert(test_cmd('--help').find(pkg_version) > -1)
assert(test_cmd('--version').strip() == pkg_version)
assert(test_cmd(os.path.join(scripts_path, 'script.js')) == 'it works\n')
test_output = test_cmd('test --no-colors ' + os.path.join(scripts_path, 'mytest.js'))
assert('PASS ok1' in test_output)
assert('PASS ok2' in test_output)
assert('PASS ok3' in test_output)
print('Python executable tests passed.')
sys.exit(0)
for arg in sys.argv[1:]:
for arg in SYS_ARGS:
found = False
for native in PHANTOMJS_NATIVE_ARGS:
if arg.startswith('--%s' % native):
......@@ -43,7 +68,6 @@ for arg in sys.argv[1:]:
if not found:
CASPER_ARGS.append(arg)
CASPER_PATH = os.path.abspath(os.path.join(os.path.dirname(resolve(__file__)), '..'))
CASPER_COMMAND = os.environ.get('PHANTOMJS_EXECUTABLE', 'phantomjs').split(' ')
CASPER_COMMAND.extend(PHANTOMJS_ARGS)
CASPER_COMMAND.extend([
......
/*jshint strict:false*/
/*global CasperError casper console phantom require*/
casper.start('about:blank', function() {
this.test.pass('ok1');
});
casper.then(function() {
this.test.pass('ok2');
});
casper.run(function() {
this.test.pass('ok3');
this.test.done();
});
var casper = require('casper').create();
casper.echo('it works');
casper.exit();