[Pkg-javascript-commits] [node-stack-utils] 47/67: A test for some strange line parsing situations
Bastien Roucariès
rouca at moszumanska.debian.org
Thu Sep 7 09:53:05 UTC 2017
This is an automated email from the git hooks/post-receive script.
rouca pushed a commit to branch master
in repository node-stack-utils.
commit e7084dbdce1ec0d87d3e47a1161d243e67798e3c
Author: isaacs <i at izs.me>
Date: Sun Apr 23 13:25:49 2017 -0700
A test for some strange line parsing situations
---
test/fixtures/generate-parse-fixture.js | 206 +++++++++++++++++++++++++++
test/fixtures/parse-fixture.json | 237 ++++++++++++++++++++++++++++++++
test/parse-line-fixtures.js | 12 ++
3 files changed, 455 insertions(+)
diff --git a/test/fixtures/generate-parse-fixture.js b/test/fixtures/generate-parse-fixture.js
new file mode 100644
index 0000000..43a4e98
--- /dev/null
+++ b/test/fixtures/generate-parse-fixture.js
@@ -0,0 +1,206 @@
+'use strict'
+// Run this file to re-generate the parse fixture json after changes.
+
+let lines = new Set()
+const basename = require('path').basename(__filename)
+const lineRE = new RegExp('\\b' + basename + ':([0-9]+):([0-9]+)\\b', 'g')
+const capture = e => e.stack.split('\n').forEach(line => {
+ if (line === 'Error: ok')
+ return
+
+ lines.add(
+ line
+ .split(__dirname).join('__dirname')
+ .replace(lineRE, basename + ':420:69')
+ )
+})
+
+const done = _ => {
+ const StackUtils = require('../..')
+ var stack = new StackUtils()
+ const obj = Object.create(null)
+ lines.forEach(line => obj[line] = stack.parseLine(line))
+ const fs = require('fs')
+ const json = JSON.stringify(obj, null, 2) + '\n'
+ fs.writeFileSync(__dirname + '/parse-fixture.json', json)
+}
+
+{
+ const s = Symbol('foo')
+ const o = { [s] () { throw new Error('ok') } }
+ try {
+ o[s]()
+ } catch (e) {
+ capture(e)
+ }
+}
+
+{
+ const o = { ['asdf ][)( \u0000\u0001\u0002\u0003\u001b[44;37m foo'] () { throw new Error('ok') } }
+ try {
+ o['asdf ][)( \u0000\u0001\u0002\u0003\u001b[44;37m foo']()
+ } catch (e) {
+ capture(e)
+ }
+}
+
+{
+ const s = 'asdf (' + __filename + ':1:9999)'
+ const o = { [s] () { throw new Error('ok') } }
+ try {
+ o[s]()
+ } catch (e) {
+ capture(e)
+ }
+}
+
+{
+ const s = 'eval'
+ const o = { [s] () { throw new Error('ok') } }
+ try {
+ eval('o[s]()')
+ } catch (e) {
+ capture(e)
+ }
+}
+
+{
+ const vm = require('vm')
+ const code = 'function fooeval () { eval("o[s]()") }; fooeval()'
+ const s = 'a (s) d [f]'
+ const o = { [s] () { throw new Error('ok') } }
+ try {
+ vm.runInNewContext(code, {o, s}, { filename: 'a file with eval .js' })
+ } catch (e) {
+ capture(e)
+ }
+}
+
+{
+ const vm = require('vm')
+ const code = 'eval("o[s]()")'
+ const s = 'a (s) d [f]'
+ const o = { [s] () { throw new Error('ok') } }
+ try {
+ vm.runInNewContext(code, {o, s}, { filename: 'a file with eval .js' })
+ } catch (e) {
+ capture(e)
+ }
+}
+
+{
+ const s = 'function ctor (file.js:1:2) <anonymous>'
+ const o = { [s] () { throw new Error('ok') } }
+ try {
+ new Function('o', 's', 'o[s]()')(o, s)
+ } catch (e) {
+ capture(e)
+ }
+}
+
+{
+ const s = Symbol.iterator
+ const o = { [s] () { throw new Error('ok') } }
+ try {
+ new Function('o', 's', 'o[s]()')(o, s)
+ } catch (e) {
+ capture(e)
+ }
+}
+
+{
+ const s = Symbol.iterator
+ const o = new class Classy { [s] () { throw new Error('ok') } }
+ try {
+ new Function('o', 's', 'o[s]()')(o, s)
+ } catch (e) {
+ capture(e)
+ }
+}
+
+{
+ const s = Symbol('some (weird) [<symbolism>]')
+ const o = new class Classy { [s] () { throw new Error('ok') } }
+ try {
+ const x = o[s]
+ x()
+ } catch (e) {
+ capture(e)
+ }
+}
+
+{
+ const s = Symbol('some (weird) [<symbolism>]')
+ const o = new class Classy { [s] () { throw new Error('ok') } }
+ try {
+ const x = { foo: o[s] }
+ x.foo()
+ } catch (e) {
+ capture(e)
+ }
+}
+
+{
+ const s = Symbol('some (weird) [<symbolism>]')
+ const o = new class Classy { [s] () { throw new Error('ok') } }
+ try {
+ const x = new class OtherClass { constructor() { this.foo = o[s] } }
+ x.foo()
+ } catch (e) {
+ capture(e)
+ }
+}
+
+{
+ const vm = require('vm')
+ const o = { ['a (w) [<s>]'] () { throw new Error('ok') } }
+ try {
+ vm.runInNewContext('o["a (w) [<s>]"]()', { o: o })
+ } catch (e) {
+ capture(e)
+ }
+}
+
+{
+ const vm = require('vm')
+ const o = { ['a (w) [<s>]'] () { throw new Error('ok') } }
+ try {
+ vm.runInNewContext(
+ 'function x () { o["a (w) [<s>]"]() }\n' +
+ 'x()', { o: o }, {
+ filename: ' f[i](l<e>:.js:1:2) '
+ })
+ } catch (e) {
+ capture(e)
+ }
+}
+
+{
+ class Foo {
+ constructor () {
+ throw new Error('ok')
+ }
+ }
+ try {
+ new Foo()
+ } catch (e) {
+ capture(e)
+ }
+}
+
+{
+ class Foo {
+ constructor (n) {
+ this.n = n
+ throw new Error('ok')
+ }
+ }
+ const arr = [1,2,3]
+ try {
+ arr.map(n => new Foo(n))
+ } catch (e) {
+ capture(e)
+ }
+}
+
+done()
diff --git a/test/fixtures/parse-fixture.json b/test/fixtures/parse-fixture.json
new file mode 100644
index 0000000..9f69ff4
--- /dev/null
+++ b/test/fixtures/parse-fixture.json
@@ -0,0 +1,237 @@
+{
+ " at Object.[foo] (__dirname/generate-parse-fixture.js:420:69)": {
+ "line": 420,
+ "column": 69,
+ "file": "__dirname/generate-parse-fixture.js",
+ "function": "Object.[foo]"
+ },
+ " at Object.<anonymous> (__dirname/generate-parse-fixture.js:420:69)": {
+ "line": 420,
+ "column": 69,
+ "file": "__dirname/generate-parse-fixture.js",
+ "function": "Object.<anonymous>"
+ },
+ " at Module._compile (module.js:571:32)": {
+ "line": 571,
+ "column": 32,
+ "file": "module.js",
+ "function": "Module._compile"
+ },
+ " at Object.Module._extensions..js (module.js:580:10)": {
+ "line": 580,
+ "column": 10,
+ "file": "module.js",
+ "function": "Object.Module._extensions..js"
+ },
+ " at Module.load (module.js:488:32)": {
+ "line": 488,
+ "column": 32,
+ "file": "module.js",
+ "function": "Module.load"
+ },
+ " at tryModuleLoad (module.js:447:12)": {
+ "line": 447,
+ "column": 12,
+ "file": "module.js",
+ "function": "tryModuleLoad"
+ },
+ " at Function.Module._load (module.js:439:3)": {
+ "line": 439,
+ "column": 3,
+ "file": "module.js",
+ "function": "Function.Module._load"
+ },
+ " at Module.runMain (module.js:605:10)": {
+ "line": 605,
+ "column": 10,
+ "file": "module.js",
+ "function": "Module.runMain"
+ },
+ " at run (bootstrap_node.js:418:7)": {
+ "line": 418,
+ "column": 7,
+ "file": "bootstrap_node.js",
+ "function": "run"
+ },
+ " at startup (bootstrap_node.js:139:9)": {
+ "line": 139,
+ "column": 9,
+ "file": "bootstrap_node.js",
+ "function": "startup"
+ },
+ " at Object.asdf ][)( \u0000\u0001\u0002\u0003\u001b[44;37m foo (__dirname/generate-parse-fixture.js:420:69)": {
+ "line": 420,
+ "column": 69,
+ "file": "__dirname/generate-parse-fixture.js",
+ "function": "Object.asdf ][)( \u0000\u0001\u0002\u0003\u001b[44;37m foo"
+ },
+ " at Object.asdf (__dirname/generate-parse-fixture.js:420:69) (__dirname/generate-parse-fixture.js:420:69)": {
+ "line": 420,
+ "column": 69,
+ "file": "__dirname/generate-parse-fixture.js",
+ "function": "Object.asdf (__dirname/generate-parse-fixture.js:420:69)"
+ },
+ " at Object.eval (__dirname/generate-parse-fixture.js:420:69)": {
+ "line": 420,
+ "column": 69,
+ "file": "__dirname/generate-parse-fixture.js",
+ "function": "Object.eval"
+ },
+ " at eval (eval at <anonymous> (__dirname/generate-parse-fixture.js:420:69), <anonymous>:1:5)": {
+ "line": 1,
+ "column": 5,
+ "file": "<anonymous>",
+ "evalOrigin": "<anonymous>",
+ "evalLine": 420,
+ "evalColumn": 69,
+ "evalFile": "__dirname/generate-parse-fixture.js",
+ "function": "eval"
+ },
+ " at Object.a (s) d [f] (__dirname/generate-parse-fixture.js:420:69)": {
+ "line": 420,
+ "column": 69,
+ "file": "__dirname/generate-parse-fixture.js",
+ "function": "Object.a (s) d [f]"
+ },
+ " at eval (eval at fooeval (a file with eval .js:1:23), <anonymous>:1:5)": {
+ "line": 1,
+ "column": 5,
+ "file": "<anonymous>",
+ "evalOrigin": "fooeval",
+ "evalLine": 1,
+ "evalColumn": 23,
+ "evalFile": "a file with eval .js",
+ "function": "eval"
+ },
+ " at fooeval (a file with eval .js:1:23)": {
+ "line": 1,
+ "column": 23,
+ "file": "a file with eval .js",
+ "function": "fooeval"
+ },
+ " at a file with eval .js:1:41": {
+ "line": 1,
+ "column": 41,
+ "file": "a file with eval .js"
+ },
+ " at ContextifyScript.Script.runInContext (vm.js:32:29)": {
+ "line": 32,
+ "column": 29,
+ "file": "vm.js",
+ "function": "ContextifyScript.Script.runInContext"
+ },
+ " at ContextifyScript.Script.runInNewContext (vm.js:38:15)": {
+ "line": 38,
+ "column": 15,
+ "file": "vm.js",
+ "function": "ContextifyScript.Script.runInNewContext"
+ },
+ " at Object.exports.runInNewContext (vm.js:69:17)": {
+ "line": 69,
+ "column": 17,
+ "file": "vm.js",
+ "function": "Object.exports.runInNewContext"
+ },
+ " at eval (eval at <anonymous> (a file with eval .js:1:1), <anonymous>:1:5)": {
+ "line": 1,
+ "column": 5,
+ "file": "<anonymous>",
+ "evalOrigin": "<anonymous>",
+ "evalLine": 1,
+ "evalColumn": 1,
+ "evalFile": "a file with eval .js",
+ "function": "eval"
+ },
+ " at a file with eval .js:1:1": {
+ "line": 1,
+ "column": 1,
+ "file": "a file with eval .js"
+ },
+ " at Object.function ctor (file.js:1:2) <anonymous> (__dirname/generate-parse-fixture.js:420:69)": {
+ "line": 420,
+ "column": 69,
+ "file": "__dirname/generate-parse-fixture.js",
+ "function": "Object.function ctor (file.js:1:2) <anonymous>"
+ },
+ " at eval (eval at <anonymous> (__dirname/generate-parse-fixture.js:420:69), <anonymous>:3:5)": {
+ "line": 3,
+ "column": 5,
+ "file": "<anonymous>",
+ "evalOrigin": "<anonymous>",
+ "evalLine": 420,
+ "evalColumn": 69,
+ "evalFile": "__dirname/generate-parse-fixture.js",
+ "function": "eval"
+ },
+ " at Object.[Symbol.iterator] (__dirname/generate-parse-fixture.js:420:69)": {
+ "line": 420,
+ "column": 69,
+ "file": "__dirname/generate-parse-fixture.js",
+ "function": "Object.[Symbol.iterator]"
+ },
+ " at Classy.[Symbol.iterator] (__dirname/generate-parse-fixture.js:420:69)": {
+ "line": 420,
+ "column": 69,
+ "file": "__dirname/generate-parse-fixture.js",
+ "function": "Classy.[Symbol.iterator]"
+ },
+ " at [some (weird) [<symbolism>]] (__dirname/generate-parse-fixture.js:420:69)": {
+ "line": 420,
+ "column": 69,
+ "file": "__dirname/generate-parse-fixture.js",
+ "function": "[some (weird) [<symbolism>]]"
+ },
+ " at Object.[some (weird) [<symbolism>]] [as foo] (__dirname/generate-parse-fixture.js:420:69)": {
+ "line": 420,
+ "column": 69,
+ "file": "__dirname/generate-parse-fixture.js",
+ "function": "Object.[some (weird) [<symbolism>]]",
+ "method": "foo"
+ },
+ " at OtherClass.[some (weird) [<symbolism>]] [as foo] (__dirname/generate-parse-fixture.js:420:69)": {
+ "line": 420,
+ "column": 69,
+ "file": "__dirname/generate-parse-fixture.js",
+ "function": "OtherClass.[some (weird) [<symbolism>]]",
+ "method": "foo"
+ },
+ " at Object.a (w) [<s>] (__dirname/generate-parse-fixture.js:420:69)": {
+ "line": 420,
+ "column": 69,
+ "file": "__dirname/generate-parse-fixture.js",
+ "function": "Object.a (w) [<s>]"
+ },
+ " at evalmachine.<anonymous>:1:17": {
+ "line": 1,
+ "column": 17,
+ "file": "evalmachine.<anonymous>"
+ },
+ " at x ( f[i](l<e>:.js:1:2) :1:33)": {
+ "line": 1,
+ "column": 33,
+ "file": " f[i](l<e>:.js:1:2) ",
+ "function": "x"
+ },
+ " at f[i](l<e>:.js:1:2) :2:1": {
+ "line": 2,
+ "column": 1,
+ "file": " f[i](l<e>:.js:1:2) "
+ },
+ " at new Foo (__dirname/generate-parse-fixture.js:420:69)": {
+ "line": 420,
+ "column": 69,
+ "file": "__dirname/generate-parse-fixture.js",
+ "constructor": true,
+ "function": "Foo"
+ },
+ " at arr.map.n (__dirname/generate-parse-fixture.js:420:69)": {
+ "line": 420,
+ "column": 69,
+ "file": "__dirname/generate-parse-fixture.js",
+ "function": "arr.map.n"
+ },
+ " at Array.map (native)": {
+ "native": true,
+ "function": "Array.map"
+ }
+}
diff --git a/test/parse-line-fixtures.js b/test/parse-line-fixtures.js
new file mode 100644
index 0000000..c18ef10
--- /dev/null
+++ b/test/parse-line-fixtures.js
@@ -0,0 +1,12 @@
+var t = require('tap')
+var cases = require('./fixtures/parse-fixture.json')
+var lines = Object.keys(cases)
+var StackUtils = require('../')
+var stack = new StackUtils()
+t.plan(lines.length * 2)
+lines.forEach(function (line) {
+ var expect = cases[line]
+ t.match(stack.parseLine(line), expect, JSON.stringify(line))
+ line = line.replace(/^ at /, '')
+ t.match(stack.parseLine(line), expect, JSON.stringify(line))
+})
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-stack-utils.git
More information about the Pkg-javascript-commits
mailing list