Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

look at shebangs in tests #6

Open
wants to merge 4 commits into from

2 participants

@thejh

As discussed in IRC. E.g. a test starting like this works for me now and has access to the gc() function:

#! node --expose-gc
@temsa

+1, need !

@thejh

@temsa I talked about this with isaacs a while ago. This pull request is outdated (everything is in the tap project itself now, also a lot changed in the code in the meantime, so this doesn't merge anymore). You'll have to ask isaacs whether he already redid this change - I think he offered doing it.

@isaacs isaacs referenced this pull request from a commit in isaacs/node-tap
@isaacs Look at shebangs in test files b716123
@thejh thejh referenced this pull request in substack/dnode
Closed

Networked GC #75

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Nov 16, 2011
  1. @thejh

    look at shebangs in tests

    thejh authored
  2. @thejh

    removed debug output

    thejh authored
  3. @thejh

    camelCase variable name

    thejh authored
  4. @thejh

    don't nest so many calls

    thejh authored
This page is out of date. Refresh to see the latest.
Showing with 50 additions and 33 deletions.
  1. +50 −33 runner.js
View
83 runner.js
@@ -46,11 +46,23 @@ Runner.prototype.runDir = function (dir, cb) {
}
Runner.prototype.runFiles = function (files, dir, cb) {
-
var self = this
- chain(files.map(function (f) { return function (cb) {
+ chain(files.map(makeFileHandler), cb)
+
+ return self
+
+ function makeFileHandler(f) { return function (cb) {
var relDir = dir || path.dirname(f)
, fileName = relDir === "." ? f : f.substr(relDir.length + 1)
+ , cmd
+ , args = []
+ , env = {}
+ , err = ""
+ , out = ""
+ , tc = new TapConsumer
+
+ for (var i in process.env) env[i] = process.env[i]
+ env.TAP = 1
self.write(fileName)
fs.lstat(f, function (er, st) {
@@ -60,8 +72,7 @@ Runner.prototype.runFiles = function (files, dir, cb) {
return cb()
}
- var cmd = f
- , args = []
+ cmd = f
if (path.extname(f) === ".js") {
cmd = "node"
@@ -73,15 +84,21 @@ Runner.prototype.runFiles = function (files, dir, cb) {
if (st.isDirectory()) {
return self.runDir(f, cb)
}
-
- var env = {}
- for (var i in process.env) env[i] = process.env[i]
- env.TAP = 1
-
+
+ fs.readFile(f, 'utf8', runFile)
+ })
+
+ function runFile(er, fileSource) {
+ if (er) {
+ self.write(assert.fail("could not read "+f, {error: er}))
+ return cb()
+ }
+ if (fileSource.slice(0, 2) === '#!') {
+ args = fileSource.split('\n')[0].slice(2).trim().split(' ')
+ cmd = args.shift()
+ args.push(fileName)
+ }
var cp = child_process.spawn(cmd, args, { env: env, cwd: relDir })
- , out = ""
- , err = ""
- , tc = new TapConsumer
, childTests = [f]
tc.on("data", function (c) {
@@ -93,26 +110,26 @@ Runner.prototype.runFiles = function (files, dir, cb) {
cp.stdout.on("data", function (c) { out += c })
cp.stderr.on("data", function (c) { err += c })
- cp.on("exit", function (code) {
- //childTests.forEach(function (c) { self.write(c) })
- var res = { name: fileName
- , ok: !code }
- if (err) {
- res.stderr = err
- if (tc.results.ok && tc.results.tests === 0) {
- // perhaps a compilation error or something else failed...
- console.error(err)
- }
+ cp.on("exit", fileRan)
+ }
+
+ function fileRan(code) {
+ //childTests.forEach(function (c) { self.write(c) })
+ var res = { name: fileName
+ , ok: !code }
+ if (err) {
+ res.stderr = err
+ if (tc.results.ok && tc.results.tests === 0) {
+ // perhaps a compilation error or something else failed...
+ console.error(err)
}
- res.command = [cmd].concat(args).map(JSON.stringify).join(" ")
- self.emit("result", res)
- self.emit("file", f, res, tc.results)
- self.write(res)
- self.write("\n")
- cb()
- })
- })
- }}), cb)
-
- return self
+ }
+ res.command = [cmd].concat(args).map(JSON.stringify).join(" ")
+ self.emit("result", res)
+ self.emit("file", f, res, tc.results)
+ self.write(res)
+ self.write("\n")
+ cb()
+ }
+ }}
}
Something went wrong with that request. Please try again.