diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000..3c3629e647 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +node_modules diff --git a/.travis.yml b/.travis.yml index 3d7e65b748..218b22710f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,12 +1,9 @@ -language: bash +language: node_js +node_js: + - "6" -sudo: false - -addons: - apt: - packages: - - jq +cache: yarn script: - - bin/jsonlint - bin/check_required_files_present + - npm test diff --git a/README.md b/README.md index 5767f7273b..2c355d8fe8 100644 --- a/README.md +++ b/README.md @@ -113,13 +113,26 @@ There are also some convention about `expected` that you must follow: ## Automated Tests -The only thing that we're testing at the moment, is whether or not `canonical-data.json` -is valid json. +`canonical-data.json` for each exercise is checked for compliancy against the [canonical-schema.json](canonical-schema.json). +In order to run these tests, you will need to have `node` and `npm` installed on your system. +Install them from [here](https://nodejs.org/en/). (`npm` comes bundled with most installations of `node`). -If you want to run this before you commit, you will need to install -[jq](https://stedolan.github.io/jq/download/). Then run the script with: +Install the required packages: +```shell +npm install +``` + +Run for all exercises: +```shell +npm test +``` + +Run for single exercise: +```shell +npm test-one exercises//canonical-data.json +``` +Replace `` by the name of exercise which you want to check. - bin/jsonlint ## License diff --git a/bin/jsonlint b/bin/jsonlint deleted file mode 100755 index cc955a4893..0000000000 --- a/bin/jsonlint +++ /dev/null @@ -1,27 +0,0 @@ -#!/usr/bin/env bash - -LINTER=jq -INSTRUCTIONS_URL="https://stedolan.github.io/jq/download/" - -function command_exists() { - type "$1" &> /dev/null -} - -function error_exit { - printf "$1" >&2 - exit "${2:-1}" -} - -if ! command_exists $LINTER; then - error_exit "'$LINTER' is not installed.\nSee $INSTRUCTIONS_URL for installation instructions.\n" -fi - -STATUS=0 -for f in $(ls exercises/**/*.json); do - cat $f | $LINTER . > /dev/null 2>&1 - if [ $? != 0 ]; then - echo "Invalid json: $f" - STATUS=1 - fi -done -exit $STATUS diff --git a/package.json b/package.json new file mode 100644 index 0000000000..3fa319526c --- /dev/null +++ b/package.json @@ -0,0 +1,16 @@ +{ + "name": "x-common", + "version": "1.0.0", + "description": "Shared metadata for exercism exercises.", + "main": "index.js", + "repository": "git@github.com:exercism/x-common.git", + "author": "Tejas Bubane ", + "license": "MIT", + "dependencies": { + "ajv-cli": "^1.1.1" + }, + "scripts": { + "test": "ajv -s canonical-schema.json -d \"exercises/*/canonical-data.json\"", + "test-one": "ajv -s canonical-schema.json -d" + } +} diff --git a/yarn.lock b/yarn.lock new file mode 100644 index 0000000000..a7133b35fd --- /dev/null +++ b/yarn.lock @@ -0,0 +1,195 @@ +# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. +# yarn lockfile v1 + + +abbrev@1: + version "1.1.0" + resolved "https://registry.yarnpkg.com/abbrev/-/abbrev-1.1.0.tgz#d0554c2256636e2f56e7c2e5ad183f859428d81f" + +ajv-cli@^1.1.1: + version "1.1.1" + resolved "https://registry.yarnpkg.com/ajv-cli/-/ajv-cli-1.1.1.tgz#08ba8006413e888973cfac650c3a95acc2e7c6be" + dependencies: + ajv "^4.7.4" + ajv-pack "^0.2.3" + fast-json-patch "^0.5.6" + glob "^7.0.3" + minimist "^1.2.0" + +ajv-pack@^0.2.3: + version "0.2.7" + resolved "https://registry.yarnpkg.com/ajv-pack/-/ajv-pack-0.2.7.tgz#bdd340f1c6799108d7aac12975a000c6e2a362c8" + dependencies: + js-beautify "^1.6.4" + require-from-string "^1.2.0" + +ajv@^4.7.4: + version "4.11.4" + resolved "https://registry.yarnpkg.com/ajv/-/ajv-4.11.4.tgz#ebf3a55d4b132ea60ff5847ae85d2ef069960b45" + dependencies: + co "^4.6.0" + json-stable-stringify "^1.0.1" + +balanced-match@^0.4.1: + version "0.4.2" + resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-0.4.2.tgz#cb3f3e3c732dc0f01ee70b403f302e61d7709838" + +bluebird@^3.0.5: + version "3.5.0" + resolved "https://registry.yarnpkg.com/bluebird/-/bluebird-3.5.0.tgz#791420d7f551eea2897453a8a77653f96606d67c" + +brace-expansion@^1.0.0: + version "1.1.6" + resolved "https://registry.yarnpkg.com/brace-expansion/-/brace-expansion-1.1.6.tgz#7197d7eaa9b87e648390ea61fc66c84427420df9" + dependencies: + balanced-match "^0.4.1" + concat-map "0.0.1" + +co@^4.6.0: + version "4.6.0" + resolved "https://registry.yarnpkg.com/co/-/co-4.6.0.tgz#6ea6bdf3d853ae54ccb8e47bfa0bf3f9031fb184" + +commander@^2.9.0: + version "2.9.0" + resolved "https://registry.yarnpkg.com/commander/-/commander-2.9.0.tgz#9c99094176e12240cb22d6c5146098400fe0f7d4" + dependencies: + graceful-readlink ">= 1.0.0" + +concat-map@0.0.1: + version "0.0.1" + resolved "https://registry.yarnpkg.com/concat-map/-/concat-map-0.0.1.tgz#d8a96bd77fd68df7793a73036a3ba0d5405d477b" + +config-chain@~1.1.5: + version "1.1.11" + resolved "https://registry.yarnpkg.com/config-chain/-/config-chain-1.1.11.tgz#aba09747dfbe4c3e70e766a6e41586e1859fc6f2" + dependencies: + ini "^1.3.4" + proto-list "~1.2.1" + +editorconfig@^0.13.2: + version "0.13.2" + resolved "https://registry.yarnpkg.com/editorconfig/-/editorconfig-0.13.2.tgz#8e57926d9ee69ab6cb999f027c2171467acceb35" + dependencies: + bluebird "^3.0.5" + commander "^2.9.0" + lru-cache "^3.2.0" + sigmund "^1.0.1" + +fast-json-patch@^0.5.6: + version "0.5.7" + resolved "https://registry.yarnpkg.com/fast-json-patch/-/fast-json-patch-0.5.7.tgz#b5a8f49d259624596ef98b872f3fda895b4d8665" + +fs.realpath@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/fs.realpath/-/fs.realpath-1.0.0.tgz#1504ad2523158caa40db4a2787cb01411994ea4f" + +glob@^7.0.3: + version "7.1.1" + resolved "https://registry.yarnpkg.com/glob/-/glob-7.1.1.tgz#805211df04faaf1c63a3600306cdf5ade50b2ec8" + dependencies: + fs.realpath "^1.0.0" + inflight "^1.0.4" + inherits "2" + minimatch "^3.0.2" + once "^1.3.0" + path-is-absolute "^1.0.0" + +"graceful-readlink@>= 1.0.0": + version "1.0.1" + resolved "https://registry.yarnpkg.com/graceful-readlink/-/graceful-readlink-1.0.1.tgz#4cafad76bc62f02fa039b2f94e9a3dd3a391a725" + +inflight@^1.0.4: + version "1.0.6" + resolved "https://registry.yarnpkg.com/inflight/-/inflight-1.0.6.tgz#49bd6331d7d02d0c09bc910a1075ba8165b56df9" + dependencies: + once "^1.3.0" + wrappy "1" + +inherits@2: + version "2.0.3" + resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.3.tgz#633c2c83e3da42a502f52466022480f4208261de" + +ini@^1.3.4: + version "1.3.4" + resolved "https://registry.yarnpkg.com/ini/-/ini-1.3.4.tgz#0537cb79daf59b59a1a517dff706c86ec039162e" + +js-beautify@^1.6.4: + version "1.6.11" + resolved "https://registry.yarnpkg.com/js-beautify/-/js-beautify-1.6.11.tgz#538a22867e669250935bcdc7b90a8cd6386ddab6" + dependencies: + config-chain "~1.1.5" + editorconfig "^0.13.2" + mkdirp "~0.5.0" + nopt "~3.0.1" + +json-stable-stringify@^1.0.1: + version "1.0.1" + resolved "https://registry.yarnpkg.com/json-stable-stringify/-/json-stable-stringify-1.0.1.tgz#9a759d39c5f2ff503fd5300646ed445f88c4f9af" + dependencies: + jsonify "~0.0.0" + +jsonify@~0.0.0: + version "0.0.0" + resolved "https://registry.yarnpkg.com/jsonify/-/jsonify-0.0.0.tgz#2c74b6ee41d93ca51b7b5aaee8f503631d252a73" + +lru-cache@^3.2.0: + version "3.2.0" + resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-3.2.0.tgz#71789b3b7f5399bec8565dda38aa30d2a097efee" + dependencies: + pseudomap "^1.0.1" + +minimatch@^3.0.2: + version "3.0.3" + resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-3.0.3.tgz#2a4e4090b96b2db06a9d7df01055a62a77c9b774" + dependencies: + brace-expansion "^1.0.0" + +minimist@0.0.8: + version "0.0.8" + resolved "https://registry.yarnpkg.com/minimist/-/minimist-0.0.8.tgz#857fcabfc3397d2625b8228262e86aa7a011b05d" + +minimist@^1.2.0: + version "1.2.0" + resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.0.tgz#a35008b20f41383eec1fb914f4cd5df79a264284" + +mkdirp@~0.5.0: + version "0.5.1" + resolved "https://registry.yarnpkg.com/mkdirp/-/mkdirp-0.5.1.tgz#30057438eac6cf7f8c4767f38648d6697d75c903" + dependencies: + minimist "0.0.8" + +nopt@~3.0.1: + version "3.0.6" + resolved "https://registry.yarnpkg.com/nopt/-/nopt-3.0.6.tgz#c6465dbf08abcd4db359317f79ac68a646b28ff9" + dependencies: + abbrev "1" + +once@^1.3.0: + version "1.4.0" + resolved "https://registry.yarnpkg.com/once/-/once-1.4.0.tgz#583b1aa775961d4b113ac17d9c50baef9dd76bd1" + dependencies: + wrappy "1" + +path-is-absolute@^1.0.0: + version "1.0.1" + resolved "https://registry.yarnpkg.com/path-is-absolute/-/path-is-absolute-1.0.1.tgz#174b9268735534ffbc7ace6bf53a5a9e1b5c5f5f" + +proto-list@~1.2.1: + version "1.2.4" + resolved "https://registry.yarnpkg.com/proto-list/-/proto-list-1.2.4.tgz#212d5bfe1318306a420f6402b8e26ff39647a849" + +pseudomap@^1.0.1: + version "1.0.2" + resolved "https://registry.yarnpkg.com/pseudomap/-/pseudomap-1.0.2.tgz#f052a28da70e618917ef0a8ac34c1ae5a68286b3" + +require-from-string@^1.2.0: + version "1.2.1" + resolved "https://registry.yarnpkg.com/require-from-string/-/require-from-string-1.2.1.tgz#529c9ccef27380adfec9a2f965b649bbee636418" + +sigmund@^1.0.1: + version "1.0.1" + resolved "https://registry.yarnpkg.com/sigmund/-/sigmund-1.0.1.tgz#3ff21f198cad2175f9f3b781853fd94d0d19b590" + +wrappy@1: + version "1.0.2" + resolved "https://registry.yarnpkg.com/wrappy/-/wrappy-1.0.2.tgz#b5243d8f3ec1aa35f1364605bc0d1036e30ab69f"