From 0bf4a38f5ea89f411b8e120711e8f3513f0d24f1 Mon Sep 17 00:00:00 2001 From: Nicolas Oliver Date: Thu, 17 Aug 2017 13:30:41 -0700 Subject: [PATCH] check for examples and images path Signed-off-by: Nicolas Oliver Signed-off-by: Abhishek Malik --- src/apa102/apa102.json | 4 +-- src/bh1750/bh1750.json | 4 +-- src/bmi160/bmi160.json | 2 +- tests/node/package.json | 1 + tests/node/test.js | 76 +++++++++++++++++++++++++++++++++++++++-- 5 files changed, 80 insertions(+), 7 deletions(-) diff --git a/src/apa102/apa102.json b/src/apa102/apa102.json index bab83835..e776eb77 100644 --- a/src/apa102/apa102.json +++ b/src/apa102/apa102.json @@ -12,7 +12,7 @@ "Manufacturers": ["Shiji Lighting", "Adafruit"], "Image": "apa102.jpg", "Examples": { - "Java": ["apa102.java"], + "Java": ["APA102Sample.java"], "Python": ["apa102.py"], "Node.js": ["apa102.js"], "C++": ["apa102.cxx"] @@ -42,4 +42,4 @@ } } } -} \ No newline at end of file +} diff --git a/src/bh1750/bh1750.json b/src/bh1750/bh1750.json index fc679e1c..1b85b51b 100644 --- a/src/bh1750/bh1750.json +++ b/src/bh1750/bh1750.json @@ -13,7 +13,7 @@ "Image": "bh1750.jpg", "Examples": { "Java": ["BH1750_Example.java"], - "Python": ["bh1750"], + "Python": ["bh1750.py"], "Node.js": ["bh1750.js"], "C++": ["bh1750.cxx"], "C": ["bh1750.c"] @@ -48,4 +48,4 @@ } } } -} \ No newline at end of file +} diff --git a/src/bmi160/bmi160.json b/src/bmi160/bmi160.json index eac8959d..7fea7a80 100644 --- a/src/bmi160/bmi160.json +++ b/src/bmi160/bmi160.json @@ -12,7 +12,7 @@ "Manufacturers": ["bosch"], "Image": "bmi160.jpg", "Examples": { - "Java": ["BMI190_Example.java"], + "Java": ["BMI1&0_Example.java"], "Python": ["bmi160.py"], "Node.js": ["bmi160.js"], "C++": ["bmi160.cxx"], diff --git a/tests/node/package.json b/tests/node/package.json index 376a61e7..99c6d4c1 100644 --- a/tests/node/package.json +++ b/tests/node/package.json @@ -12,6 +12,7 @@ "license": "ISC", "devDependencies": { "chai": "^4.1.1", + "json-query": "^2.2.2", "jsonlint": "^1.6.2", "mocha": "^3.5.0", "shelljs": "^0.7.8" diff --git a/tests/node/test.js b/tests/node/test.js index fbe29563..7856b5c9 100644 --- a/tests/node/test.js +++ b/tests/node/test.js @@ -1,10 +1,12 @@ var shell = require('shelljs'); var path = require('path'); var expect = require('chai').expect; +var jsonQuery = require('json-query'); var rootPath = path.resolve(__dirname, '../../'); var srcPath = path.resolve(rootPath, 'src'); -var examplePath = path.resolve(rootPath, 'examples'); +var examplesPath = path.resolve(rootPath, 'examples'); +var imagesPath = path.resolve(rootPath, 'docs/images'); var sensorTemplateJson = require(path.join(srcPath, 'sensortemplate/sensortemplate.json')); @@ -35,7 +37,7 @@ function checkProperty(target, propertyName, propertySpecs) { // Check non required property if (target[propertyName]) { var propertyType = getTypeName(target[propertyName]); - var errorMsg = propertyName + ' property should be a ' + propertySpecs.type; + var errorMsg = propertyName + ' property should be a ' + propertySpecs.type + '.'; expect(propertyType).to.be.equal(propertySpecs.type, errorMsg); } } @@ -114,6 +116,74 @@ function checkObjectSpecs(object, target) { } } +/** + * Check if the included image in the target actually exists + * in docs/images folder + * @param {object} target The json object to check + */ +function checkImageLinks(target) { + var imageLinksArray = jsonQuery('Sensor Class[**]Image', { + data: target + }).value; + + if(imageLinksArray) { + imageLinksArray.forEach(function (imageLink) { + it(imageLink + ' should exists in docs/images', function () { + var globalImagePath = path.join(imagesPath, imageLink); + var exists = shell.test('-e', globalImagePath); + var errorMsg = 'docs/images/' + imageLink + ' should exist, but was not found.'; + expect(exists).to.be.equal(true, errorMsg); + }); + }); + } +} + +/** + * Check if the included examples in the target actually exists + * in examples folder + * @param {object} target The json object to check + */ +function checkExamplesLinks(target) { + var examplesLinksArray = jsonQuery('Sensor Class[**]Examples', { + data: target + }).value; + + function checkExamplesLinksForLanguage(language, examplesSubfolder) { + var examples = examplesLinksArray[0][language]; + examples.forEach(function (example) { + it(example + ' should exists in examples/' + examplesSubfolder, function () { + var globalExamplePath = path.join(examplesPath, examplesSubfolder, example); + var exists = shell.test('-e', globalExamplePath); + var errorMsg = 'examples/' + examplesSubfolder + '/' + example + ' should exist, but was not found.'; + expect(exists).to.be.equal(true, errorMsg); + }); + }); + } + + if(examplesLinksArray[0]) { + // Check C++ examples + if(examplesLinksArray[0]['C++']) { + checkExamplesLinksForLanguage('C++', 'c++'); + } + // Check C examples + if(examplesLinksArray[0]['C']) { + checkExamplesLinksForLanguage('C', 'c'); + } + // Check Java examples + if(examplesLinksArray[0]['Java']) { + checkExamplesLinksForLanguage('Java', 'java'); + } + // Check Python examples + if(examplesLinksArray[0]['Python']) { + checkExamplesLinksForLanguage('Python', 'python'); + } + // Check Node.js examples + if(examplesLinksArray[0]['Node.js']) { + checkExamplesLinksForLanguage('Node.js', 'javascript'); + } + } +} + shell.find(srcPath) .filter(function (file) { return file.match(/\.json$/); @@ -131,5 +201,7 @@ shell.find(srcPath) describe(relativePath, function () { var parsedJson = require(jsonFile); checkObjectSpecs(sensorTemplateJson, parsedJson); + checkImageLinks(parsedJson); + checkExamplesLinks(parsedJson); }); });