Skip to content

Commit

Permalink
convert test runner to coco
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewrk committed Jul 12, 2012
1 parent a228bf0 commit 7addbe3
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 96 deletions.
100 changes: 100 additions & 0 deletions src/test.co
Original file line number Diff line number Diff line change
@@ -0,0 +1,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)
96 changes: 0 additions & 96 deletions src/test.coffee

This file was deleted.

0 comments on commit 7addbe3

Please sign in to comment.