diff options
author | Yoichi Hirai <i@yoichihirai.com> | 2017-08-23 01:03:11 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-08-23 01:03:11 +0800 |
commit | 3c8e613c12a363b570fb8453c5955f5a0699b863 (patch) | |
tree | 79d40b8b8902d96325a706aaacc77243a70d9e45 /JSONSchema/validate.js | |
parent | 76c6d463525f21dcded3bd62176934901f118012 (diff) | |
parent | 28ccaf0bbd9d02cb63095da08feedd927021622d (diff) | |
download | tangerine-tests-3c8e613c12a363b570fb8453c5955f5a0699b863.tar tangerine-tests-3c8e613c12a363b570fb8453c5955f5a0699b863.tar.gz tangerine-tests-3c8e613c12a363b570fb8453c5955f5a0699b863.tar.bz2 tangerine-tests-3c8e613c12a363b570fb8453c5955f5a0699b863.tar.lz tangerine-tests-3c8e613c12a363b570fb8453c5955f5a0699b863.tar.xz tangerine-tests-3c8e613c12a363b570fb8453c5955f5a0699b863.tar.zst tangerine-tests-3c8e613c12a363b570fb8453c5955f5a0699b863.zip |
Merge pull request #213 from jwasinger/issue-204
JSON schema for state tests
Diffstat (limited to 'JSONSchema/validate.js')
-rwxr-xr-x | JSONSchema/validate.js | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/JSONSchema/validate.js b/JSONSchema/validate.js new file mode 100755 index 000000000..1a1a605db --- /dev/null +++ b/JSONSchema/validate.js @@ -0,0 +1,73 @@ +#! /bin/env node + +var fs = require('fs'); +var validate = require('jsonschema').validate; +var readline = require('readline'); + +var schemaFile = process.argv[2]; +var schema = ''; +var testCode = ''; +var success = true; +var numFiles = 0; +var numFailed = 0; +var numSucceeded = 0; +var fileNames = []; + +var rl = readline.createInterface({ + input: process.stdin, + output: process.stdout, + terminal: false +}); + +rl.on('line', function(line) { + fileNames.push(line); +}); + +rl.on('close', function() { + schema = JSON.parse(fs.readFileSync(schemaFile)); + + //sort file names alphabetically so that log output ordering is consistent + fileNames.sort(function(a,b) { + if(a<b) { + return -1; + } else { + return 1; + } + + return 0; + }); + + for (var i = 0; i < fileNames.length; i++) { + try { + testCode = JSON.parse(fs.readFileSync(fileNames[i])); + } catch(e) { + console.log('error on file:', fileNames[i]) + console.log(e); + numFailed++; + } + + try { + var x = validate(testCode, schema); + + 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') + } + } else { + numSucceeded++; + } + } catch (e) { + console.log(e); + numFailed++; + } + } + + console.log("Valid: "+numSucceeded+"\n"); + console.log("Failed: "+numFailed+"\n"); + + if(numFailed > 0) { + process.exit(-1); + } +}); |