var tt = require('../')

if (process.argv[2] === 'child')
  tt('child', child)
else
  tt('parent', parent)

function child(t) {
  // this passes
  t.ok(true, 'yoyoyo')
  t.ok(false, 'message')
  t.equal(true, 1, 'basically the same')
  t.strictEqual(true, 1, 'but not quite')
  t.test('firstborn', function (t) {
    t.deepEqual([1,2,3], [1,2,3])
    t.test('grandchild', function (t) {
      t.ok(true)
      t.ok(false)
      t.end()
    })
    t.test('grandchild 2', function (t) {
      t.ok(true)
      t.ok(false)
      t.end()
    })
    t.end()
  })
  t.test('secondborn', function (t) {
    t.deepEqual([1,2,3], [1,2,5], 'not the same!')
    t.end()
  })
  t.end()
}

var path = require('path')
var TT = path.dirname(__dirname)
var expect = (function(){/*
# child

ok 1 ok

not ok 2 AssertionError: message
# at child ({TT}/test/basic.js:11:5)
# at {TT}/tt.js:98:5
# at process._tickCallback (node.js:415:13)
# at Function.Module.runMain (module.js:499:11)


ok 3 equal

not ok 4 AssertionError: but not quite
# at child ({TT}/test/basic.js:13:5)
# at {TT}/tt.js:98:5
# at process._tickCallback (node.js:415:13)
# at Function.Module.runMain (module.js:499:11)


# firstborn

ok 5 deepEqual

# grandchild

ok 6 ok

not ok 7 AssertionError: false == true
# at {TT}/test/basic.js:18:9
# at {TT}/tt.js:98:5
# at process._tickCallback (node.js:415:13)
# at Function.Module.runMain (module.js:499:11)


# grandchild 2

ok 8 ok

not ok 9 AssertionError: false == true
# at {TT}/test/basic.js:23:9
# at {TT}/tt.js:98:5
# at process._tickCallback (node.js:415:13)
# at Function.Module.runMain (module.js:499:11)


# secondborn

not ok 10 AssertionError: not the same!
# at {TT}/test/basic.js:29:7
# at {TT}/tt.js:98:5
# at process._tickCallback (node.js:415:13)
# at Function.Module.runMain (module.js:499:11)


0..10

# pass 5/10
# fail 5/10
*/}).toString().split(/\n/).slice(1, -1).join('\n')
.replace(/\{TT\}/g, TT)
.replace(/:[0-9]+:[0-9]+(\)?)\n/g, ':#:#$1\n')

function parent(t) {
  var spawn = require('child_process').spawn
  var args = [ __filename, 'child' ]
  var node = process.execPath
  var child = spawn(node, args)
  var stdout = ''
  var stderr = ''
  child.stdout.on('data', function(c) {
    stdout += c
  })
  child.stderr.on('data', function(c) {
    stderr += c
  })
  child.on('close', function(code, signal) {
    stdout = stdout.trim().replace(/:[0-9]+:[0-9]+(\)?)\n/g, ':#:#$1\n')
    t.equal(stdout.trim(), expect.trim(), 'correct output')
    t.equal(code, 5, 'error code')
    t.equal(signal, null, 'no signal')
    t.end()
  })
}

@@ -844,13 +844,11 @@
 .js:
-11:5)
+#:#
 %0A# a
@@ -852,36 +852,35 @@
 # at %7BTT%7D/tt.js:
-98:5
+#:#
 %0A# at process._t
@@ -892,39 +892,35 @@
 llback (node.js:
-415:13)
+#:#
 %0A# at Function.M
@@ -944,23 +944,19 @@
 dule.js:
-499:11)
+#:#
 %0A%0A%0Aok 3 
@@ -1036,13 +1036,11 @@
 .js:
-13:5)
+#:#
 %0A# a
@@ -1044,36 +1044,35 @@
 # at %7BTT%7D/tt.js:
-98:5
+#:#
 %0A# at process._t
@@ -1084,39 +1084,35 @@
 llback (node.js:
-415:13)
+#:#
 %0A# at Function.M
@@ -1132,31 +1132,27 @@
  (module.js:
-499:11)
+#:#
 %0A%0A%0A# firstbo
@@ -1261,12 +1261,11 @@
 .js:
-18:9
+#:#
 %0A# a
@@ -1269,36 +1269,35 @@
 # at %7BTT%7D/tt.js:
-98:5
+#:#
 %0A# at process._t
@@ -1309,39 +1309,35 @@
 llback (node.js:
-415:13)
+#:#
 %0A# at Function.M
@@ -1357,31 +1357,27 @@
  (module.js:
-499:11)
+#:#
 %0A%0A%0A# grandch
@@ -1459,12 +1459,11 @@
 .js:
-23:9
+#:#
 %0A# a
@@ -1467,36 +1467,35 @@
 # at %7BTT%7D/tt.js:
-98:5
+#:#
 %0A# at process._t
@@ -1507,39 +1507,35 @@
 llback (node.js:
-415:13)
+#:#
 %0A# at Function.M
@@ -1559,23 +1559,19 @@
 dule.js:
-499:11)
+#:#
 %0A%0A%0A# sec
@@ -1647,12 +1647,11 @@
 .js:
-29:7
+#:#
 %0A# a
@@ -1667,12 +1667,11 @@
 .js:
-98:5
+#:#
 %0A# a
@@ -1707,15 +1707,11 @@
 .js:
-415:13)
+#:#
 %0A# a
@@ -1751,15 +1751,11 @@
 .js:
-499:11)
+#:#
 %0A%0A%0A0
@@ -1863,55 +1863,8 @@
  TT)
-%0A.replace(/:%5B0-9%5D+:%5B0-9%5D+(%5C)?)%5Cn/g, ':#:#$1%5Cn')
 %0A%0Afu
@@ -2299,10 +2299,8 @@
 :#:#
-$1
 %5Cn')

simplify output test