Permalink
Browse files

move from in-tree tests to using them from the JSONSelectTests submod…

…ule. closes #16.
  • Loading branch information...
1 parent 6b402c0 commit ea7ca9b64fd38e2a3023b4e8568e6025d37f78bf @lloyd committed May 28, 2011
View
@@ -0,0 +1,3 @@
+[submodule "src/test/tests"]
+ path = src/test/tests
+ url = git://github.com/lloyd/JSONSelectTests
View
@@ -13,7 +13,7 @@ SRC = ${SRC_DIR}/jsonselect.js
DIST = ${DIST_DIR}/jsonselect.js
DIST_MIN = ${DIST_DIR}/jsonselect.min.js
-all: hint project min
+all: hint project min tests
@@echo "Project build complete."
${DIST_DIR}:
@@ -49,9 +49,25 @@ hint:
fi
+test/tests/README.md:
+ @@cd .. && git submodule init
+ @@cd .. && git submodule update
+
+
+tests: test/tests/README.md
+ @@if test ! -z ${JS_ENGINE}; then \
+ echo "Testing Project"; \
+ ${JS_ENGINE} test/run.js; \
+ else \
+ echo "nodejs is missing"; \
+ fi
+
+
clean:
@@echo "Removing Distribution directory:" ${DIST_DIR}
@@rm -rf ${DIST_DIR}
-.PHONY: all project hint min
+
+
+.PHONY: all project hint min tests
View
@@ -16,9 +16,9 @@ var numTests = 0;
var numPassed = 0;
var tests = {};
-function runOneSync(name, selname) {
- var testDocPath = path.join(pathToTests, name + ".json");
- var selDocPath = path.join(pathToTests, name + '_' +
+function runOneSync(name, selname, p) {
+ var testDocPath = path.join(p, name + ".json");
+ var selDocPath = path.join(p, name + '_' +
selname + ".selector");
var outputDocPath = selDocPath.replace(/selector$/, "output");
@@ -35,14 +35,14 @@ function runOneSync(name, selname) {
}
- function runTests() {
- console.log("Running Tests:");
+function runTests() {
+ console.log("Running Tests:");
for (var d in tests) {
console.log(" tests against '" + d + ".json`:");
for (var i = 0; i < tests[d].length; i++) {
- sys.print(" " + tests[d][i] + ": ");
+ sys.print(" " + tests[d][i][0] + ": ");
try {
- runOneSync(d, tests[d][i]);
+ runOneSync(d, tests[d][i][0], tests[d][i][1]);
numPassed++;
console.log("pass");
} catch (e) {
@@ -55,15 +55,20 @@ function runOneSync(name, selname) {
}
// discover all tests
-fs.readdir(pathToTests, function(e, files) {
+var pathToTests = path.join(__dirname, "tests");
+
+fs.readdirSync(pathToTests).forEach(function(subdir) {
+ var p = path.join(pathToTests, subdir);
+ if (!fs.statSync(p).isDirectory()) return;
+ var files = fs.readdirSync(p);
for (var i = 0; i < files.length; i++) {
var f = files[i];
var m = /^([A-Za-z]+)_(.+)\.selector$/.exec(f);
if (m) {
if (!tests.hasOwnProperty(m[1])) tests[m[1]] = [];
numTests++;
- tests[m[1]].push(m[2]);
+ tests[m[1]].push([m[2], p]);
}
}
- runTests();
});
+runTests();
View
Submodule tests added at 728372
View
@@ -1,14 +0,0 @@
-## JSONSelect Conformance Tests.
-
-Test documents have a suffix of `.json`, like `basic.json`.
-
-Selectors to be applied to test documents have the document name,
-followed by an underbar, followed by a description of the test, with
-a `.selector` file name suffix, like `basic_grouping.selector`.
-
-Expected output files have the same name as the `.selector` file,
-but have a `.output` suffix, like `basic_grouping.output`.
-
-Expected output files contain a stream of JSON objects that are what
-is expected to be produced when a given selector is applied to a given
-document.
View
@@ -1,31 +0,0 @@
-basic.json
-basic_first-child.output
-basic_first-child.selector
-basic_grouping.output
-basic_grouping.selector
-basic_id.output
-basic_id.selector
-basic_id_multiple.output
-basic_id_multiple.selector
-basic_id_quotes.output
-basic_id_quotes.selector
-basic_id_with_type.output
-basic_id_with_type.selector
-basic_last-child.output
-basic_last-child.selector
-basic_nth-child-2.output
-basic_nth-child-2.selector
-basic_nth-child.output
-basic_nth-child.selector
-basic_nth-last-child.output
-basic_nth-last-child.selector
-basic_root_pseudo.output
-basic_root_pseudo.selector
-basic_type.output
-basic_type.selector
-basic_type2.output
-basic_type2.selector
-basic_type3.output
-basic_type3.selector
-basic_universal.output
-basic_universal.selector
View
@@ -1,31 +0,0 @@
-{
- "name": {
- "first": "Lloyd",
- "last": "Hilaiel"
- },
- "favoriteColor": "yellow",
- "languagesSpoken": [
- {
- "language": "Bulgarian",
- "level": "advanced"
- },
- {
- "language": "English",
- "level": "native"
- },
- {
- "language": "Spanish",
- "level": "beginner"
- }
- ],
- "seatingPreference": [
- "window",
- "aisle"
- ],
- "drinkPreference": [
- "beer",
- "whiskey",
- "wine"
- ],
- "weight": 172
-}
@@ -1,2 +0,0 @@
-"window"
-"beer"
@@ -1,2 +0,0 @@
-string:first-child
-
@@ -1,4 +0,0 @@
-"advanced"
-"native"
-"beginner"
-172
@@ -1 +0,0 @@
-string.level,number
@@ -1 +0,0 @@
-"yellow"
@@ -1 +0,0 @@
-.favoriteColor
@@ -1,3 +0,0 @@
-"Bulgarian"
-"English"
-"Spanish"
@@ -1 +0,0 @@
-.language
@@ -1,2 +0,0 @@
-172
-
@@ -1 +0,0 @@
-."weight"
@@ -1 +0,0 @@
-"yellow"
@@ -1 +0,0 @@
-string.favoriteColor
@@ -1,2 +0,0 @@
-"aisle"
-"wine"
@@ -1,2 +0,0 @@
-string:last-child
-
@@ -1,4 +0,0 @@
-"window"
-"aisle"
-"beer"
-"whiskey"
@@ -1 +0,0 @@
-string:nth-child(-n+2)
@@ -1,3 +0,0 @@
-"window"
-"beer"
-"wine"
@@ -1 +0,0 @@
-string:nth-child(odd)
@@ -1,2 +0,0 @@
-"aisle"
-"wine"
@@ -1 +0,0 @@
-string:nth-last-child(1)
@@ -1,31 +0,0 @@
-{
- "name": {
- "first": "Lloyd",
- "last": "Hilaiel"
- },
- "favoriteColor": "yellow",
- "languagesSpoken": [
- {
- "language": "Bulgarian",
- "level": "advanced"
- },
- {
- "language": "English",
- "level": "native"
- },
- {
- "language": "Spanish",
- "level": "beginner"
- }
- ],
- "seatingPreference": [
- "window",
- "aisle"
- ],
- "drinkPreference": [
- "beer",
- "whiskey",
- "wine"
- ],
- "weight": 172
-}
@@ -1 +0,0 @@
-:root
@@ -1,14 +0,0 @@
-"Lloyd"
-"Hilaiel"
-"yellow"
-"Bulgarian"
-"advanced"
-"English"
-"native"
-"Spanish"
-"beginner"
-"window"
-"aisle"
-"beer"
-"whiskey"
-"wine"
@@ -1 +0,0 @@
-string
@@ -1 +0,0 @@
-172
@@ -1 +0,0 @@
-number
@@ -1,47 +0,0 @@
-{
- "first": "Lloyd",
- "last": "Hilaiel"
-}
-{
- "language": "Bulgarian",
- "level": "advanced"
-}
-{
- "language": "English",
- "level": "native"
-}
-{
- "language": "Spanish",
- "level": "beginner"
-}
-{
- "name": {
- "first": "Lloyd",
- "last": "Hilaiel"
- },
- "favoriteColor": "yellow",
- "languagesSpoken": [
- {
- "language": "Bulgarian",
- "level": "advanced"
- },
- {
- "language": "English",
- "level": "native"
- },
- {
- "language": "Spanish",
- "level": "beginner"
- }
- ],
- "seatingPreference": [
- "window",
- "aisle"
- ],
- "drinkPreference": [
- "beer",
- "whiskey",
- "wine"
- ],
- "weight": 172
-}
@@ -1 +0,0 @@
-object
Oops, something went wrong. Retry.

0 comments on commit ea7ca9b

Please sign in to comment.