check for examples and images path

This commit is contained in:
Nicolas Oliver 2017-08-17 13:30:41 -07:00
parent 4bb652cb4b
commit 02d8a16d4b
8 changed files with 86 additions and 13 deletions

View File

@ -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"]

View File

@ -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"]

View File

@ -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"],

View File

@ -12,7 +12,7 @@
"Manufacturers": ["Seeed"],
"Kits": ["gsk", "eak", "hak"],
"Examples": {
"C++": ["grovebutton.cxx"]
"C++": ["grove-grovebutton.cxx"]
},
"Urls": {
"Product Pages": ["https://github.com/intel-iot-devkit/upm/tree/master/src/grove"]

View File

@ -15,7 +15,7 @@
"Java": ["MPU9150Sample.java"],
"Python": ["mpu9150.py"],
"Node.js": ["mpu9150.js"],
"C++": ["mpu9150-ak8975.cxx.cxx", "mpu9150-mpu60x0.cxx", "mpu9150-mpu9250.cxx", "mpu9150.cxx"]
"C++": ["mpu9150-ak8975.cxx", "mpu9150-mpu60x0.cxx", "mpu9150-mpu9250.cxx", "mpu9150.cxx"]
},
"Specifications": {
"Vsource": {

View File

@ -14,7 +14,7 @@
"Examples": {
"Python": ["grovecircularled.py"],
"Node.js": ["grovecircularled.js"],
"C++": ["my9221-grovecircularled.cxx.cxx"]
"C++": ["my9221-grovecircularled.cxx"]
},
"Specifications": {
"Vsource": {

View File

@ -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"

View File

@ -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);
});
});