added python executable self tests
Showing
4 changed files
with
44 additions
and
2 deletions
... | @@ -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([ | ... | ... |
tests/commands/mytest.js
0 → 100644
tests/commands/script.js
0 → 100644
-
Please register or sign in to post a comment