Skip to content

Commit

Permalink
Added actual info in README.md (#342)
Browse files Browse the repository at this point in the history
### What's done:
Updated actual info in README.md
  • Loading branch information
Cheshiriks authored Feb 4, 2022
1 parent c4414a8 commit aded7a7
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 5 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ In case you would like to have several plugins to work in your directory with sa
...
```

## Save warnings DSL
![save-cli](https://user-images.githubusercontent.com/58667063/146390474-71e4921d-416b-4922-b2ea-894f71e491c3.jpg)
You can read more about the `warn plugin` [here](save-plugins/warn-plugin/README.md)


## How to configure
SAVE has a command line interface that runs the framework and your executable. What you need is simply to configure the output of your static analyzer so SAVE will be able to
check if the proper error was raised on the proper line of test code.
Expand Down Expand Up @@ -151,6 +156,9 @@ excludedTests = ["warn/chapter1/GarbageTest.kt", "warn/otherDir/NewTest.kt"], e.
# command execution time for one test (milliseconds)
timeOutMillis = 10000
# language for tests
language = "Kotlin"
```

## Executing specific tests
Expand Down
35 changes: 30 additions & 5 deletions save-plugins/warn-plugin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ Plugin that runs the provided executable and compares emitted warnings with expe
Please note, that it is important for test resources to have specific keywords. For test file it should be `Test`.

### Examples
If you don't like to read long readme file, you can simply check [examples](/examples/kotlin-diktat/warn).
If you don't like to read long readme file, you can simply check [examples](/examples/kotlin-diktat/warn).
There are all available configurations that you need.

### Source files
Test source files (input for SAVE) should have a comment line (use single-line commenting syntax of the target programming language for it)
Expand All @@ -27,7 +28,13 @@ Warning messages are very flexible and can be described in very different ways:
```
// ;warn:3:1: Warning with an explicit set of a line number and column number
```

```
/* ;warn:1: Multiline warning. This line should match `expectedWariningsPattern`
* To match other lines, you need to specify a value of `expectedWarningsEndPattern` (and `expectedWarningsMiddlePattern` if there is any).
* This line should match `expectedWarningsMiddlePattern`
* And the next line should match `expectedWarningsEndPattern`
*/
```
### Regular expressions in warnings
Regular expressions can be used in warning messages.
To configure delimiters, use `patternForRegexInWarning` option (default: `"{{", "}}"`):
Expand Down Expand Up @@ -74,13 +81,27 @@ you will need the following SAVE configuration:
execCmd = "./detekt"
description = "My suite description"
suiteName = "DocsCheck"
# warning is set inside the comment in code, `//` marks comment start in Java
language = "Kotlin"
# if you are using IN_PLACE mode, this flag will be used to extract EXPECTED warnings from the file
expectedWarningsPattern = "// ;warn:(\\d+):(\\d+): (.*)" # (default value)

# for multiline warnings ONLY (if you are using IN_PLACE mode and multiline warnings)
expectedWarningsMiddlePattern = "\\* (.*)"
expectedWarningsEndPattern = "(.*)?\\*/"

[warn]
# extra execution flags that are added to the exec cmd
execFlags = "--build-upon-default-config -i"

# the format and place, where EXPECTED warnings should be put, for example:
# SARIF: means that you put ALL your expected warnings into the special file with the name 'save-warnings.sarif'
# (default) IN_PLACE: means that you need to put your expected warnings into the test resource (and they will be matched by expectedWarningsPattern)
expectedWarningsFormat = "SARIF"

# the format of actual warnings
# (default) PLAIN: means that your tool reports warnings in plain text that. Warnings will be extracted with actualWarningsPattern
# SARIF: means that the output of the tool will be extracted with a SARIF format
actualWarningsFormat = "SARIF"

# e.g. `WARN - 10/14 - Class name is in incorrect case`
# expected regex may allow an empty group for line number
# regex group with lineCaptureGroupIdx may include a number or linePlaceholder and addition/subtraction of a number
Expand All @@ -95,6 +116,10 @@ columnCaptureGroup = 3 # (default value)
# index of regex capture group for message text
messageCaptureGroup = 4 # (default value)

# options that control the capture group for patterns of warnings to extract multiline warning
messageCaptureGroupMiddle = 1 # (default value)
messageCaptureGroupEnd = 1 # (default value)

warningTextHasColumn = true # (default value)
warningTextHasLine = true # (default value)
testNameRegex = ".*Test.*" # (default value)
Expand All @@ -115,7 +140,7 @@ parsed from the same `$testFile` using `warningsInputPattern`. `batchSeparator`
If line number is not present in the comment, it's assumed to be `current line + 1` in regex group with lineCaptureGroupIdx.
`linePlaceholder` is an optional placeholder for the line number that is recognized as the current line and supports addition and subtraction.

`warningsInputPattern` and `warningsOutputPattern` must include some mandatory capture groups: for line number (if `warningTextHasLine` is true),
`expectedWarningsPattern` and `actualWarningsPattern` must include some mandatory capture groups: for line number (if `warningTextHasLine` is true),
for column number (if `warningTextHasColumn` is true) and for warning text. Their indices can be customized
with `lineCaptureGroup`, `columnCaptureGroup` and `messageCaptureGroup` parameters. These parameters are shared between input and output pattern;
usually you'll want them to be consistent to make testing easier, i.e. if input has line number, then so should output.
Expand Down

0 comments on commit aded7a7

Please sign in to comment.