summaryrefslogtreecommitdiff
path: root/test/parallel/test-assert-first-line.js
diff options
context:
space:
mode:
authorRuben Bridgewater <ruben@bridgewater.de>2018-07-02 20:29:57 +0200
committerRuben Bridgewater <ruben@bridgewater.de>2018-07-16 11:30:55 +0200
commit43ee4d692afb7bae224e529c6088d3890b4ea31f (patch)
tree0f262da3d65fe781a20d142487c92d0fb1eee2cf /test/parallel/test-assert-first-line.js
parent7eeb7948b3a9f29334612a79f349178888df5f7e (diff)
downloadandroid-node-v8-43ee4d692afb7bae224e529c6088d3890b4ea31f.tar.gz
android-node-v8-43ee4d692afb7bae224e529c6088d3890b4ea31f.tar.bz2
android-node-v8-43ee4d692afb7bae224e529c6088d3890b4ea31f.zip
assert: improve simple assert
1) If simple assert is called in the very first line of a file and it causes an error, it used to report the wrong code. The reason is that the column that is reported is faulty. This is fixed by subtracting the offset from now on in such cases. 2) The actual code read is now limited to the part that is actually required to visualize the call site. All other code in e.g. minified files will not cause a significant overhead anymore. 3) The number of allocations is now significantly lower than it used to be. The buffer is reused until the correct line in the code is found. In general the algorithm tries to safe operations where possible. 4) The indentation is now corrected depending on where the statement actually beginns. 5) It is now possible to handle `.call()` and `.apply()` properly. 6) The user defined function name will now always be used instead of only choosing either `assert.ok()` or `assert()`. PR-URL: https://github.com/nodejs/node/pull/21626 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Ben Coe <bencoe@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'test/parallel/test-assert-first-line.js')
-rw-r--r--test/parallel/test-assert-first-line.js23
1 files changed, 23 insertions, 0 deletions
diff --git a/test/parallel/test-assert-first-line.js b/test/parallel/test-assert-first-line.js
new file mode 100644
index 0000000000..32eadbf741
--- /dev/null
+++ b/test/parallel/test-assert-first-line.js
@@ -0,0 +1,23 @@
+'use strict';
+
+// Verify that asserting in the very first line produces the expected result.
+
+require('../common');
+const assert = require('assert');
+const { path } = require('../common/fixtures');
+
+assert.throws(
+ () => require(path('assert-first-line')),
+ {
+ name: 'AssertionError [ERR_ASSERTION]',
+ message: "The expression evaluated to a falsy value:\n\n ässört.ok('')\n"
+ }
+);
+
+assert.throws(
+ () => require(path('assert-long-line')),
+ {
+ name: 'AssertionError [ERR_ASSERTION]',
+ message: "The expression evaluated to a falsy value:\n\n assert.ok('')\n"
+ }
+);