-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(inspections) #44 Add tests for clippy output parser
- Loading branch information
1 parent
c23c0ed
commit 315b7e8
Showing
8 changed files
with
197 additions
and
3 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
123 changes: 123 additions & 0 deletions
123
...ent/src/test/kotlin/jetbrains/buildServer/rust/inspections/ClippyInspectionsParserTest.kt
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,123 @@ | ||
/* | ||
* Copyright 2000-2021 JetBrains s.r.o. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"). | ||
* See LICENSE in the project root for license information. | ||
*/ | ||
|
||
package jetbrains.buildServer.rust.inspections | ||
|
||
import org.assertj.core.api.Java6Assertions.assertThat | ||
import org.testng.annotations.BeforeMethod | ||
|
||
import org.testng.annotations.Test | ||
|
||
class ClippyInspectionsParserTest { | ||
|
||
private lateinit var parser: ClippyInspectionsParser | ||
|
||
private lateinit var clippyOutput: String | ||
private val parserResult = mutableListOf<Inspection>() | ||
|
||
@BeforeMethod | ||
fun setUp() { | ||
parser = ClippyInspectionsParser() | ||
} | ||
|
||
@Test | ||
fun `should parse empty files without errors`() { | ||
`given clippy produced`("nothing") | ||
`when parser runs`() | ||
`no inspections should be reported`() | ||
} | ||
|
||
@Test | ||
fun `should parse clippy output with 1 error reported`() { | ||
`given clippy produced`("single.error") | ||
`when parser runs`() | ||
`single error should be reported`() | ||
} | ||
|
||
@Test | ||
fun `should parse clippy output with 1 warning reported`() { | ||
`given clippy produced`("single.warning") | ||
`when parser runs`() | ||
`single warning should be reported`() | ||
} | ||
|
||
@Test | ||
fun `should parse clippy output with error and warning reported`() { | ||
`given clippy produced`("error.and.warning") | ||
`when parser runs`() | ||
`error and warning should be reported`() | ||
} | ||
|
||
@Test | ||
fun `should parse clippy output with filename with colon symbol in name`() { | ||
`given clippy produced`("file.with.colon") | ||
`when parser runs`() | ||
`error with filename with colon symbol should be reported`() | ||
} | ||
|
||
private fun `given clippy produced`(filename: String) { | ||
clippyOutput = this::class.java.classLoader.getResource("cargo/clippy/$filename.txt")!!.readText() | ||
} | ||
|
||
private fun `when parser runs`() { | ||
parserResult.clear() | ||
for (line in clippyOutput.lineSequence()) { | ||
parser.processLine(line)?.let(parserResult::add) | ||
} | ||
} | ||
|
||
private fun `no inspections should be reported`() { | ||
assertThat(parserResult).isEmpty() | ||
} | ||
|
||
private fun `single error should be reported`() { | ||
assertThat(parserResult).hasSize(1) | ||
val inspection = parserResult[0] | ||
assertThat(inspection.type).isEqualTo(ClippyInspectionsParser.CLIPPY_ERROR) | ||
assertThat(inspection.severity).isEqualTo(Inspection.Severity.ERROR) | ||
assertThat(inspection.message).isEqualTo("for loop over `option`, which is an `Option`. This is more readably written as an `if let` statement") | ||
assertThat(inspection.file).isEqualTo("clippy2.rs") | ||
assertThat(inspection.line).isEqualTo(9) | ||
} | ||
|
||
private fun `single warning should be reported`() { | ||
assertThat(parserResult).hasSize(1) | ||
val inspection = parserResult[0] | ||
assertThat(inspection.type).isEqualTo(ClippyInspectionsParser.CLIPPY_WARNING) | ||
assertThat(inspection.severity).isEqualTo(Inspection.Severity.WARNING) | ||
assertThat(inspection.message).isEqualTo("unused variable: `y`") | ||
assertThat(inspection.file).isEqualTo("clippy.rs") | ||
assertThat(inspection.line).isEqualTo(16) | ||
} | ||
|
||
private fun `error and warning should be reported`() { | ||
assertThat(parserResult).hasSize(2) | ||
val error = parserResult[0] | ||
assertThat(error.type).isEqualTo(ClippyInspectionsParser.CLIPPY_ERROR) | ||
assertThat(error.severity).isEqualTo(Inspection.Severity.ERROR) | ||
assertThat(error.message).isEqualTo("for loop over `option`, which is an `Option`. This is more readably written as an `if let` statement") | ||
assertThat(error.file).isEqualTo("clippy2.rs") | ||
assertThat(error.line).isEqualTo(9) | ||
|
||
val warning = parserResult[1] | ||
assertThat(warning.type).isEqualTo(ClippyInspectionsParser.CLIPPY_WARNING) | ||
assertThat(warning.severity).isEqualTo(Inspection.Severity.WARNING) | ||
assertThat(warning.message).isEqualTo("`assert!(false)` should probably be replaced") | ||
assertThat(warning.file).isEqualTo("clippy.rs") | ||
assertThat(warning.line).isEqualTo(19) | ||
} | ||
|
||
private fun `error with filename with colon symbol should be reported`() { | ||
assertThat(parserResult).hasSize(1) | ||
val inspection = parserResult[0] | ||
assertThat(inspection.type).isEqualTo(ClippyInspectionsParser.CLIPPY_ERROR) | ||
assertThat(inspection.severity).isEqualTo(Inspection.Severity.ERROR) | ||
assertThat(inspection.message).isEqualTo("for loop over `option`, which is an `Option`. This is more readably written as an `if let` statement") | ||
assertThat(inspection.file).isEqualTo("weird:file:name.rs") | ||
assertThat(inspection.line).isEqualTo(9) | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
plugin-rust-agent/src/test/resources/cargo/clippy/error.and.warning.txt
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,25 @@ | ||
Checking clippy2 v0.0.1 (/home/evgenii_bovykin/IdeaProjects/teamcity-rust-plugin/servers/TeamCity-2021.1/buildAgent/work/2d3c4d163bcdcf0e)t | ||
error: for loop over `option`, which is an `Option`. This is more readably written as an `if let` statement | ||
--> clippy2.rs:9:14 | ||
| | ||
9 | for x in option { | ||
| ^^^^^^ | ||
| | ||
= note: `#[deny(clippy::for_loops_over_fallibles)]` on by default | ||
= help: consider replacing `for x in option` with `if let Some(x) = option` | ||
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#for_loops_over_fallibles | ||
|
||
warning: `assert!(false)` should probably be replaced | ||
--> clippy.rs:19:5 | ||
| | ||
19 | assert!(false); | ||
| ^^^^^^^^^^^^^^^ | ||
| | ||
= note: `#[warn(clippy::assertions_on_constants)]` on by default | ||
= help: use `panic!()` or `unreachable!()` | ||
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#assertions_on_constants | ||
= note: this warning originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) | ||
|
||
error: could not compile `clippy2` | ||
|
||
To learn more, run the command again with --verbose. |
16 changes: 16 additions & 0 deletions
16
plugin-rust-agent/src/test/resources/cargo/clippy/file.with.colon.txt
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,16 @@ | ||
Checking clippy2 v0.0.1 (/home/evgenii_bovykin/IdeaProjects/teamcity-rust-plugin/servers/TeamCity-2021.1/buildAgent/work/2d3c4d163bcdcf0e) | ||
error: for loop over `option`, which is an `Option`. This is more readably written as an `if let` statement | ||
--> weird:file:name.rs:9:14 | ||
| | ||
9 | for x in option { | ||
| ^^^^^^ | ||
| | ||
= note: `#[deny(clippy::for_loops_over_fallibles)]` on by default | ||
= help: consider replacing `for x in option` with `if let Some(x) = option` | ||
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#for_loops_over_fallibles | ||
|
||
error: aborting due to 2 previous errors; 4 warnings emitted | ||
|
||
error: could not compile `clippy2` | ||
|
||
To learn more, run the command again with --verbose. |
Empty file.
16 changes: 16 additions & 0 deletions
16
plugin-rust-agent/src/test/resources/cargo/clippy/single.error.txt
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,16 @@ | ||
Checking clippy2 v0.0.1 (/home/evgenii_bovykin/IdeaProjects/teamcity-rust-plugin/servers/TeamCity-2021.1/buildAgent/work/2d3c4d163bcdcf0e) | ||
error: for loop over `option`, which is an `Option`. This is more readably written as an `if let` statement | ||
--> clippy2.rs:9:14 | ||
| | ||
9 | for x in option { | ||
| ^^^^^^ | ||
| | ||
= note: `#[deny(clippy::for_loops_over_fallibles)]` on by default | ||
= help: consider replacing `for x in option` with `if let Some(x) = option` | ||
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#for_loops_over_fallibles | ||
|
||
error: aborting due to 2 previous errors; 4 warnings emitted | ||
|
||
error: could not compile `clippy2` | ||
|
||
To learn more, run the command again with --verbose. |
14 changes: 14 additions & 0 deletions
14
plugin-rust-agent/src/test/resources/cargo/clippy/single.warning.txt
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,14 @@ | ||
Checking clippy2 v0.0.1 (/home/evgenii_bovykin/IdeaProjects/teamcity-rust-plugin/servers/TeamCity-2021.1/buildAgent/work/2d3c4d163bcdcf0e) | ||
warning: unused variable: `y` | ||
--> clippy.rs:16:9 | ||
| | ||
16 | let y = 1_f64 / x; | ||
| ^ help: if this is intentional, prefix it with an underscore: `_y` | ||
| | ||
= note: `#[warn(unused_variables)]` on by default | ||
|
||
error: aborting due to 2 previous errors; 4 warnings emitted | ||
|
||
error: could not compile `clippy2` | ||
|
||
To learn more, run the command again with --verbose. |