diff --git a/src/test.ts b/src/test.ts index 9955787f172..3bac7fde607 100644 --- a/src/test.ts +++ b/src/test.ts @@ -39,9 +39,9 @@ export interface TestResult { }; } -export function runTest(testDirectory: string): TestResult { +export function runTest(testDirectory: string, rulesDirectory?: string | string[]): TestResult { const filesToLint = glob.sync(path.join(testDirectory, `**/*${FILE_EXTENSION}`)); - const tslintConfig = JSON.parse(fs.readFileSync(path.join(testDirectory, "tslint.json"), "utf8")); + const tslintConfig = Linter.findConfiguration(path.join(testDirectory, "tslint.json"), null); const results: TestResult = { directory: testDirectory, results: {} }; for (const fileToLint of filesToLint) { @@ -54,7 +54,7 @@ export function runTest(testDirectory: string): TestResult { configuration: tslintConfig, formatter: "prose", formattersDirectory: "", - rulesDirectory: "", + rulesDirectory, }; const linter = new Linter(fileBasename, fileTextWithoutMarkup, lintOptions); const errorsFromLinter: LintError[] = linter.lint().failures.map((failure) => { diff --git a/src/tslint-cli.ts b/src/tslint-cli.ts index 9c0430bd993..3851d26c63a 100644 --- a/src/tslint-cli.ts +++ b/src/tslint-cli.ts @@ -114,7 +114,7 @@ if (argv.i != null) { } if (argv.test != null) { - const results = runTest(argv.test); + const results = runTest(argv.test, argv.r); const didAllTestsPass = consoleTestResultHandler(results); process.exit(didAllTestsPass ? 0 : 1); } diff --git a/test/check-bin.sh b/test/check-bin.sh index 254e0658ad0..07c65f364ec 100755 --- a/test/check-bin.sh +++ b/test/check-bin.sh @@ -101,6 +101,13 @@ expectOut $? 0 "tslint --test did not exit correctly for a passing test" ./bin/tslint --test test/files/incorrect-rule-test expectOut $? 1 "tslint --test did not exit correctly for a failing test" +# ensure --test command works correctly with custom rules +./bin/tslint --test test/files/custom-rule-rule-test +expectOut $? 0 "tslint --test did not exit correctly for a passing test with custom rules" + +./bin/tslint -r test/files/custom-rules-2 --test test/files/custom-rule-cli-rule-test +expectOut $? 0 "tslint --test did not exit correctly for a passing test with custom rules from the CLI" + if [ $num_failures != 0 ]; then echo "Failed $num_failures tests" exit 1 diff --git a/test/files/custom-rule-cli-rule-test/test.ts.lint b/test/files/custom-rule-cli-rule-test/test.ts.lint new file mode 100644 index 00000000000..d879311be7a --- /dev/null +++ b/test/files/custom-rule-cli-rule-test/test.ts.lint @@ -0,0 +1 @@ +var test = 5; diff --git a/test/files/custom-rule-cli-rule-test/tslint.json b/test/files/custom-rule-cli-rule-test/tslint.json new file mode 100644 index 00000000000..03debafdccb --- /dev/null +++ b/test/files/custom-rule-cli-rule-test/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "no-fail": true + } +} diff --git a/test/files/custom-rule-rule-test/test.ts.lint b/test/files/custom-rule-rule-test/test.ts.lint new file mode 100644 index 00000000000..d879311be7a --- /dev/null +++ b/test/files/custom-rule-rule-test/test.ts.lint @@ -0,0 +1 @@ +var test = 5; diff --git a/test/files/custom-rule-rule-test/tslint.json b/test/files/custom-rule-rule-test/tslint.json new file mode 100644 index 00000000000..569530971c0 --- /dev/null +++ b/test/files/custom-rule-rule-test/tslint.json @@ -0,0 +1,6 @@ +{ + "rulesDirectory": "../custom-rules-2", + "rules": { + "no-fail": true + } +}