Skip to content
This repository has been archived by the owner on Mar 25, 2021. It is now read-only.

New testing system for rules #900

Merged
merged 30 commits into from
Jan 26, 2016
Merged

New testing system for rules #900

merged 30 commits into from
Jan 26, 2016

Conversation

jkillian
Copy link
Contributor

@jkillian jkillian commented Jan 4, 2016

Implements #620 and provides a solution to #532.

Documentation for this feature will come in a separate PR. The code is still a little bit messy, but I'd like to get a second set of eyes on it for ideas to make it nicer.

In brief, src/test.ts and src/test/* contain the logic/code for parsing the markup of the new testing system. test/rule-tester contains the tests for this code. test/rules contains one directory for every rule which contains the rule's tests written in the new markup style.

Jason Killian added 24 commits January 6, 2016 10:43
Allows tests for rules to be written in a more visual manner.
Works in this commit! However, major code cleanup needed.
Fix bug where messages couldn't have punctuation
Fix bug where errors wouldn't be sorted with a total ordering (sort by message)
Convert tests for no-consecutive-blank-lines, no-duplicate-key
no-duplicate-variable, no-empty, and no-eval rules
…eyword, and no-require-imports. Allow '-' and '_' in message shortcuts
…case-fall-through, and no-trailing-whitespace rules

Tweak no-switch-case-fall-through rule to have saner error start and end locations
Switch to one directory per rule with subdirectories for different options
…typedef rules

Fix trailing-comma rule to have more sensible error locations
Adjust Gruntfile so tests for rules run on Windows
Convert tsx test to new format
This lets us add a --test command that people can use to test custom rules if they wish
Jason Killian added 2 commits January 6, 2016 11:02
@@ -0,0 +1,95 @@
import * as colors from "colors";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

copyright block

@@ -152,6 +162,12 @@ tslint accepts the following commandline options:
and verbose. prose is the default if this option is not used. Additonal
formatters can be added and used if the --formatters-dir option is set.

--test:
Runs tslint on the specified directory and checks if tslint's output matches
the expected output. Automatically loads the tslint.json file in the
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about "... the expected output in .linttest files" (or whatever we end up naming the extension)

@adidahiya
Copy link
Contributor

looks pretty great overall.

I'm wondering if we can make the structure of the linttests simpler. All the .linttest files are called test.ts.linttest and are adjacent to exactly one tslint.json file. Maybe we could do something like TypeScript's fourslash tests?

for example, test/rules/no-require-imports.ts.linttest:

//// tslint.json
{
  "rules": {
    "no-require-imports": true
  }
}

//// linttest
var lib = require('lib'); // failure
          ~~~~~~~~~~~~~~             [no-require]

let lib2 = require('lib2'); // failure
           ~~~~~~~~~~~~~~~             [no-require]

import {l} from 'lib';

var lib3 = load('not_an_import');

var lib4 = lib2.subImport;

var lib5 = require('lib5'), // failure
           ~~~~~~~~~~~~~~~             [no-require]
    lib6 = require('lib6'), // failure
           ~~~~~~~~~~~~~~~             [no-require]
    lib7 = 700;

import lib8 = require('lib8'); // failure
              ~~~~~~~~~~~~~~~             [no-require]

import lib9 = lib2.anotherSubImport;

[no-require]: require() style import is forbidden

this would flatten the directories. you could still have multiple files for a rule, e.g. test/rules/variable-name/allow-leading-underscore.ts.linttest. thoughts?

@jkillian
Copy link
Contributor Author

I'm wondering if we can make the structure of the linttests simpler. All the .linttest files are called test.ts.linttest and are adjacent to exactly one tslint.json file. Maybe we could do something like TypeScript's fourslash tests?

Interesting idea. There are a few cases where this isn't true (no-unused-variable/default, no-unused-variable/react, and some others probably). I don't really feel that this would be a bad idea, but I don't really feel like it would be a huge benefit either. What do you think?

@adidahiya
Copy link
Contributor

yeah, I don't see it as a huge benefit either; the tradeoffs are minor. the current structure does support cases like test/rules/no-unused-variable/ nicely, where you don't have to repeat the contents of tslint.json across your tests. let's keep it how it is.

somewhat relatedly, any ideas for a better directory name than _comprehensive? It's a little misleading because "comprehensive" implies testing all the rules. Perhaps _integration?

@@ -22,13 +22,16 @@ module.exports = function (grunt) {
options: {
reporter: "spec"
},
src: ["build/test/**/*.js"]
src: ["build/test/**/*Tests.js", "build/test/assert.js", "build/test/lint.js"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do you need to include build/test/lint.js here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it seems to still work if I remove it.

@adidahiya
Copy link
Contributor

filed a separate issue for updating documentation, which should be handled next: #941

@adidahiya
Copy link
Contributor

👍

adidahiya added a commit that referenced this pull request Jan 26, 2016
@adidahiya adidahiya merged commit e5b5ff1 into master Jan 26, 2016
@adidahiya adidahiya deleted the new-test-system branch February 20, 2016 08:42
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants