Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replace whitelist by allowlist in parser-tests #11727

Merged
merged 1 commit into from Jun 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 6 additions & 6 deletions Makefile
Expand Up @@ -172,8 +172,8 @@ test-flow:
test-flow-ci: build-bundle-ci bootstrap-flow
$(MAKE) test-flow

test-flow-update-whitelist:
$(NODE) scripts/parser-tests/flow --update-whitelist
test-flow-update-allowlist:
$(NODE) scripts/parser-tests/flow --update-allowlist

bootstrap-typescript:
rm -rf ./build/typescript
Expand All @@ -187,8 +187,8 @@ test-typescript:
test-typescript-ci: build-bundle-ci bootstrap-typescript
$(MAKE) test-typescript

test-typescript-update-whitelist:
$(NODE) scripts/parser-tests/typescript --update-whitelist
test-typescript-update-allowlist:
$(NODE) scripts/parser-tests/typescript --update-allowlist

bootstrap-test262:
rm -rf build/test262
Expand All @@ -202,8 +202,8 @@ test-test262:
test-test262-ci: build-bundle-ci bootstrap-test262
$(MAKE) test-test262

test-test262-update-whitelist:
$(NODE) scripts/parser-tests/test262 --update-whitelist
test-test262-update-allowlist:
$(NODE) scripts/parser-tests/test262 --update-allowlist

# Does not work on Windows
clone-license:
Expand Down
4 changes: 2 additions & 2 deletions scripts/parser-tests/flow/index.js
Expand Up @@ -89,8 +89,8 @@ async function* loadTests(root) {

const runner = new TestRunner({
testDir: path.join(__dirname, "../../../build/flow/src/parser/test/flow"),
whitelist: path.join(__dirname, "whitelist.txt"),
shouldUpdate: process.argv.includes("--update-whitelist"),
allowlist: path.join(__dirname, "allowlist.txt"),
shouldUpdate: process.argv.includes("--update-allowlist"),

async *getTests() {
for await (const test of loadTests(this.testDir)) {
Expand Down
4 changes: 2 additions & 2 deletions scripts/parser-tests/test262/index.js
Expand Up @@ -148,9 +148,9 @@ function* getPlugins(features) {

const runner = new TestRunner({
testDir: path.join(__dirname, "../../../build/test262"),
whitelist: path.join(__dirname, "whitelist.txt"),
allowlist: path.join(__dirname, "allowlist.txt"),
logInterval: 500,
shouldUpdate: process.argv.includes("--update-whitelist"),
shouldUpdate: process.argv.includes("--update-allowlist"),

async *getTests() {
const stream = new TestStream(this.testDir, {
Expand Down
4 changes: 2 additions & 2 deletions scripts/parser-tests/typescript/index.js
Expand Up @@ -45,9 +45,9 @@ async function baselineContainsParserErrorCodes(testName) {

const runner = new TestRunner({
testDir: path.join(TSTestsPath, "./cases/compiler"),
whitelist: path.join(__dirname, "whitelist.txt"),
allowlist: path.join(__dirname, "allowlist.txt"),
logInterval: 50,
shouldUpdate: process.argv.includes("--update-whitelist"),
shouldUpdate: process.argv.includes("--update-allowlist"),

async *getTests() {
for await (const test of loadTests(this.testDir)) {
Expand Down
52 changes: 26 additions & 26 deletions scripts/parser-tests/utils/parser-test-runner.js
Expand Up @@ -9,22 +9,22 @@ const dot = chalk.gray(".");
class TestRunner {
constructor({
testDir,
whitelist,
allowlist,
logInterval = 1,
shouldUpdate,
getTests,
parse = this.parse,
}) {
this.testDir = testDir;
this.whitelist = whitelist;
this.allowlist = allowlist;
this.logInterval = logInterval;
this.shouldUpdate = shouldUpdate;
this.getTests = getTests;
this.parse = parse;
}

async run() {
const whitelistP = this.getWhitelist();
const allowlistP = this.getAllowlist();

console.log(`Now running tests...`);

Expand All @@ -35,7 +35,7 @@ class TestRunner {
}
process.stdout.write("\n");

const summary = this.interpret(results, await whitelistP);
const summary = this.interpret(results, await allowlistP);

await this.output(summary);
}
Expand Down Expand Up @@ -66,8 +66,8 @@ class TestRunner {
});
}

async getWhitelist() {
const contents = await fs.readFile(this.whitelist, "utf-8");
async getAllowlist() {
const contents = await fs.readFile(this.allowlist, "utf-8");
const table = new Set();

for (const line of contents.split("\n")) {
Expand All @@ -78,8 +78,8 @@ class TestRunner {
return table;
}

async updateWhitelist(summary) {
const contents = await fs.readFile(this.whitelist, "utf-8");
async updateAllowlist(summary) {
const contents = await fs.readFile(this.allowlist, "utf-8");

const toRemove = summary.disallowed.success
.concat(summary.disallowed.failure)
Expand All @@ -99,10 +99,10 @@ class TestRunner {

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 = {
passed: true,
allowed: {
Expand All @@ -123,24 +123,24 @@ class TestRunner {

results.forEach(function (result) {
let classification, isAllowed;
const inWhitelist = whitelist.has(result.id);
whitelist.delete(result.id);
const inAllowlist = allowlist.has(result.id);
allowlist.delete(result.id);

if (!result.expectedError) {
if (!result.actualError) {
classification = "success";
isAllowed = !inWhitelist;
isAllowed = !inAllowlist;
} else {
classification = "falseNegative";
isAllowed = inWhitelist;
isAllowed = inAllowlist;
}
} else {
if (!result.actualError) {
classification = "falsePositive";
isAllowed = inWhitelist;
isAllowed = inAllowlist;
} else {
classification = "failure";
isAllowed = !inWhitelist;
isAllowed = !inAllowlist;
}
}

Expand All @@ -150,7 +150,7 @@ class TestRunner {
);
});

summary.unrecognized = Array.from(whitelist);
summary.unrecognized = Array.from(allowlist);
summary.passed = !!summary.passed && summary.unrecognized.length === 0;

return summary;
Expand All @@ -163,10 +163,10 @@ class TestRunner {
" invalid programs produced a parsing error",
summary.allowed.falsePositive.length +
" invalid programs did not produce a parsing error" +
" (and allowed by the whitelist file)",
" (and allowed by the allowlist file)",
summary.allowed.falseNegative.length +
" valid programs produced a parsing error" +
" (and allowed by the whitelist file)",
" (and allowed by the allowlist file)",
];
const badnews = [];
const badnewsDetails = [];
Expand All @@ -176,29 +176,29 @@ class TestRunner {
tests: summary.disallowed.success,
label:
"valid programs parsed without error" +
" (in violation of the whitelist file)",
" (in violation of the allowlist file)",
},
{
tests: summary.disallowed.failure,
label:
"invalid programs produced a parsing error" +
" (in violation of the whitelist file)",
" (in violation of the allowlist file)",
},
{
tests: summary.disallowed.falsePositive,
label:
"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,
label:
"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,
label: "non-existent programs specified in the whitelist file",
label: "non-existent programs specified in the allowlist file",
},
].forEach(function ({ tests, label }) {
if (!tests.length) {
Expand All @@ -225,9 +225,9 @@ class TestRunner {
}

if (this.shouldUpdate) {
await this.updateWhitelist(summary);
await this.updateAllowlist(summary);
console.log("");
console.log("Whitelist file updated.");
console.log("Allowlist file updated.");
} else {
process.exitCode = summary.passed ? 0 : 1;
}
Expand Down