Skip to content

Commit

Permalink
Write test to verify that each rule corresponds to a rule test (palan…
Browse files Browse the repository at this point in the history
  • Loading branch information
nchen63 authored Jan 26, 2017
1 parent 7cb4a98 commit 1404880
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion test/ruleLoaderTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@
* limitations under the License.
*/

import {loadRules} from "./lint";
import * as diff from "diff";
import * as fs from "fs";
import * as path from "path";
import { camelize } from "../src/utils";
import { loadRules } from "./lint";

describe("Rule Loader", () => {
const RULES_DIRECTORY = "build/src/rules";
Expand Down Expand Up @@ -65,4 +69,32 @@ describe("Rule Loader", () => {
const rules = loadRules(validConfiguration, {}, RULES_DIRECTORY, true);
assert.equal(rules.length, 1);
});

it("tests every rule", () => {
const rulesDir = "src/rules";
const testsDir = "test/rules";
const rules = fs.readdirSync(rulesDir)
.filter((file) => /Rule.ts$/.test(file))
.map((file) => file.substr(0, file.length - "Rule.ts".length))
.sort()
.join("\n");
const tests = fs.readdirSync(testsDir)
.filter((file) => !file.startsWith("_") && fs.statSync(path.join(testsDir, file)).isDirectory())
.map(camelize)
.sort()
.join("\n");
const diffResults = diff.diffLines(rules, tests);
let testFailed = false;
for (const result of diffResults) {
if (result.added) {
console.warn("Test has no matching rule: " + result.value);
testFailed = true;
} else if (result.removed) {
console.warn("Missing test: " + result.value);
testFailed = true;
}
}

assert.isFalse(testFailed, "List of rules doesn't match list of tests");
});
});
File renamed without changes.
File renamed without changes.

0 comments on commit 1404880

Please sign in to comment.