forked from devongovett/importer
/
test.co
100 lines (90 loc) · 3.21 KB
/
test.co
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
const {exec} = require('child_process')
const fs = require('fs')
const path = require('path')
const async = require('async')
const temp = require('temp')
const tests_dir = "./tests/"
const tmp_js_file = "./.test_out.tmp.js"
msg = ""
pass_count = 0
fail_count = 0
fs.readdir tests_dir, !(err, files) ->
const doTest = !(test_dir, testDone) ->
const main_file = path.join(tests_dir, test_dir, "test")
const expect_file = path.join(tests_dir, test_dir, "expected.txt")
const switches_file = path.join(tests_dir, test_dir, "switches.txt")
let
exec_result = null
expected_output = null
const execTest = !(cb) ->
fs.readFile switches_file, 'utf8', !(err, switches) ->
switches = (switches || "").replace(/\n/g, " ")
temp.open "", !(err, tmp_js_file) ->
const cmdline = "bin/jspackage #switches #main_file #{tmp_js_file.path}"
exec cmdline, !(err, stdout, stderr) ->
if stderr.length > 0
exec_result :=
compile: false
msg: stderr
cb!
exec "node #{tmp_js_file.path}", !(err, stdout, stderr) ->
fs.close tmp_js_file.fd, ->
fs.unlink tmp_js_file.path
if stderr.length > 0
exec_result :=
compile: true
run: false
msg: stderr
else
exec_result :=
compile: true
run: true
output: stdout
cb!
readExpected = !(cb) -> fs.readFile expect_file, \utf8, !(err, out) ->
expected_output := out
cb!
async.parallel [execTest, readExpected], !->
if exec_result.compile
if exec_result.run
if exec_result.output is expected_output
process.stdout.write(\.)
pass_count += 1
else
process.stdout.write(\F)
fail_count += 1
msg += """\n
======== #test_dir failed =========
-------- Expected Output: ---------
#expected_output
-------------------------------------
-------- Actual Output: ---------
#{exec_result.output}
-------------------------------------
"""
else
process.stdout.write(\E)
fail_count += 1
msg += """\n
======== #test_dir crashed =========
-------- stderr: ---------
#{exec_result.msg}
-------------------------------------
"""
else
process.stdout.write(\X)
fail_count += 1
msg += """\n
======== #test_dir compile error ====
-------- stderr: ---------
#{exec_result.msg}
-------------------------------------
"""
testDone!
async.map files, doTest, !->
if msg.length > 0
process.stdout.write(msg)
process.stdout.write "\n#pass_count passed, #fail_count failed.\n"
fs.unlink tmp_js_file
if fail_count > 0
process.exit(1)