diff --git a/package.json b/package.json index bb8424c562d..c75fc5f226a 100644 --- a/package.json +++ b/package.json @@ -120,7 +120,7 @@ "open-changed-examples": "git diff --name-only mb-pages HEAD -- docs/_posts/examples/*.html | awk '{print \"http://127.0.0.1:4000/mapbox-gl-js/example/\" substr($0,33,length($0)-37)}' | xargs open", "test": "run-s lint lint-css test-unit test-flow", "test-suite": "run-s test-render test-query", - "test-suite-clean": "find test/integration/*-tests -mindepth 2 -type d -not \\( -exec test -e \"{}/style.json\" \\; \\) -print | xargs -t rm -r", + "test-suite-clean": "find test/integration/{render,query}-tests -mindepth 2 -type d -not \\( -exec test -e \"{}/style.json\" \\; \\) -print | xargs -t rm -r", "test-unit": "tap --reporter dot --no-coverage test/unit", "test-render": "node test/render.test.js", "test-query": "node test/query.test.js", diff --git a/test/expression.test.js b/test/expression.test.js new file mode 100644 index 00000000000..c8ae2d90cd5 --- /dev/null +++ b/test/expression.test.js @@ -0,0 +1,38 @@ +'use strict'; + +require('flow-remove-types/register'); +const util = require('../src/util/util'); +const expressionSuite = require('./integration').expression; +const compileExpression = require('../src/style-spec/function/expression'); + +let tests; + +if (process.argv[1] === __filename && process.argv.length > 2) { + tests = process.argv.slice(2); +} + +expressionSuite.run('js', {tests: tests}, (fixture) => { + const compiled = compileExpression(fixture.expression); + + const testResult = { + compileResult: util.pick(compiled, ['result', 'isFeatureConstant', 'isZoomConstant', 'errors']) + }; + if (compiled.result === 'success') testResult.compileResult.type = compiled.type.name; + + if (compiled.result === 'success' && fixture.evaluate) { + const evaluateResults = []; + for (const input of fixture.evaluate) { + try { + const output = compiled.function.apply(null, input); + evaluateResults.push(output); + } catch (error) { + evaluateResults.push({ error: error.toJSON() }); + } + } + if (evaluateResults.length) { + testResult.evaluateResults = evaluateResults; + } + } + + return testResult; +}); diff --git a/test/integration/expression-tests/acos/basic/test.json b/test/integration/expression-tests/acos/basic/test.json new file mode 100644 index 00000000000..cb9ece574aa --- /dev/null +++ b/test/integration/expression-tests/acos/basic/test.json @@ -0,0 +1,23 @@ +{ + "expression": [ + "acos", + 0.5 + ], + "evaluate": [ + [ + {}, + {} + ] + ], + "expected": { + "compileResult": { + "result": "success", + "isFeatureConstant": true, + "isZoomConstant": true, + "type": "number" + }, + "evaluateResults": [ + 1.0471975511965976 + ] + } +} \ No newline at end of file diff --git a/test/integration/expression-tests/and/basic/test.json b/test/integration/expression-tests/and/basic/test.json new file mode 100644 index 00000000000..3b00f960a81 --- /dev/null +++ b/test/integration/expression-tests/and/basic/test.json @@ -0,0 +1,57 @@ +{ + "expression": [ + "&&", + [ + "boolean", + [ + "get", + [ + "properties" + ], + "x" + ] + ], + [ + "boolean", + [ + "get", + [ + "properties" + ], + "y" + ] + ] + ], + "evaluate": [ + [ + {}, + { + "properties": { + "x": true, + "y": false + } + } + ], + [ + {}, + { + "properties": { + "x": true, + "y": true + } + } + ] + ], + "expected": { + "compileResult": { + "result": "success", + "isFeatureConstant": false, + "isZoomConstant": true, + "type": "boolean" + }, + "evaluateResults": [ + false, + true + ] + } +} \ No newline at end of file diff --git a/test/integration/expression-tests/asin/basic/test.json b/test/integration/expression-tests/asin/basic/test.json new file mode 100644 index 00000000000..2033bef3994 --- /dev/null +++ b/test/integration/expression-tests/asin/basic/test.json @@ -0,0 +1,23 @@ +{ + "expression": [ + "asin", + 0.5 + ], + "evaluate": [ + [ + {}, + {} + ] + ], + "expected": { + "compileResult": { + "result": "success", + "isFeatureConstant": true, + "isZoomConstant": true, + "type": "number" + }, + "evaluateResults": [ + 0.5235987755982988 + ] + } +} \ No newline at end of file diff --git a/test/integration/expression-tests/at/basic/test.json b/test/integration/expression-tests/at/basic/test.json new file mode 100644 index 00000000000..6a7b5b0ae45 --- /dev/null +++ b/test/integration/expression-tests/at/basic/test.json @@ -0,0 +1,44 @@ +{ + "expression": [ + "number", + [ + "at", + [ + "json_array", + [ + "get", + [ + "properties" + ], + "arr" + ] + ], + 1 + ] + ], + "evaluate": [ + [ + {}, + { + "properties": { + "arr": [ + 9, + 8, + 7 + ] + } + } + ] + ], + "expected": { + "compileResult": { + "result": "success", + "isFeatureConstant": false, + "isZoomConstant": true, + "type": "number" + }, + "evaluateResults": [ + 8 + ] + } +} \ No newline at end of file diff --git a/test/integration/expression-tests/atan/basic/test.json b/test/integration/expression-tests/atan/basic/test.json new file mode 100644 index 00000000000..b8164eac059 --- /dev/null +++ b/test/integration/expression-tests/atan/basic/test.json @@ -0,0 +1,23 @@ +{ + "expression": [ + "atan", + 1 + ], + "evaluate": [ + [ + {}, + {} + ] + ], + "expected": { + "compileResult": { + "result": "success", + "isFeatureConstant": true, + "isZoomConstant": true, + "type": "number" + }, + "evaluateResults": [ + 0.7853981633974483 + ] + } +} \ No newline at end of file diff --git a/test/integration/expression-tests/boolean/basic/test.json b/test/integration/expression-tests/boolean/basic/test.json new file mode 100644 index 00000000000..b518d61c6f2 --- /dev/null +++ b/test/integration/expression-tests/boolean/basic/test.json @@ -0,0 +1,94 @@ +{ + "expression": [ + "boolean", + [ + "get", + [ + "properties" + ], + "x" + ] + ], + "evaluate": [ + [ + {}, + {} + ], + [ + {}, + { + "properties": { + "x": true + } + } + ], + [ + {}, + { + "properties": { + "x": false + } + } + ], + [ + {}, + { + "properties": { + "x": "" + } + } + ], + [ + {}, + { + "properties": { + "x": "false" + } + } + ], + [ + {}, + { + "properties": { + "x": 0 + } + } + ], + [ + {}, + { + "properties": { + "x": 1 + } + } + ], + [ + {}, + { + "properties": { + "x": null + } + } + ] + ], + "expected": { + "compileResult": { + "result": "success", + "isFeatureConstant": false, + "isZoomConstant": true, + "type": "boolean" + }, + "evaluateResults": [ + { + "error": "ExpressionEvaluationError: Property x not found in object with keys: []" + }, + true, + false, + false, + true, + false, + true, + false + ] + } +} \ No newline at end of file diff --git a/test/integration/expression-tests/case/basic/test.json b/test/integration/expression-tests/case/basic/test.json new file mode 100644 index 00000000000..c3a3f471ba4 --- /dev/null +++ b/test/integration/expression-tests/case/basic/test.json @@ -0,0 +1,83 @@ +{ + "expression": [ + "string", + [ + "case", + [ + "boolean", + [ + "get", + [ + "properties" + ], + "x" + ] + ], + "x", + [ + "boolean", + [ + "get", + [ + "properties" + ], + "y" + ] + ], + "y", + "otherwise" + ] + ], + "evaluate": [ + [ + {}, + { + "properties": { + "x": true, + "y": true + } + } + ], + [ + {}, + { + "properties": { + "x": true, + "y": false + } + } + ], + [ + {}, + { + "properties": { + "x": false, + "y": true + } + } + ], + [ + {}, + { + "properties": { + "x": false, + "y": false + } + } + ] + ], + "expected": { + "compileResult": { + "result": "success", + "isFeatureConstant": false, + "isZoomConstant": true, + "type": "string" + }, + "evaluateResults": [ + "x", + "x", + "y", + "otherwise" + ] + } +} \ No newline at end of file diff --git a/test/integration/expression-tests/concat/basic/test.json b/test/integration/expression-tests/concat/basic/test.json new file mode 100644 index 00000000000..ae27a8a304b --- /dev/null +++ b/test/integration/expression-tests/concat/basic/test.json @@ -0,0 +1,25 @@ +{ + "expression": [ + "concat", + "a", + "b", + "c" + ], + "evaluate": [ + [ + {}, + {} + ] + ], + "expected": { + "compileResult": { + "result": "success", + "isFeatureConstant": true, + "isZoomConstant": true, + "type": "string" + }, + "evaluateResults": [ + "abc" + ] + } +} \ No newline at end of file diff --git a/test/integration/expression-tests/cos/basic/test.json b/test/integration/expression-tests/cos/basic/test.json new file mode 100644 index 00000000000..9f063bc9b58 --- /dev/null +++ b/test/integration/expression-tests/cos/basic/test.json @@ -0,0 +1,23 @@ +{ + "expression": [ + "cos", + 0 + ], + "evaluate": [ + [ + {}, + {} + ] + ], + "expected": { + "compileResult": { + "result": "success", + "isFeatureConstant": true, + "isZoomConstant": true, + "type": "number" + }, + "evaluateResults": [ + 1 + ] + } +} \ No newline at end of file diff --git a/test/integration/expression-tests/divide/basic/test.json b/test/integration/expression-tests/divide/basic/test.json new file mode 100644 index 00000000000..40de5e495b5 --- /dev/null +++ b/test/integration/expression-tests/divide/basic/test.json @@ -0,0 +1,24 @@ +{ + "expression": [ + "/", + 10, + 5 + ], + "evaluate": [ + [ + {}, + {} + ] + ], + "expected": { + "compileResult": { + "result": "success", + "isFeatureConstant": true, + "isZoomConstant": true, + "type": "number" + }, + "evaluateResults": [ + 2 + ] + } +} \ No newline at end of file diff --git a/test/integration/expression-tests/downcase/basic/test.json b/test/integration/expression-tests/downcase/basic/test.json new file mode 100644 index 00000000000..e095e4107aa --- /dev/null +++ b/test/integration/expression-tests/downcase/basic/test.json @@ -0,0 +1,23 @@ +{ + "expression": [ + "downcase", + "StRiNg" + ], + "evaluate": [ + [ + {}, + {} + ] + ], + "expected": { + "compileResult": { + "result": "success", + "isFeatureConstant": true, + "isZoomConstant": true, + "type": "string" + }, + "evaluateResults": [ + "string" + ] + } +} \ No newline at end of file diff --git a/test/integration/expression-tests/e/basic/test.json b/test/integration/expression-tests/e/basic/test.json new file mode 100644 index 00000000000..af04258b28c --- /dev/null +++ b/test/integration/expression-tests/e/basic/test.json @@ -0,0 +1,22 @@ +{ + "expression": [ + "e" + ], + "evaluate": [ + [ + {}, + {} + ] + ], + "expected": { + "compileResult": { + "result": "success", + "isFeatureConstant": true, + "isZoomConstant": true, + "type": "number" + }, + "evaluateResults": [ + 2.718281828459045 + ] + } +} \ No newline at end of file diff --git a/test/integration/expression-tests/equal/mismatch/test.json b/test/integration/expression-tests/equal/mismatch/test.json new file mode 100644 index 00000000000..7ee8389a857 --- /dev/null +++ b/test/integration/expression-tests/equal/mismatch/test.json @@ -0,0 +1,36 @@ +{ + "expression": [ + "==", + [ + "string", + [ + "get", + [ + "properties" + ], + "x" + ] + ], + [ + "number", + [ + "get", + [ + "properties" + ], + "y" + ] + ] + ], + "expected": { + "compileResult": { + "result": "error", + "errors": [ + { + "key": ".2", + "error": "Expected string but found number instead." + } + ] + } + } +} \ No newline at end of file diff --git a/test/integration/expression-tests/equal/number/test.json b/test/integration/expression-tests/equal/number/test.json new file mode 100644 index 00000000000..b42dcb8256d --- /dev/null +++ b/test/integration/expression-tests/equal/number/test.json @@ -0,0 +1,57 @@ +{ + "expression": [ + "==", + [ + "number", + [ + "get", + [ + "properties" + ], + "x" + ] + ], + [ + "number", + [ + "get", + [ + "properties" + ], + "y" + ] + ] + ], + "evaluate": [ + [ + {}, + { + "properties": { + "x": 1, + "y": 1 + } + } + ], + [ + {}, + { + "properties": { + "x": 1, + "y": 2 + } + } + ] + ], + "expected": { + "compileResult": { + "result": "success", + "isFeatureConstant": false, + "isZoomConstant": true, + "type": "boolean" + }, + "evaluateResults": [ + true, + false + ] + } +} \ No newline at end of file diff --git a/test/integration/expression-tests/equal/string/test.json b/test/integration/expression-tests/equal/string/test.json new file mode 100644 index 00000000000..1f25c5fb9e7 --- /dev/null +++ b/test/integration/expression-tests/equal/string/test.json @@ -0,0 +1,57 @@ +{ + "expression": [ + "==", + [ + "string", + [ + "get", + [ + "properties" + ], + "x" + ] + ], + [ + "string", + [ + "get", + [ + "properties" + ], + "y" + ] + ] + ], + "evaluate": [ + [ + {}, + { + "properties": { + "x": 1, + "y": 1 + } + } + ], + [ + {}, + { + "properties": { + "x": 1, + "y": 2 + } + } + ] + ], + "expected": { + "compileResult": { + "result": "success", + "isFeatureConstant": false, + "isZoomConstant": true, + "type": "boolean" + }, + "evaluateResults": [ + true, + false + ] + } +} \ No newline at end of file diff --git a/test/integration/expression-tests/equal/untagged/test.json b/test/integration/expression-tests/equal/untagged/test.json new file mode 100644 index 00000000000..19a51224a14 --- /dev/null +++ b/test/integration/expression-tests/equal/untagged/test.json @@ -0,0 +1,33 @@ +{ + "expression": [ + "==", + [ + "string", + [ + "get", + [ + "properties" + ], + "x" + ] + ], + [ + "get", + [ + "properties" + ], + "y" + ] + ], + "expected": { + "compileResult": { + "result": "error", + "errors": [ + { + "key": ".2", + "error": "Expected string but found Variant> instead." + } + ] + } + } +} \ No newline at end of file diff --git a/test/integration/expression-tests/geometry_type/basic/test.json b/test/integration/expression-tests/geometry_type/basic/test.json new file mode 100644 index 00000000000..32e11431faa --- /dev/null +++ b/test/integration/expression-tests/geometry_type/basic/test.json @@ -0,0 +1,31 @@ +{ + "expression": [ + "geometry_type" + ], + "evaluate": [ + [ + {}, + {} + ], + [ + {}, + { + "geometry": { + "type": "LineString" + } + } + ] + ], + "expected": { + "compileResult": { + "result": "success", + "isFeatureConstant": false, + "isZoomConstant": true, + "type": "string" + }, + "evaluateResults": [ + null, + "LineString" + ] + } +} \ No newline at end of file diff --git a/test/integration/expression-tests/get/basic/test.json b/test/integration/expression-tests/get/basic/test.json new file mode 100644 index 00000000000..8caf3531ae7 --- /dev/null +++ b/test/integration/expression-tests/get/basic/test.json @@ -0,0 +1,40 @@ +{ + "expression": [ + "number", + [ + "get", + [ + "properties" + ], + "x" + ] + ], + "evaluate": [ + [ + {}, + {} + ], + [ + {}, + { + "properties": { + "x": 1 + } + } + ] + ], + "expected": { + "compileResult": { + "result": "success", + "isFeatureConstant": false, + "isZoomConstant": true, + "type": "number" + }, + "evaluateResults": [ + { + "error": "ExpressionEvaluationError: Property x not found in object with keys: []" + }, + 1 + ] + } +} \ No newline at end of file diff --git a/test/integration/expression-tests/greater/number/test.json b/test/integration/expression-tests/greater/number/test.json new file mode 100644 index 00000000000..855dabbbbd9 --- /dev/null +++ b/test/integration/expression-tests/greater/number/test.json @@ -0,0 +1,67 @@ +{ + "expression": [ + ">", + [ + "number", + [ + "get", + [ + "properties" + ], + "x" + ] + ], + [ + "number", + [ + "get", + [ + "properties" + ], + "y" + ] + ] + ], + "evaluate": [ + [ + {}, + { + "properties": { + "x": 1, + "y": 1 + } + } + ], + [ + {}, + { + "properties": { + "x": 1, + "y": 2 + } + } + ], + [ + {}, + { + "properties": { + "x": 2, + "y": 1 + } + } + ] + ], + "expected": { + "compileResult": { + "result": "success", + "isFeatureConstant": false, + "isZoomConstant": true, + "type": "boolean" + }, + "evaluateResults": [ + false, + false, + true + ] + } +} \ No newline at end of file diff --git a/test/integration/expression-tests/greater/string/test.json b/test/integration/expression-tests/greater/string/test.json new file mode 100644 index 00000000000..8d1b7424158 --- /dev/null +++ b/test/integration/expression-tests/greater/string/test.json @@ -0,0 +1,97 @@ +{ + "expression": [ + ">", + [ + "string", + [ + "get", + [ + "properties" + ], + "x" + ] + ], + [ + "string", + [ + "get", + [ + "properties" + ], + "y" + ] + ] + ], + "evaluate": [ + [ + {}, + { + "properties": { + "x": 1, + "y": 1 + } + } + ], + [ + {}, + { + "properties": { + "x": 1, + "y": 2 + } + } + ], + [ + {}, + { + "properties": { + "x": 2, + "y": 1 + } + } + ], + [ + {}, + { + "properties": { + "x": "abc", + "y": "azz" + } + } + ], + [ + {}, + { + "properties": { + "x": "abc", + "y": "aaa" + } + } + ], + [ + {}, + { + "properties": { + "x": "abc", + "y": "abc" + } + } + ] + ], + "expected": { + "compileResult": { + "result": "success", + "isFeatureConstant": false, + "isZoomConstant": true, + "type": "boolean" + }, + "evaluateResults": [ + false, + false, + true, + false, + true, + false + ] + } +} \ No newline at end of file diff --git a/test/integration/expression-tests/greater_or_equal/number/test.json b/test/integration/expression-tests/greater_or_equal/number/test.json new file mode 100644 index 00000000000..d3b7a875513 --- /dev/null +++ b/test/integration/expression-tests/greater_or_equal/number/test.json @@ -0,0 +1,67 @@ +{ + "expression": [ + ">=", + [ + "number", + [ + "get", + [ + "properties" + ], + "x" + ] + ], + [ + "number", + [ + "get", + [ + "properties" + ], + "y" + ] + ] + ], + "evaluate": [ + [ + {}, + { + "properties": { + "x": 1, + "y": 1 + } + } + ], + [ + {}, + { + "properties": { + "x": 1, + "y": 2 + } + } + ], + [ + {}, + { + "properties": { + "x": 2, + "y": 1 + } + } + ] + ], + "expected": { + "compileResult": { + "result": "success", + "isFeatureConstant": false, + "isZoomConstant": true, + "type": "boolean" + }, + "evaluateResults": [ + true, + false, + true + ] + } +} \ No newline at end of file diff --git a/test/integration/expression-tests/greater_or_equal/string/test.json b/test/integration/expression-tests/greater_or_equal/string/test.json new file mode 100644 index 00000000000..084b260ebbd --- /dev/null +++ b/test/integration/expression-tests/greater_or_equal/string/test.json @@ -0,0 +1,97 @@ +{ + "expression": [ + ">=", + [ + "string", + [ + "get", + [ + "properties" + ], + "x" + ] + ], + [ + "string", + [ + "get", + [ + "properties" + ], + "y" + ] + ] + ], + "evaluate": [ + [ + {}, + { + "properties": { + "x": 1, + "y": 1 + } + } + ], + [ + {}, + { + "properties": { + "x": 1, + "y": 2 + } + } + ], + [ + {}, + { + "properties": { + "x": 2, + "y": 1 + } + } + ], + [ + {}, + { + "properties": { + "x": "abc", + "y": "azz" + } + } + ], + [ + {}, + { + "properties": { + "x": "abc", + "y": "aaa" + } + } + ], + [ + {}, + { + "properties": { + "x": "abc", + "y": "abc" + } + } + ] + ], + "expected": { + "compileResult": { + "result": "success", + "isFeatureConstant": false, + "isZoomConstant": true, + "type": "boolean" + }, + "evaluateResults": [ + true, + false, + true, + false, + true, + true + ] + } +} \ No newline at end of file diff --git a/test/integration/expression-tests/has/basic/test.json b/test/integration/expression-tests/has/basic/test.json new file mode 100644 index 00000000000..04d2a85af4f --- /dev/null +++ b/test/integration/expression-tests/has/basic/test.json @@ -0,0 +1,62 @@ +{ + "expression": [ + "has", + [ + "properties" + ], + "x" + ], + "evaluate": [ + [ + {}, + {} + ], + [ + {}, + { + "properties": { + "x": 1 + } + } + ], + [ + {}, + { + "properties": { + "x": 0 + } + } + ], + [ + {}, + { + "properties": { + "x": false + } + } + ], + [ + {}, + { + "properties": { + "x": null + } + } + ] + ], + "expected": { + "compileResult": { + "result": "success", + "isFeatureConstant": false, + "isZoomConstant": true, + "type": "boolean" + }, + "evaluateResults": [ + false, + true, + true, + true, + true + ] + } +} \ No newline at end of file diff --git a/test/integration/expression-tests/id/basic/test.json b/test/integration/expression-tests/id/basic/test.json new file mode 100644 index 00000000000..793be056b3a --- /dev/null +++ b/test/integration/expression-tests/id/basic/test.json @@ -0,0 +1,36 @@ +{ + "expression": [ + "id" + ], + "evaluate": [ + [ + {}, + {} + ], + [ + {}, + { + "id": 1 + } + ], + [ + {}, + { + "id": "one" + } + ] + ], + "expected": { + "compileResult": { + "result": "success", + "isFeatureConstant": false, + "isZoomConstant": true, + "type": "Variant>" + }, + "evaluateResults": [ + null, + 1, + "one" + ] + } +} \ No newline at end of file diff --git a/test/integration/expression-tests/length/string/test.json b/test/integration/expression-tests/length/string/test.json new file mode 100644 index 00000000000..9a7569cdd34 --- /dev/null +++ b/test/integration/expression-tests/length/string/test.json @@ -0,0 +1,36 @@ +{ + "expression": [ + "length", + [ + "string", + [ + "get", + [ + "properties" + ], + "x" + ] + ] + ], + "evaluate": [ + [ + {}, + { + "properties": { + "x": "a string" + } + } + ] + ], + "expected": { + "compileResult": { + "result": "success", + "isFeatureConstant": false, + "isZoomConstant": true, + "type": "number" + }, + "evaluateResults": [ + 8 + ] + } +} \ No newline at end of file diff --git a/test/integration/expression-tests/length/vector/test.json b/test/integration/expression-tests/length/vector/test.json new file mode 100644 index 00000000000..fbb3364887c --- /dev/null +++ b/test/integration/expression-tests/length/vector/test.json @@ -0,0 +1,42 @@ +{ + "expression": [ + "length", + [ + "json_array", + [ + "get", + [ + "properties" + ], + "x" + ] + ] + ], + "evaluate": [ + [ + {}, + { + "properties": { + "x": [ + 1, + 2, + 3, + 4, + 5 + ] + } + } + ] + ], + "expected": { + "compileResult": { + "result": "success", + "isFeatureConstant": false, + "isZoomConstant": true, + "type": "number" + }, + "evaluateResults": [ + 5 + ] + } +} \ No newline at end of file diff --git a/test/integration/expression-tests/less/number/test.json b/test/integration/expression-tests/less/number/test.json new file mode 100644 index 00000000000..eb42d64b503 --- /dev/null +++ b/test/integration/expression-tests/less/number/test.json @@ -0,0 +1,67 @@ +{ + "expression": [ + "<", + [ + "number", + [ + "get", + [ + "properties" + ], + "x" + ] + ], + [ + "number", + [ + "get", + [ + "properties" + ], + "y" + ] + ] + ], + "evaluate": [ + [ + {}, + { + "properties": { + "x": 1, + "y": 1 + } + } + ], + [ + {}, + { + "properties": { + "x": 1, + "y": 2 + } + } + ], + [ + {}, + { + "properties": { + "x": 2, + "y": 1 + } + } + ] + ], + "expected": { + "compileResult": { + "result": "success", + "isFeatureConstant": false, + "isZoomConstant": true, + "type": "boolean" + }, + "evaluateResults": [ + false, + true, + false + ] + } +} \ No newline at end of file diff --git a/test/integration/expression-tests/less/string/test.json b/test/integration/expression-tests/less/string/test.json new file mode 100644 index 00000000000..37099c163c8 --- /dev/null +++ b/test/integration/expression-tests/less/string/test.json @@ -0,0 +1,97 @@ +{ + "expression": [ + "<", + [ + "string", + [ + "get", + [ + "properties" + ], + "x" + ] + ], + [ + "string", + [ + "get", + [ + "properties" + ], + "y" + ] + ] + ], + "evaluate": [ + [ + {}, + { + "properties": { + "x": 1, + "y": 1 + } + } + ], + [ + {}, + { + "properties": { + "x": 1, + "y": 2 + } + } + ], + [ + {}, + { + "properties": { + "x": 2, + "y": 1 + } + } + ], + [ + {}, + { + "properties": { + "x": "abc", + "y": "azz" + } + } + ], + [ + {}, + { + "properties": { + "x": "abc", + "y": "aaa" + } + } + ], + [ + {}, + { + "properties": { + "x": "abc", + "y": "abc" + } + } + ] + ], + "expected": { + "compileResult": { + "result": "success", + "isFeatureConstant": false, + "isZoomConstant": true, + "type": "boolean" + }, + "evaluateResults": [ + false, + true, + false, + true, + false, + false + ] + } +} \ No newline at end of file diff --git a/test/integration/expression-tests/less_or_equal/number/test.json b/test/integration/expression-tests/less_or_equal/number/test.json new file mode 100644 index 00000000000..1bc05a303db --- /dev/null +++ b/test/integration/expression-tests/less_or_equal/number/test.json @@ -0,0 +1,67 @@ +{ + "expression": [ + "<=", + [ + "number", + [ + "get", + [ + "properties" + ], + "x" + ] + ], + [ + "number", + [ + "get", + [ + "properties" + ], + "y" + ] + ] + ], + "evaluate": [ + [ + {}, + { + "properties": { + "x": 1, + "y": 1 + } + } + ], + [ + {}, + { + "properties": { + "x": 1, + "y": 2 + } + } + ], + [ + {}, + { + "properties": { + "x": 2, + "y": 1 + } + } + ] + ], + "expected": { + "compileResult": { + "result": "success", + "isFeatureConstant": false, + "isZoomConstant": true, + "type": "boolean" + }, + "evaluateResults": [ + true, + true, + false + ] + } +} \ No newline at end of file diff --git a/test/integration/expression-tests/less_or_equal/string/test.json b/test/integration/expression-tests/less_or_equal/string/test.json new file mode 100644 index 00000000000..053e0320b9f --- /dev/null +++ b/test/integration/expression-tests/less_or_equal/string/test.json @@ -0,0 +1,97 @@ +{ + "expression": [ + "<=", + [ + "string", + [ + "get", + [ + "properties" + ], + "x" + ] + ], + [ + "string", + [ + "get", + [ + "properties" + ], + "y" + ] + ] + ], + "evaluate": [ + [ + {}, + { + "properties": { + "x": 1, + "y": 1 + } + } + ], + [ + {}, + { + "properties": { + "x": 1, + "y": 2 + } + } + ], + [ + {}, + { + "properties": { + "x": 2, + "y": 1 + } + } + ], + [ + {}, + { + "properties": { + "x": "abc", + "y": "azz" + } + } + ], + [ + {}, + { + "properties": { + "x": "abc", + "y": "aaa" + } + } + ], + [ + {}, + { + "properties": { + "x": "abc", + "y": "abc" + } + } + ] + ], + "expected": { + "compileResult": { + "result": "success", + "isFeatureConstant": false, + "isZoomConstant": true, + "type": "boolean" + }, + "evaluateResults": [ + true, + true, + false, + true, + false, + true + ] + } +} \ No newline at end of file diff --git a/test/integration/expression-tests/literal/string/test.json b/test/integration/expression-tests/literal/string/test.json new file mode 100644 index 00000000000..8b06b88a527 --- /dev/null +++ b/test/integration/expression-tests/literal/string/test.json @@ -0,0 +1,20 @@ +{ + "expression": "ahoy!", + "evaluate": [ + [ + {}, + {} + ] + ], + "expected": { + "compileResult": { + "result": "success", + "isFeatureConstant": true, + "isZoomConstant": true, + "type": "string" + }, + "evaluateResults": [ + "ahoy!" + ] + } +} \ No newline at end of file diff --git a/test/integration/expression-tests/ln/basic/test.json b/test/integration/expression-tests/ln/basic/test.json new file mode 100644 index 00000000000..f6385134c64 --- /dev/null +++ b/test/integration/expression-tests/ln/basic/test.json @@ -0,0 +1,25 @@ +{ + "expression": [ + "ln", + [ + "e" + ] + ], + "evaluate": [ + [ + {}, + {} + ] + ], + "expected": { + "compileResult": { + "result": "success", + "isFeatureConstant": true, + "isZoomConstant": true, + "type": "number" + }, + "evaluateResults": [ + 1 + ] + } +} \ No newline at end of file diff --git a/test/integration/expression-tests/ln2/basic/test.json b/test/integration/expression-tests/ln2/basic/test.json new file mode 100644 index 00000000000..7bc181393ea --- /dev/null +++ b/test/integration/expression-tests/ln2/basic/test.json @@ -0,0 +1,22 @@ +{ + "expression": [ + "ln2" + ], + "evaluate": [ + [ + {}, + {} + ] + ], + "expected": { + "compileResult": { + "result": "success", + "isFeatureConstant": true, + "isZoomConstant": true, + "type": "number" + }, + "evaluateResults": [ + 0.6931471805599453 + ] + } +} \ No newline at end of file diff --git a/test/integration/expression-tests/log10/basic/test.json b/test/integration/expression-tests/log10/basic/test.json new file mode 100644 index 00000000000..9f9c34edc7e --- /dev/null +++ b/test/integration/expression-tests/log10/basic/test.json @@ -0,0 +1,23 @@ +{ + "expression": [ + "log10", + 100 + ], + "evaluate": [ + [ + {}, + {} + ] + ], + "expected": { + "compileResult": { + "result": "success", + "isFeatureConstant": true, + "isZoomConstant": true, + "type": "number" + }, + "evaluateResults": [ + 2 + ] + } +} \ No newline at end of file diff --git a/test/integration/expression-tests/log2/basic/test.json b/test/integration/expression-tests/log2/basic/test.json new file mode 100644 index 00000000000..52403f41519 --- /dev/null +++ b/test/integration/expression-tests/log2/basic/test.json @@ -0,0 +1,23 @@ +{ + "expression": [ + "log2", + 1024 + ], + "evaluate": [ + [ + {}, + {} + ] + ], + "expected": { + "compileResult": { + "result": "success", + "isFeatureConstant": true, + "isZoomConstant": true, + "type": "number" + }, + "evaluateResults": [ + 10 + ] + } +} \ No newline at end of file diff --git a/test/integration/expression-tests/minus/basic/test.json b/test/integration/expression-tests/minus/basic/test.json new file mode 100644 index 00000000000..7da3ec22c6e --- /dev/null +++ b/test/integration/expression-tests/minus/basic/test.json @@ -0,0 +1,24 @@ +{ + "expression": [ + "-", + 5, + 7 + ], + "evaluate": [ + [ + {}, + {} + ] + ], + "expected": { + "compileResult": { + "result": "success", + "isFeatureConstant": true, + "isZoomConstant": true, + "type": "number" + }, + "evaluateResults": [ + -2 + ] + } +} \ No newline at end of file diff --git a/test/integration/expression-tests/mod/basic/test.json b/test/integration/expression-tests/mod/basic/test.json new file mode 100644 index 00000000000..3c45b99e222 --- /dev/null +++ b/test/integration/expression-tests/mod/basic/test.json @@ -0,0 +1,24 @@ +{ + "expression": [ + "%", + 18, + 12 + ], + "evaluate": [ + [ + {}, + {} + ] + ], + "expected": { + "compileResult": { + "result": "success", + "isFeatureConstant": true, + "isZoomConstant": true, + "type": "number" + }, + "evaluateResults": [ + 6 + ] + } +} \ No newline at end of file diff --git a/test/integration/expression-tests/not/basic/test.json b/test/integration/expression-tests/not/basic/test.json new file mode 100644 index 00000000000..e8f7f005308 --- /dev/null +++ b/test/integration/expression-tests/not/basic/test.json @@ -0,0 +1,45 @@ +{ + "expression": [ + "!", + [ + "boolean", + [ + "get", + [ + "properties" + ], + "x" + ] + ] + ], + "evaluate": [ + [ + {}, + { + "properties": { + "x": true + } + } + ], + [ + {}, + { + "properties": { + "x": false + } + } + ] + ], + "expected": { + "compileResult": { + "result": "success", + "isFeatureConstant": false, + "isZoomConstant": true, + "type": "boolean" + }, + "evaluateResults": [ + false, + true + ] + } +} \ No newline at end of file diff --git a/test/integration/expression-tests/not_equal/mismatch/test.json b/test/integration/expression-tests/not_equal/mismatch/test.json new file mode 100644 index 00000000000..17da22bf276 --- /dev/null +++ b/test/integration/expression-tests/not_equal/mismatch/test.json @@ -0,0 +1,36 @@ +{ + "expression": [ + "!=", + [ + "string", + [ + "get", + [ + "properties" + ], + "x" + ] + ], + [ + "number", + [ + "get", + [ + "properties" + ], + "y" + ] + ] + ], + "expected": { + "compileResult": { + "result": "error", + "errors": [ + { + "key": ".2", + "error": "Expected string but found number instead." + } + ] + } + } +} \ No newline at end of file diff --git a/test/integration/expression-tests/not_equal/number/test.json b/test/integration/expression-tests/not_equal/number/test.json new file mode 100644 index 00000000000..1cf8167f46c --- /dev/null +++ b/test/integration/expression-tests/not_equal/number/test.json @@ -0,0 +1,57 @@ +{ + "expression": [ + "!=", + [ + "number", + [ + "get", + [ + "properties" + ], + "x" + ] + ], + [ + "number", + [ + "get", + [ + "properties" + ], + "y" + ] + ] + ], + "evaluate": [ + [ + {}, + { + "properties": { + "x": 1, + "y": 1 + } + } + ], + [ + {}, + { + "properties": { + "x": 1, + "y": 2 + } + } + ] + ], + "expected": { + "compileResult": { + "result": "success", + "isFeatureConstant": false, + "isZoomConstant": true, + "type": "boolean" + }, + "evaluateResults": [ + false, + true + ] + } +} \ No newline at end of file diff --git a/test/integration/expression-tests/not_equal/string/test.json b/test/integration/expression-tests/not_equal/string/test.json new file mode 100644 index 00000000000..f51107c6fa4 --- /dev/null +++ b/test/integration/expression-tests/not_equal/string/test.json @@ -0,0 +1,57 @@ +{ + "expression": [ + "!=", + [ + "string", + [ + "get", + [ + "properties" + ], + "x" + ] + ], + [ + "string", + [ + "get", + [ + "properties" + ], + "y" + ] + ] + ], + "evaluate": [ + [ + {}, + { + "properties": { + "x": 1, + "y": 1 + } + } + ], + [ + {}, + { + "properties": { + "x": 1, + "y": 2 + } + } + ] + ], + "expected": { + "compileResult": { + "result": "success", + "isFeatureConstant": false, + "isZoomConstant": true, + "type": "boolean" + }, + "evaluateResults": [ + false, + true + ] + } +} \ No newline at end of file diff --git a/test/integration/expression-tests/not_equal/untagged/test.json b/test/integration/expression-tests/not_equal/untagged/test.json new file mode 100644 index 00000000000..03d83015485 --- /dev/null +++ b/test/integration/expression-tests/not_equal/untagged/test.json @@ -0,0 +1,33 @@ +{ + "expression": [ + "!=", + [ + "string", + [ + "get", + [ + "properties" + ], + "x" + ] + ], + [ + "get", + [ + "properties" + ], + "y" + ] + ], + "expected": { + "compileResult": { + "result": "error", + "errors": [ + { + "key": ".2", + "error": "Expected string but found Variant> instead." + } + ] + } + } +} \ No newline at end of file diff --git a/test/integration/expression-tests/or/basic/test.json b/test/integration/expression-tests/or/basic/test.json new file mode 100644 index 00000000000..d40d4f5fd22 --- /dev/null +++ b/test/integration/expression-tests/or/basic/test.json @@ -0,0 +1,77 @@ +{ + "expression": [ + "||", + [ + "boolean", + [ + "get", + [ + "properties" + ], + "x" + ] + ], + [ + "boolean", + [ + "get", + [ + "properties" + ], + "y" + ] + ] + ], + "evaluate": [ + [ + {}, + { + "properties": { + "x": true, + "y": true + } + } + ], + [ + {}, + { + "properties": { + "x": true, + "y": false + } + } + ], + [ + {}, + { + "properties": { + "x": false, + "y": true + } + } + ], + [ + {}, + { + "properties": { + "x": false, + "y": false + } + } + ] + ], + "expected": { + "compileResult": { + "result": "success", + "isFeatureConstant": false, + "isZoomConstant": true, + "type": "boolean" + }, + "evaluateResults": [ + true, + true, + true, + false + ] + } +} \ No newline at end of file diff --git a/test/integration/expression-tests/pi/basic/test.json b/test/integration/expression-tests/pi/basic/test.json new file mode 100644 index 00000000000..37aded04968 --- /dev/null +++ b/test/integration/expression-tests/pi/basic/test.json @@ -0,0 +1,22 @@ +{ + "expression": [ + "pi" + ], + "evaluate": [ + [ + {}, + {} + ] + ], + "expected": { + "compileResult": { + "result": "success", + "isFeatureConstant": true, + "isZoomConstant": true, + "type": "number" + }, + "evaluateResults": [ + 3.141592653589793 + ] + } +} \ No newline at end of file diff --git a/test/integration/expression-tests/plus/basic/test.json b/test/integration/expression-tests/plus/basic/test.json new file mode 100644 index 00000000000..04b7948af58 --- /dev/null +++ b/test/integration/expression-tests/plus/basic/test.json @@ -0,0 +1,24 @@ +{ + "expression": [ + "+", + 2, + 3 + ], + "evaluate": [ + [ + {}, + {} + ] + ], + "expected": { + "compileResult": { + "result": "success", + "isFeatureConstant": true, + "isZoomConstant": true, + "type": "number" + }, + "evaluateResults": [ + 5 + ] + } +} \ No newline at end of file diff --git a/test/integration/expression-tests/pow/basic/test.json b/test/integration/expression-tests/pow/basic/test.json new file mode 100644 index 00000000000..2158436e6d2 --- /dev/null +++ b/test/integration/expression-tests/pow/basic/test.json @@ -0,0 +1,46 @@ +{ + "expression": [ + "^", + 4, + [ + "number", + [ + "get", + [ + "properties" + ], + "x" + ] + ] + ], + "evaluate": [ + [ + {}, + { + "properties": { + "x": 2 + } + } + ], + [ + {}, + { + "properties": { + "x": 0.5 + } + } + ] + ], + "expected": { + "compileResult": { + "result": "success", + "isFeatureConstant": false, + "isZoomConstant": true, + "type": "number" + }, + "evaluateResults": [ + 16, + 2 + ] + } +} \ No newline at end of file diff --git a/test/integration/expression-tests/properties/basic/test.json b/test/integration/expression-tests/properties/basic/test.json new file mode 100644 index 00000000000..153df0f7c46 --- /dev/null +++ b/test/integration/expression-tests/properties/basic/test.json @@ -0,0 +1,42 @@ +{ + "expression": [ + "properties" + ], + "evaluate": [ + [ + {}, + {} + ], + [ + {}, + { + "properties": { + "x": 5 + } + } + ], + [ + {}, + { + "properties": "invalid" + } + ] + ], + "expected": { + "compileResult": { + "result": "success", + "isFeatureConstant": false, + "isZoomConstant": true, + "type": "object" + }, + "evaluateResults": [ + {}, + { + "x": 5 + }, + { + "error": "ExpressionEvaluationError: Expected an object" + } + ] + } +} \ No newline at end of file diff --git a/test/integration/expression-tests/results.html.tmpl b/test/integration/expression-tests/results.html.tmpl new file mode 100644 index 00000000000..172e457ff98 --- /dev/null +++ b/test/integration/expression-tests/results.html.tmpl @@ -0,0 +1,19 @@ + + + + + + +<% for (r of results) { %> + + + + +<% } %> +
ActualInfo
<%- r.expression %> +

<%- r.group %>/<%- r.test %>

+
<%- r.difference %>
+
diff --git a/test/integration/expression-tests/sin/basic/test.json b/test/integration/expression-tests/sin/basic/test.json new file mode 100644 index 00000000000..093ca13570c --- /dev/null +++ b/test/integration/expression-tests/sin/basic/test.json @@ -0,0 +1,23 @@ +{ + "expression": [ + "sin", + 0 + ], + "evaluate": [ + [ + {}, + {} + ] + ], + "expected": { + "compileResult": { + "result": "success", + "isFeatureConstant": true, + "isZoomConstant": true, + "type": "number" + }, + "evaluateResults": [ + 0 + ] + } +} \ No newline at end of file diff --git a/test/integration/expression-tests/string/basic/test.json b/test/integration/expression-tests/string/basic/test.json new file mode 100644 index 00000000000..a24e39df21f --- /dev/null +++ b/test/integration/expression-tests/string/basic/test.json @@ -0,0 +1,51 @@ +{ + "expression": [ + "string", + [ + "get", + [ + "properties" + ], + "x" + ] + ], + "evaluate": [ + [ + {}, + { + "properties": { + "x": 1 + } + } + ], + [ + {}, + { + "properties": { + "x": false + } + } + ], + [ + {}, + { + "properties": { + "x": null + } + } + ] + ], + "expected": { + "compileResult": { + "result": "success", + "isFeatureConstant": false, + "isZoomConstant": true, + "type": "string" + }, + "evaluateResults": [ + "1", + "false", + "null" + ] + } +} \ No newline at end of file diff --git a/test/integration/expression-tests/tan/basic/test.json b/test/integration/expression-tests/tan/basic/test.json new file mode 100644 index 00000000000..4a2f0d15b4f --- /dev/null +++ b/test/integration/expression-tests/tan/basic/test.json @@ -0,0 +1,23 @@ +{ + "expression": [ + "tan", + 0.7853981633974483 + ], + "evaluate": [ + [ + {}, + {} + ] + ], + "expected": { + "compileResult": { + "result": "success", + "isFeatureConstant": true, + "isZoomConstant": true, + "type": "number" + }, + "evaluateResults": [ + 0.9999999999999999 + ] + } +} \ No newline at end of file diff --git a/test/integration/expression-tests/times/basic/test.json b/test/integration/expression-tests/times/basic/test.json new file mode 100644 index 00000000000..795cda0bad8 --- /dev/null +++ b/test/integration/expression-tests/times/basic/test.json @@ -0,0 +1,24 @@ +{ + "expression": [ + "*", + 12, + 0.5 + ], + "evaluate": [ + [ + {}, + {} + ] + ], + "expected": { + "compileResult": { + "result": "success", + "isFeatureConstant": true, + "isZoomConstant": true, + "type": "number" + }, + "evaluateResults": [ + 6 + ] + } +} \ No newline at end of file diff --git a/test/integration/expression-tests/typeof/basic/test.json b/test/integration/expression-tests/typeof/basic/test.json new file mode 100644 index 00000000000..d5987791470 --- /dev/null +++ b/test/integration/expression-tests/typeof/basic/test.json @@ -0,0 +1,78 @@ +{ + "expression": [ + "typeof", + [ + "get", + [ + "properties" + ], + "x" + ] + ], + "evaluate": [ + [ + {}, + { + "properties": { + "x": null + } + } + ], + [ + {}, + { + "properties": { + "x": "s" + } + } + ], + [ + {}, + { + "properties": { + "x": 0 + } + } + ], + [ + {}, + { + "properties": { + "x": false + } + } + ], + [ + {}, + { + "properties": { + "x": [] + } + } + ], + [ + {}, + { + "properties": { + "x": {} + } + } + ] + ], + "expected": { + "compileResult": { + "result": "success", + "isFeatureConstant": false, + "isZoomConstant": true, + "type": "string" + }, + "evaluateResults": [ + "Null", + "String", + "Number", + "Boolean", + "Vector", + "Object" + ] + } +} \ No newline at end of file diff --git a/test/integration/expression-tests/upcase/basic/test.json b/test/integration/expression-tests/upcase/basic/test.json new file mode 100644 index 00000000000..2df9a53b813 --- /dev/null +++ b/test/integration/expression-tests/upcase/basic/test.json @@ -0,0 +1,23 @@ +{ + "expression": [ + "upcase", + "string" + ], + "evaluate": [ + [ + {}, + {} + ] + ], + "expected": { + "compileResult": { + "result": "success", + "isFeatureConstant": true, + "isZoomConstant": true, + "type": "string" + }, + "evaluateResults": [ + "STRING" + ] + } +} \ No newline at end of file diff --git a/test/integration/expression-tests/zoom/basic/test.json b/test/integration/expression-tests/zoom/basic/test.json new file mode 100644 index 00000000000..65f53a2daa4 --- /dev/null +++ b/test/integration/expression-tests/zoom/basic/test.json @@ -0,0 +1,24 @@ +{ + "expression": [ + "zoom" + ], + "evaluate": [ + [ + { + "zoom": 5 + }, + {} + ] + ], + "expected": { + "compileResult": { + "result": "success", + "isFeatureConstant": true, + "isZoomConstant": false, + "type": "number" + }, + "evaluateResults": [ + 5 + ] + } +} \ No newline at end of file diff --git a/test/integration/index.js b/test/integration/index.js index 7b6253e9c71..016704a21f2 100644 --- a/test/integration/index.js +++ b/test/integration/index.js @@ -2,3 +2,4 @@ module.exports.render = require('./lib/render'); module.exports.query = require('./lib/query'); +module.exports.expression = require('./lib/expression'); diff --git a/test/integration/lib/expression.js b/test/integration/lib/expression.js new file mode 100644 index 00000000000..01a744c9532 --- /dev/null +++ b/test/integration/lib/expression.js @@ -0,0 +1,97 @@ +'use strict'; + +const path = require('path'); +const harness = require('./harness'); +const diff = require('diff'); +const fs = require('fs'); + +function deepEqual(a, b) { + if (typeof a !== typeof b) + return false; + if (typeof a === 'number') + return Math.abs(a - b) < 1e-10; + if (a === null || b === null || typeof a !== 'object') + return a === b; + + const ka = Object.keys(a); + const kb = Object.keys(b); + + if (ka.length !== kb.length) + return false; + + ka.sort(); + kb.sort(); + + for (let i = 0; i < ka.length; i++) + if (ka[i] !== kb[i] || !deepEqual(a[ka[i]], b[ka[i]])) + return false; + + return true; +} +/** + * Run the expression suite. + * + * @param {string} implementation - identify the implementation under test; used to + * deal with implementation-specific test exclusions and fudge-factors + * @param {Object} options + * @param {Array} [options.tests] - array of test names to run; tests not in the + * array will be skipped + * @param {} runExpressionTest - a function that runs a single expression test fixture + * @returns {undefined} terminates the process when testing is complete + */ +exports.run = function (implementation, options, runExpressionTest) { + const directory = path.join(__dirname, '../expression-tests'); + options.fixtureFilename = 'test.json'; + harness(directory, implementation, options, (fixture, params, done) => { + try { + const result = runExpressionTest(fixture, params); + const dir = path.join(directory, params.group, params.test); + + if (process.env.UPDATE) { + fixture.expected = result; + fs.writeFile(path.join(dir, 'test.json'), JSON.stringify(fixture, null, 2), done); + return; + } + + const expected = fixture.expected; + + const compileOk = deepEqual(result.compileResult, expected.compileResult); + const evalOk = compileOk && deepEqual(result.evaluateResults, expected.evaluateResults); + params.ok = compileOk && evalOk; + + let msg = ''; + if (!compileOk) { + msg += diff.diffJson(expected.compileResult, result.compileResult) + .map((hunk) => { + if (hunk.added) { + return `+ ${hunk.value}`; + } else if (hunk.removed) { + return `- ${hunk.value}`; + } else { + return ` ${hunk.value}`; + } + }) + .join(''); + } + if (compileOk && !evalOk) { + msg += expected.evaluateResults.map((expectedOutput, i) => { + if (!deepEqual(expectedOutput, result.evaluateResults[i])) { + return `f(${JSON.stringify(fixture.evaluate[i])})\nExpected: ${JSON.stringify(expectedOutput)}\nActual: ${JSON.stringify(result.evaluateResults[i])}`; + } + return false; + }) + .filter(Boolean) + .join('\n'); + } + + params.difference = msg; + if (msg) { console.log(msg); } + + params.expression = JSON.stringify(fixture.expression, null, 2); + + done(); + } catch (e) { + done(e); + } + }); +}; diff --git a/test/integration/lib/harness.js b/test/integration/lib/harness.js index d544dd17185..cb38f8b1f98 100644 --- a/test/integration/lib/harness.js +++ b/test/integration/lib/harness.js @@ -14,6 +14,8 @@ module.exports = function (directory, implementation, options, run) { const tests = options.tests || []; + const fixtureFilename = options.fixtureFilename || 'style.json'; + function shouldRunTest(group, test) { if (tests.length === 0) return true; @@ -44,14 +46,14 @@ module.exports = function (directory, implementation, options, run) { return; try { - if (!fs.lstatSync(path.join(directory, group, test, 'style.json')).isFile()) + if (!fs.lstatSync(path.join(directory, group, test, fixtureFilename)).isFile()) return; } catch (err) { - console.log(colors.blue(`* omitting ${group} ${test} due to missing style`)); + console.log(colors.blue(`* omitting ${group} ${test} due to missing ${fixtureFilename}`)); return; } - const style = require(path.join(directory, group, test, 'style.json')); + const style = require(path.join(directory, group, test, fixtureFilename)); server.localizeURLs(style); @@ -99,6 +101,7 @@ module.exports = function (directory, implementation, options, run) { } else if (!params.ok) { params.color = 'red'; console.log(colors.red(`* failed ${params.group} ${params.test}`)); + if (process.env.SINGLE_ERROR) { process.exit(1); } } else { params.color = 'green'; console.log(colors.green(`* passed ${params.group} ${params.test}`));