Skip to content

Commit c7da82a

Browse files
committed
In jones-test, add a feature to disable tests.
In jones-ndb, disable some tests in the composition suite that are known to fail because of features that have not been implemented.
1 parent 95fa1f9 commit c7da82a

File tree

6 files changed

+99
-18
lines changed

6 files changed

+99
-18
lines changed

jones-ndb/test/disabled-tests.js

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
Copyright (c) 2013, 2018, Oracle and/or its affiliates. All rights
3+
reserved.
4+
5+
This program is free software; you can redistribute it and/or
6+
modify it under the terms of the GNU General Public License
7+
as published by the Free Software Foundation; version 2 of
8+
the License.
9+
10+
This program is distributed in the hope that it will be useful,
11+
but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
GNU General Public License for more details.
14+
15+
You should have received a copy of the GNU General Public License
16+
along with this program; if not, write to the Free Software
17+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18+
02110-1301 USA
19+
*/
20+
21+
module.exports = function(driver) {
22+
driver.disableTest("composition", "QueryExtraProjectionTest.js", /.*/);
23+
driver.disableTest("composition", "QueryScanProjectionTest.js", /.*/);
24+
};
25+
26+

jones-ndb/test/driver.js

+12-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
/*
2-
Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved.
2+
Copyright (c) 2013, 2018, Oracle and/or its affiliates. All rights reserved.
3+
4+
This program is free software; you can redistribute it and/or
5+
modify it under the terms of the GNU General Public License
6+
as published by the Free Software Foundation; version 2 of
7+
the License.
38
49
This program is free software; you can redistribute it and/or modify
510
it under the terms of the GNU General Public License, version 2.0,
@@ -40,9 +45,14 @@ driver.name = "ndb";
4045
global.test_conn_properties = properties;
4146
global.adapter = "ndb";
4247

43-
/* Find and run all tests */
48+
/* Find all tests */
4449
driver.addSuitesFromDirectory(jones.fs.suites_dir);
4550
driver.addSuitesFromDirectory(jonesMysql.config.suites_dir);
4651
driver.addSuitesFromDirectory(jonesNdb.config.suites_dir);
52+
53+
/* Disable some tests */
54+
driver.disableTestsFromFile(jonesNdb.config.suites_dir, "disabled-tests.js");
55+
56+
/* Run tests */
4757
driver.runAllTests();
4858

jones-test/API-Documentation/Driver.md

+16
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,22 @@ function addSuiteFromFile(suitename, filename);
9393
function addSuitesFromDirectory(directory);
9494
```
9595

96+
### Disabling tests
97+
```JavaScript
98+
/* In file testFileName in suite suiteName,
99+
disable all tests matching testNamePattern (which must be a RegExp)
100+
*/
101+
function disableTest(suiteName, testFileName, testNamePattern);
102+
103+
104+
/* Specify disabled tests in a file.
105+
The file is a JavaScript source file read using require().
106+
It should export a single function which calls driver.disableTest()
107+
for each test to be disabled.
108+
*/
109+
function disableTestsFromFile(directoryName, fileName);
110+
```
111+
96112

97113
### Creating Lint Tests
98114
```JavaScript

jones-test/lib/Driver.js

+15-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (c) 2012, 2015 Oracle and/or its affiliates. All rights
2+
Copyright (c) 2012, 2018 Oracle and/or its affiliates. All rights
33
reserved.
44
55
This program is free software; you can redistribute it and/or
@@ -160,6 +160,20 @@ Driver.prototype.listSuites = function() {
160160
});
161161
};
162162

163+
Driver.prototype.disableTest = function(suiteName, fileName, testNamePattern) {
164+
this.suites.forEach(function(s) {
165+
if(s.name == suiteName) {
166+
s.disableTest(fileName, testNamePattern);
167+
}
168+
});
169+
};
170+
171+
Driver.prototype.disableTestsFromFile = function(dir, f) {
172+
var file = path.join(dir, f);
173+
var disablerFunction = require(file);
174+
disablerFunction(this);
175+
};
176+
163177
Driver.prototype.testCompleted = function(testCase) {
164178
var suite = testCase.suite;
165179
if (suite.testCompleted(testCase)) {

jones-test/lib/Suite.js

+22-14
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
/*
2-
Copyright (c) 2012, 2015 Oracle and/or its affiliates. All rights
1+
/*
2+
Copyright (c) 2012, 2018 Oracle and/or its affiliates. All rights
33
reserved.
44
55
This program is free software; you can redistribute it and/or
@@ -37,6 +37,7 @@ function Suite(driver, name, suiteDir) {
3737
this.path = "";
3838

3939
this.tests = [];
40+
this.disabledTests = {};
4041
this.smokeTest = {};
4142
this.smokeTestHasFailed = null;
4243
this.serialTests = [];
@@ -63,16 +64,23 @@ Suite.prototype.addTest = function(filename, test) {
6364
test.filename = path.resolve(this.path, filename);
6465
test.suite = this;
6566
test.reset();
66-
this.tests.push(test); // should check if test has been disabled
67+
this.tests.push(test);
68+
if(this.disabledTests[filename] &&
69+
this.disabledTests[filename].test(test.name))
70+
test.enabled = false;
71+
};
72+
73+
Suite.prototype.disableTest = function(fileName, testNamePattern) {
74+
this.disabledTests[fileName] = testNamePattern;
6775
};
6876

69-
/* addTestsFromFile(f, onlyTests)
70-
f is a fully resolved pathname
71-
onlyTests is a string containing a comma separated list of
77+
/* addTestsFromFile(fileName, onlyTests)
78+
onlyTests is a string containing a comma separated list of
7279
test numbers. If set, only those elements of the test array are added.
7380
*/
74-
Suite.prototype.addTestsFromFile = function(f, onlyTests) {
75-
var t, i, j, k, testList, testHash;
81+
Suite.prototype.addTestsFromFile = function(fileName, onlyTests) {
82+
var f, t, i, j, k, testList, testHash;
83+
f = path.join(this.path, fileName);
7684
if(onlyTests) {
7785
onlyTests = String(onlyTests);
7886
testList = onlyTests.split(",");
@@ -82,17 +90,17 @@ Suite.prototype.addTestsFromFile = function(f, onlyTests) {
8290
testHash[k] = 1;
8391
}
8492
}
85-
if(re_matching_test_case.test(f)) {
93+
if(re_matching_test_case.test(fileName)) {
8694
t = require(f);
8795
if(typeof(t.tests) === 'object' && t.tests instanceof Array) {
8896
for(j = 0 ; j < t.tests.length ; j++) {
8997
if(onlyTests === null || testHash[j] === 1) {
90-
this.addTest(f, t.tests[j]);
98+
this.addTest(fileName, t.tests[j]);
9199
}
92100
}
93101
}
94102
else if(typeof(t.isTest) === 'function' && t.isTest()) {
95-
this.addTest(f, t);
103+
this.addTest(fileName, t);
96104
}
97105
else {
98106
console.log("Warning: " + f + " does not export a Test.");
@@ -110,17 +118,17 @@ Suite.prototype.createTests = function() {
110118
var testFile = this.path;
111119
this.path = path.dirname(testFile);
112120
try {
113-
this.addTestsFromFile(path.join(this.path, "SmokeTest.js"), null);
121+
this.addTestsFromFile("SmokeTest.js", null);
114122
} catch(ignore) {}
115123
this.addTestsFromFile(testFile, this.driver.testInFile);
116124
try {
117-
this.addTestsFromFile(path.join(this.path, "ClearSmokeTest.js"), null);
125+
this.addTestsFromFile("ClearSmokeTest.js", null);
118126
} catch(ignore) {}
119127
}
120128
else if(stat.isDirectory()) {
121129
var files = fs.readdirSync(this.path);
122130
for(i = 0; i < files.length ; i++) {
123-
this.addTestsFromFile(path.join(this.path, files[i]), null);
131+
this.addTestsFromFile(files[i], null);
124132
}
125133
}
126134
}

jones-test/lib/Test.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (c) 2012, 2015 Oracle and/or its affiliates. All rights
2+
Copyright (c) 2012, 2018 Oracle and/or its affiliates. All rights
33
reserved.
44
55
This program is free software; you can redistribute it and/or
@@ -37,11 +37,18 @@ function Test() {
3737
this.failed = null; // will be set to true by fail(), or false by pass()
3838
this.skipped = false;
3939
this.result = null; // will be set by Test.test()
40+
this.enabled = true;
4041
}
4142

4243
Test.prototype.test = function(result) {
4344
var runReturnCode;
4445
this.result = result;
46+
47+
if(! this.enabled) {
48+
this.result.skipNotStarted(this, "disabled");
49+
return;
50+
}
51+
4552
result.startTest(this);
4653

4754
udebug.log("Starting test", this.name);

0 commit comments

Comments
 (0)