aboutsummaryrefslogtreecommitdiffstats
path: root/JSONSchema/validate.js
diff options
context:
space:
mode:
authorJared Wasinger <j-wasinger@hotmail.com>2017-07-06 14:37:04 +0800
committerUbuntu <ubuntu@ip-172-31-32-43.us-west-2.compute.internal>2017-08-08 04:41:46 +0800
commit6bdff4b01b9bda7264b4208ee12d8b7206191f98 (patch)
tree2e538911d18705d9c8c3b22cf48bc54f4bc801b7 /JSONSchema/validate.js
parent2b523eb61c79bdc5f066e49c97c6ddfb971a2f03 (diff)
downloaddexon-tests-6bdff4b01b9bda7264b4208ee12d8b7206191f98.tar.gz
dexon-tests-6bdff4b01b9bda7264b4208ee12d8b7206191f98.tar.zst
dexon-tests-6bdff4b01b9bda7264b4208ee12d8b7206191f98.zip
make error output more informative. Make schema more comprehensive. Add exit code of -1 upon failure
Diffstat (limited to 'JSONSchema/validate.js')
-rwxr-xr-xJSONSchema/validate.js69
1 files changed, 38 insertions, 31 deletions
diff --git a/JSONSchema/validate.js b/JSONSchema/validate.js
index c98e4bbf8..4c63500d0 100755
--- a/JSONSchema/validate.js
+++ b/JSONSchema/validate.js
@@ -1,15 +1,17 @@
#! /bin/env node
-var validate = require('jsonschema').validate;
var fs = require('fs');
-
+var validate = require('jsonschema').validate;
var readline = require('readline');
var schema = '';
var testCode = '';
var success = true;
+var numFiles = 0;
+var numFailed = 0;
+var numSucceeded = 0;
+var fileNames = [];
-var readline = require('readline');
var rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
@@ -17,37 +19,42 @@ var rl = readline.createInterface({
});
rl.on('line', function(line) {
- fs.readFile('JSONSchema/schema.json', function(err, data) {
- if (err) {
- throw err;
- }
-
- schema = JSON.parse(data);
-
- fs.readFile(line, function(err, data) {
- if (err) {
- throw err;
- }
+ fileNames.push(line);
+});
- try {
- testCode = JSON.parse(data);
- } catch (e) {
- console.log(e);
- }
+rl.on('close', function() {
+ schema = JSON.parse(fs.readFileSync('JSONSchema/schema.json'));
+
+ for (var i = 0; i < fileNames.length; i++) {
+ try {
+ testCode = JSON.parse(fs.readFileSync(fileNames[i]));
+ } catch(e) {
+ console.log(e);
+ numFailed++;
+ }
- try {
- var x = validate(testCode, schema);
+ try {
+ var x = validate(testCode, schema);
- if (x.errors.length > 0) {
- success = false;
- console.log(line + ':\n');
- for (var i = 0; i < x.errors.length; i++) {
- console.log(' ' + x.errors[i] + '\n')
- }
+ if (x.errors.length > 0) {
+ numFailed++;
+ console.log(fileNames[i]+ ':\n');
+ for (var j = 0; j < x.errors.length; j++) {
+ console.log(' ' + x.errors[j] + '\n')
}
- } catch (e) {
- console.log(e);
+ } else {
+ numSucceeded++;
}
- });
- });
+ } catch (e) {
+ console.log(e);
+ numFailed++;
+ }
+ }
+
+ console.log("Valid: "+numSucceeded+"\n");
+ console.log("Failed: "+numFailed+"\n");
+
+ if(numFailed > 0) {
+ process.exit(-1);
+ }
});