-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
154 additions
and
256 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# Code Structure | ||
|
||
This project is structured as a series of independent steps which are orchestrated by the main function `perturb()` in `src/index.ts`. Each step's behavior can be customized through the use of plugins. | ||
|
||
1. Run the project's test suite to ensure it passes -- if it doesn't, mutation testing is pointless. | ||
|
||
2. Copy the source and test files into a new directory so we can safely work on those files without damaging the originals. | ||
|
||
3. Run the `makeMatches` function, using the active [matcher plugin]() on the source and test lists to get a list of of Match objects. | ||
|
||
4. [`chain`](http://ramdajs.com/0.21.0/docs/#chain) the matches through the `makeMutants` function, using the active [mutator plugins](), to generate a list of Mutant objects. (`chain` is also known as [`flatMap`](http://martinfowler.com/articles/collection-pipeline/flat-map.html) or [`mapcat`](https://clojuredocs.org/clojure.core/mapcat).) | ||
|
||
5. Map the mutant objects through a composition of the `runMutant` function (which delegates to the active [runner plugin]()) and the active [reporter plugin]()'s `onResult` method. | ||
|
||
6. Pass the list of run results to the active [reporter plugin]()'s `onFinish()` method. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
# Plugins | ||
|
||
## Mutators | ||
**Multiple active** | ||
```typescript | ||
interface MutatorPlugin { | ||
name: string; | ||
nodeTypes: Array<string>; | ||
filter?: (n: ESTree.Node): boolean; | ||
mutator: (n: ESTree.Node): ESTree.Node; | ||
} | ||
``` | ||
|
||
A mutator plugin describes a mutation to be applied to an AST node. Multiple mutator plugins can (and should) be active simultaneously. A mutator plugin has the following properties: | ||
|
||
- `name`: a unique string name | ||
- `nodeTypes`: an array of [node types]() the mutator may be run on | ||
- `filter`: an optional predicate function that filters out nodes that matched one of the provided node types. | ||
- `mutator`: a function that returns a new AST node to replace the old one. Despite the name, it **must not** actually mutate the old node by changing, adding, or removing it's properties. | ||
|
||
## Matchers | ||
**One active** | ||
|
||
Matcher plugins come in two flavors, "generative" and "comparative". Comparative matchers are predicate functions which take a test file and a source file and return `true` when they match. | ||
|
||
An example of comparative matching case might be when test files have names resembling source files, but with some kind of prefix or suffix indicating what they test. The tests on the Node.js [core libraries](https://github.com/nodejs/node/tree/master/test/parallel) often fit this pattern. | ||
|
||
By contrast, a generative matcher looks at the string path of a source file and returns the string path of a test file. This would be when, for instance, `/test/thing.js` is the test file for `/lib/thing.js`. Generative matchers imply a 1-1 mapping between test and source files. | ||
|
||
A matcher function, of either type, is initialized with a full configuration object, because it almost always needs to know the directory configuration values used. | ||
|
||
``` | ||
interface MatcherPlugin { | ||
name: string; | ||
type: "comparative" | "generative", | ||
makeMatcher: (cfg: PerturbConfig): GenerativeMatcher | ComparativeMatcher; | ||
} | ||
interface GenerativeMatcher { | ||
(sourceFile: string): string; | ||
} | ||
interface ComparativeMatcher { | ||
(sourceFile: string, testFile: string): boolean; | ||
} | ||
``` | ||
|
||
## Runners | ||
**One active** | ||
```typescript | ||
interface RunnerPlugin { | ||
name: string; | ||
prepare: (m: Mutant): Promise<any>; | ||
run: (m: Mutant): Promise<RunnerResult>; | ||
cleanup: (m: Mutant, before?: any): Promise<void>; | ||
} | ||
``` | ||
|
||
A runner plugin describes how to run a single mutation. As such, it needs to understand how to work with the test harness used by the project. A runner plugin has the following properties: | ||
|
||
- `name`: a unique string name | ||
- `prepare`: a function which sets up the run. In nearly every case, this function should write out the mutated source code to a file (unless you're doing something [exotic]()), but it can also do all kinds of other stuff, such as working with the `require` cache if the run is done in-process. It returns a promise, the result of which will be threaded back into the `cleanup` method. | ||
- `run`: a function which actually executes the tests over the given mutated source file. It returns a "RunnerResult", which is essentially a Mutant with an optional `error` field. | ||
- `cleanup`: a function which cleans up whatever side effects the `prepare` and `run` functions had. Often this involves rewriting the source file to its original value. It might also operate on the `require` cache or do other sorts of housekeeping. | ||
|
||
|
||
|
||
## Reporters | ||
**One active** | ||
|
||
## Skippers | ||
**Multiple active** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.