Commit 6ce99dd1 6ce99dd171d18157e047320823204b661ea08453 by Nicolas Perriault

added python executable self tests

1 parent 1c9f18e0
...@@ -7,6 +7,7 @@ before_script: ...@@ -7,6 +7,7 @@ before_script:
7 - "export PHANTOMJS_EXECUTABLE='phantomjs --local-to-remote-url-access=yes --ignore-ssl-errors=yes'" 7 - "export PHANTOMJS_EXECUTABLE='phantomjs --local-to-remote-url-access=yes --ignore-ssl-errors=yes'"
8 script: 8 script:
9 - "./bin/casperjs selftest" 9 - "./bin/casperjs selftest"
10 - "./bin/casperjs __selfcommandtest"
10 after_script: 11 after_script:
11 - "jshint --config=.jshintconfig ." 12 - "jshint --config=.jshintconfig ."
12 notifications: 13 notifications:
......
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 2
3 import json
3 import os 4 import os
5 import subprocess
4 import sys 6 import sys
5 7
8 def test_cmd(cmd):
9 try:
10 return subprocess.check_output([__file__] + cmd.split(' '))
11 except subprocess.CalledProcessError as err:
12 sys.stderr.write('FAIL: %s\n' % ' '.join(err.cmd))
13 sys.stderr.write(' %s\n' % err.output)
14 sys.exit(1)
6 15
7 def resolve(path): 16 def resolve(path):
8 if os.path.islink(path): 17 if os.path.islink(path):
...@@ -32,9 +41,25 @@ PHANTOMJS_NATIVE_ARGS = [ ...@@ -32,9 +41,25 @@ PHANTOMJS_NATIVE_ARGS = [
32 'web-security', 41 'web-security',
33 ] 42 ]
34 CASPER_ARGS = [] 43 CASPER_ARGS = []
44 CASPER_PATH = os.path.abspath(os.path.join(os.path.dirname(resolve(__file__)), '..'))
35 PHANTOMJS_ARGS = [] 45 PHANTOMJS_ARGS = []
46 SYS_ARGS = sys.argv[1:]
47
48 if SYS_ARGS[0] == '__selfcommandtest':
49 print('Starting Python executable tests...')
50 pkg_version = json.loads(open('package.json').read()).get('version')
51 scripts_path = os.path.join(CASPER_PATH, 'tests', 'commands')
52 assert(test_cmd('--help').find(pkg_version) > -1)
53 assert(test_cmd('--version').strip() == pkg_version)
54 assert(test_cmd(os.path.join(scripts_path, 'script.js')) == 'it works\n')
55 test_output = test_cmd('test --no-colors ' + os.path.join(scripts_path, 'mytest.js'))
56 assert('PASS ok1' in test_output)
57 assert('PASS ok2' in test_output)
58 assert('PASS ok3' in test_output)
59 print('Python executable tests passed.')
60 sys.exit(0)
36 61
37 for arg in sys.argv[1:]: 62 for arg in SYS_ARGS:
38 found = False 63 found = False
39 for native in PHANTOMJS_NATIVE_ARGS: 64 for native in PHANTOMJS_NATIVE_ARGS:
40 if arg.startswith('--%s' % native): 65 if arg.startswith('--%s' % native):
...@@ -43,7 +68,6 @@ for arg in sys.argv[1:]: ...@@ -43,7 +68,6 @@ for arg in sys.argv[1:]:
43 if not found: 68 if not found:
44 CASPER_ARGS.append(arg) 69 CASPER_ARGS.append(arg)
45 70
46 CASPER_PATH = os.path.abspath(os.path.join(os.path.dirname(resolve(__file__)), '..'))
47 CASPER_COMMAND = os.environ.get('PHANTOMJS_EXECUTABLE', 'phantomjs').split(' ') 71 CASPER_COMMAND = os.environ.get('PHANTOMJS_EXECUTABLE', 'phantomjs').split(' ')
48 CASPER_COMMAND.extend(PHANTOMJS_ARGS) 72 CASPER_COMMAND.extend(PHANTOMJS_ARGS)
49 CASPER_COMMAND.extend([ 73 CASPER_COMMAND.extend([
......
1 /*jshint strict:false*/
2 /*global CasperError casper console phantom require*/
3 casper.start('about:blank', function() {
4 this.test.pass('ok1');
5 });
6
7 casper.then(function() {
8 this.test.pass('ok2');
9 });
10
11 casper.run(function() {
12 this.test.pass('ok3');
13 this.test.done();
14 });
1 var casper = require('casper').create();
2 casper.echo('it works');
3 casper.exit();