replace whitelist by allowlist in parser-tests (#11727)

This commit is contained in:
Huáng Jùnliàng 2020-06-17 15:32:46 -04:00 committed by GitHub
parent fd3c76941e
commit e498bee10f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 38 additions and 38 deletions

View File

@ -172,8 +172,8 @@ test-flow:
test-flow-ci: build-bundle-ci bootstrap-flow test-flow-ci: build-bundle-ci bootstrap-flow
$(MAKE) test-flow $(MAKE) test-flow
test-flow-update-whitelist: test-flow-update-allowlist:
$(NODE) scripts/parser-tests/flow --update-whitelist $(NODE) scripts/parser-tests/flow --update-allowlist
bootstrap-typescript: bootstrap-typescript:
rm -rf ./build/typescript rm -rf ./build/typescript
@ -187,8 +187,8 @@ test-typescript:
test-typescript-ci: build-bundle-ci bootstrap-typescript test-typescript-ci: build-bundle-ci bootstrap-typescript
$(MAKE) test-typescript $(MAKE) test-typescript
test-typescript-update-whitelist: test-typescript-update-allowlist:
$(NODE) scripts/parser-tests/typescript --update-whitelist $(NODE) scripts/parser-tests/typescript --update-allowlist
bootstrap-test262: bootstrap-test262:
rm -rf build/test262 rm -rf build/test262
@ -202,8 +202,8 @@ test-test262:
test-test262-ci: build-bundle-ci bootstrap-test262 test-test262-ci: build-bundle-ci bootstrap-test262
$(MAKE) test-test262 $(MAKE) test-test262
test-test262-update-whitelist: test-test262-update-allowlist:
$(NODE) scripts/parser-tests/test262 --update-whitelist $(NODE) scripts/parser-tests/test262 --update-allowlist
# Does not work on Windows # Does not work on Windows
clone-license: clone-license:

View File

@ -89,8 +89,8 @@ async function* loadTests(root) {
const runner = new TestRunner({ const runner = new TestRunner({
testDir: path.join(__dirname, "../../../build/flow/src/parser/test/flow"), testDir: path.join(__dirname, "../../../build/flow/src/parser/test/flow"),
whitelist: path.join(__dirname, "whitelist.txt"), allowlist: path.join(__dirname, "allowlist.txt"),
shouldUpdate: process.argv.includes("--update-whitelist"), shouldUpdate: process.argv.includes("--update-allowlist"),
async *getTests() { async *getTests() {
for await (const test of loadTests(this.testDir)) { for await (const test of loadTests(this.testDir)) {

View File

@ -148,9 +148,9 @@ function* getPlugins(features) {
const runner = new TestRunner({ const runner = new TestRunner({
testDir: path.join(__dirname, "../../../build/test262"), testDir: path.join(__dirname, "../../../build/test262"),
whitelist: path.join(__dirname, "whitelist.txt"), allowlist: path.join(__dirname, "allowlist.txt"),
logInterval: 500, logInterval: 500,
shouldUpdate: process.argv.includes("--update-whitelist"), shouldUpdate: process.argv.includes("--update-allowlist"),
async *getTests() { async *getTests() {
const stream = new TestStream(this.testDir, { const stream = new TestStream(this.testDir, {

View File

@ -45,9 +45,9 @@ async function baselineContainsParserErrorCodes(testName) {
const runner = new TestRunner({ const runner = new TestRunner({
testDir: path.join(TSTestsPath, "./cases/compiler"), testDir: path.join(TSTestsPath, "./cases/compiler"),
whitelist: path.join(__dirname, "whitelist.txt"), allowlist: path.join(__dirname, "allowlist.txt"),
logInterval: 50, logInterval: 50,
shouldUpdate: process.argv.includes("--update-whitelist"), shouldUpdate: process.argv.includes("--update-allowlist"),
async *getTests() { async *getTests() {
for await (const test of loadTests(this.testDir)) { for await (const test of loadTests(this.testDir)) {

View File

@ -9,14 +9,14 @@ const dot = chalk.gray(".");
class TestRunner { class TestRunner {
constructor({ constructor({
testDir, testDir,
whitelist, allowlist,
logInterval = 1, logInterval = 1,
shouldUpdate, shouldUpdate,
getTests, getTests,
parse = this.parse, parse = this.parse,
}) { }) {
this.testDir = testDir; this.testDir = testDir;
this.whitelist = whitelist; this.allowlist = allowlist;
this.logInterval = logInterval; this.logInterval = logInterval;
this.shouldUpdate = shouldUpdate; this.shouldUpdate = shouldUpdate;
this.getTests = getTests; this.getTests = getTests;
@ -24,7 +24,7 @@ class TestRunner {
} }
async run() { async run() {
const whitelistP = this.getWhitelist(); const allowlistP = this.getAllowlist();
console.log(`Now running tests...`); console.log(`Now running tests...`);
@ -35,7 +35,7 @@ class TestRunner {
} }
process.stdout.write("\n"); process.stdout.write("\n");
const summary = this.interpret(results, await whitelistP); const summary = this.interpret(results, await allowlistP);
await this.output(summary); await this.output(summary);
} }
@ -66,8 +66,8 @@ class TestRunner {
}); });
} }
async getWhitelist() { async getAllowlist() {
const contents = await fs.readFile(this.whitelist, "utf-8"); const contents = await fs.readFile(this.allowlist, "utf-8");
const table = new Set(); const table = new Set();
for (const line of contents.split("\n")) { for (const line of contents.split("\n")) {
@ -78,8 +78,8 @@ class TestRunner {
return table; return table;
} }
async updateWhitelist(summary) { async updateAllowlist(summary) {
const contents = await fs.readFile(this.whitelist, "utf-8"); const contents = await fs.readFile(this.allowlist, "utf-8");
const toRemove = summary.disallowed.success const toRemove = summary.disallowed.success
.concat(summary.disallowed.failure) .concat(summary.disallowed.failure)
@ -99,10 +99,10 @@ class TestRunner {
updated.sort(); updated.sort();
await fs.writeFile(this.whitelist, updated.join("\n") + "\n", "utf8"); await fs.writeFile(this.allowlist, updated.join("\n") + "\n", "utf8");
} }
interpret(results, whitelist) { interpret(results, allowlist) {
const summary = { const summary = {
passed: true, passed: true,
allowed: { allowed: {
@ -123,24 +123,24 @@ class TestRunner {
results.forEach(function (result) { results.forEach(function (result) {
let classification, isAllowed; let classification, isAllowed;
const inWhitelist = whitelist.has(result.id); const inAllowlist = allowlist.has(result.id);
whitelist.delete(result.id); allowlist.delete(result.id);
if (!result.expectedError) { if (!result.expectedError) {
if (!result.actualError) { if (!result.actualError) {
classification = "success"; classification = "success";
isAllowed = !inWhitelist; isAllowed = !inAllowlist;
} else { } else {
classification = "falseNegative"; classification = "falseNegative";
isAllowed = inWhitelist; isAllowed = inAllowlist;
} }
} else { } else {
if (!result.actualError) { if (!result.actualError) {
classification = "falsePositive"; classification = "falsePositive";
isAllowed = inWhitelist; isAllowed = inAllowlist;
} else { } else {
classification = "failure"; classification = "failure";
isAllowed = !inWhitelist; isAllowed = !inAllowlist;
} }
} }
@ -150,7 +150,7 @@ class TestRunner {
); );
}); });
summary.unrecognized = Array.from(whitelist); summary.unrecognized = Array.from(allowlist);
summary.passed = !!summary.passed && summary.unrecognized.length === 0; summary.passed = !!summary.passed && summary.unrecognized.length === 0;
return summary; return summary;
@ -163,10 +163,10 @@ class TestRunner {
" invalid programs produced a parsing error", " invalid programs produced a parsing error",
summary.allowed.falsePositive.length + summary.allowed.falsePositive.length +
" invalid programs did not produce a parsing error" + " invalid programs did not produce a parsing error" +
" (and allowed by the whitelist file)", " (and allowed by the allowlist file)",
summary.allowed.falseNegative.length + summary.allowed.falseNegative.length +
" valid programs produced a parsing error" + " valid programs produced a parsing error" +
" (and allowed by the whitelist file)", " (and allowed by the allowlist file)",
]; ];
const badnews = []; const badnews = [];
const badnewsDetails = []; const badnewsDetails = [];
@ -176,29 +176,29 @@ class TestRunner {
tests: summary.disallowed.success, tests: summary.disallowed.success,
label: label:
"valid programs parsed without error" + "valid programs parsed without error" +
" (in violation of the whitelist file)", " (in violation of the allowlist file)",
}, },
{ {
tests: summary.disallowed.failure, tests: summary.disallowed.failure,
label: label:
"invalid programs produced a parsing error" + "invalid programs produced a parsing error" +
" (in violation of the whitelist file)", " (in violation of the allowlist file)",
}, },
{ {
tests: summary.disallowed.falsePositive, tests: summary.disallowed.falsePositive,
label: label:
"invalid programs did not produce a parsing error" + "invalid programs did not produce a parsing error" +
" (without a corresponding entry in the whitelist file)", " (without a corresponding entry in the allowlist file)",
}, },
{ {
tests: summary.disallowed.falseNegative, tests: summary.disallowed.falseNegative,
label: label:
"valid programs produced a parsing error" + "valid programs produced a parsing error" +
" (without a corresponding entry in the whitelist file)", " (without a corresponding entry in the allowlist file)",
}, },
{ {
tests: summary.unrecognized, tests: summary.unrecognized,
label: "non-existent programs specified in the whitelist file", label: "non-existent programs specified in the allowlist file",
}, },
].forEach(function ({ tests, label }) { ].forEach(function ({ tests, label }) {
if (!tests.length) { if (!tests.length) {
@ -225,9 +225,9 @@ class TestRunner {
} }
if (this.shouldUpdate) { if (this.shouldUpdate) {
await this.updateWhitelist(summary); await this.updateAllowlist(summary);
console.log(""); console.log("");
console.log("Whitelist file updated."); console.log("Allowlist file updated.");
} else { } else {
process.exitCode = summary.passed ? 0 : 1; process.exitCode = summary.passed ? 0 : 1;
} }