aboutsummaryrefslogtreecommitdiffstats
path: root/test/buglistTests.js
diff options
context:
space:
mode:
authorLeonardo Alt <leo@ethereum.org>2018-08-03 19:55:44 +0800
committerchriseth <chris@ethereum.org>2018-08-14 21:57:38 +0800
commit55e67e41f9356e4953a57d8a15808e1c7d391686 (patch)
tree368286d5f45ab87bf91a054a5ce20ea7dd918662 /test/buglistTests.js
parente1bb6848976c7a54baa19e3e61f9aeeb58f55f5a (diff)
downloaddexon-solidity-55e67e41f9356e4953a57d8a15808e1c7d391686.tar.gz
dexon-solidity-55e67e41f9356e4953a57d8a15808e1c7d391686.tar.zst
dexon-solidity-55e67e41f9356e4953a57d8a15808e1c7d391686.zip
Update bug list and add regular expression to bug list and add test.
Diffstat (limited to 'test/buglistTests.js')
-rwxr-xr-xtest/buglistTests.js45
1 files changed, 45 insertions, 0 deletions
diff --git a/test/buglistTests.js b/test/buglistTests.js
new file mode 100755
index 00000000..6b7df2f2
--- /dev/null
+++ b/test/buglistTests.js
@@ -0,0 +1,45 @@
+#!/usr/bin/env node
+
+"use strict";
+
+var fs = require('fs')
+var bugs = JSON.parse(fs.readFileSync(__dirname + '/../docs/bugs.json', 'utf8'))
+
+var bugsByName = {}
+for (var i in bugs)
+{
+ if (bugs[i].name in bugsByName)
+ {
+ throw "Duplicate bug name: " + bugs[i].name
+ }
+ bugsByName[bugs[i].name] = bugs[i]
+}
+
+var tests = fs.readFileSync(__dirname + '/buglist_test_vectors.md', 'utf8')
+
+var testVectorParser = /\s*#\s+(\S+)\s+## buggy\n([^#]*)## fine\n([^#]*)/g
+
+var result;
+while ((result = testVectorParser.exec(tests)) !== null)
+{
+ var name = result[1]
+ var buggy = result[2].split('\n--\n')
+ var fine = result[3].split('\n--\n')
+ console.log("Testing " + name + " with " + buggy.length + " buggy and " + fine.length + " fine instances")
+
+ var regex = RegExp(bugsByName[name].check['regex-source'])
+ for (var i in buggy)
+ {
+ if (!regex.exec(buggy[i]))
+ {
+ throw "Bug " + name + ": Buggy source does not match: " + buggy[i]
+ }
+ }
+ for (var i in fine)
+ {
+ if (regex.exec(fine[i]))
+ {
+ throw "Bug " + name + ": Non-buggy source matches: " + fine[i]
+ }
+ }
+}