Skip to content

Commit

Permalink
Irons out some kinks in the formatting of details for testing rules
Browse files Browse the repository at this point in the history
  • Loading branch information
bvobart committed Jun 23, 2021
1 parent 301b892 commit a549c9b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
12 changes: 8 additions & 4 deletions linters/testing/linter.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,19 +223,23 @@ Please make sure your test report file is a valid Cobertura-compatible XML file.
report.Scores[RuleTestCoverage] = score

if totalLines != 0 && hitLines == totalLines {
report.Details[RuleTestCoverage] = "Wow! Congratulations! You've achieved full 100% line test coverage! Great job!"
report.Details[RuleTestCoverage] = "Wow! Congratulations! You've achieved full **100%** line test coverage! Great job!"
} else if hitRate < l.Config.CoverageTarget {
report.Details[RuleTestCoverage] = fmt.Sprintf("Your project's tests achieved %.1f%% line test coverage, but %.1f%% is the target amount of test coverage to beat. You'll need to further improve your tests.", hitRate, l.Config.CoverageTarget)
report.Details[RuleTestCoverage] = fmt.Sprintf("Your project's tests achieved **%.1f%%** line test coverage, but **%.1f%%** is the target amount of test coverage to beat. You'll need to further improve your tests.", hitRate, l.Config.CoverageTarget)
} else if hitRate >= l.Config.CoverageTarget {
report.Details[RuleTestCoverage] = fmt.Sprintf("Congratulations, your project's tests have achieved %.1f%% line test coverage, which meets the target of %.1f%% test coverage!", hitRate, l.Config.CoverageTarget)
report.Details[RuleTestCoverage] = fmt.Sprintf("Congratulations, your project's tests have achieved **%.1f%%** line test coverage, which meets the target of **%.1f%%** test coverage!", hitRate, l.Config.CoverageTarget)
} else if totalLines == 0 {
report.Details[RuleTestCoverage] = "It seems your test coverage report is empty, no lines were covered."
}
}

//---------------------------------------------------------------------------------------

const howToMakeJUnitXML = "When using `pytest` to run your project's tests, use the `--junitxml=<filename>` option to generate such a test report, e.g.: `pytest --junitxml=tests-report.xml`"
const howToMakeJUnitXML = "When using `pytest` to run your project's tests, use the `--junitxml=<filename>` option to generate such a test report, e.g.:" + `
` + "```" + `
pytest --junitxml=tests-report.xml
` + "```\n"

const howToMakeCoverageXML = "Generating a test coverage report with `pytest` can be done by adding and installing `pytest-cov` as a development dependency of your project. Then use the following command to run your tests and generate both a test report as well as a coverage report:" + `
` + "```" + `
pytest --junitxml=tests-report.xml --cov=path_to_package_under_test --cov-report=xml
Expand Down
14 changes: 7 additions & 7 deletions linters/testing/linter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ func TestTestingLinter(t *stdtesting.T) {
require.Contains(t, report.Details[testing.RuleTestsPass], "all **4** tests in your project passed")
// require.Equal(t, 0, report.Scores[testing.RuleTestsFolder])
require.EqualValues(t, 0, report.Scores[testing.RuleTestCoverage])
require.Contains(t, report.Details[testing.RuleTestCoverage], "achieved 0.0% line test coverage")
require.Contains(t, report.Details[testing.RuleTestCoverage], "80.0% is the target amount of test coverage")
require.Contains(t, report.Details[testing.RuleTestCoverage], "achieved **0.0%** line test coverage")
require.Contains(t, report.Details[testing.RuleTestCoverage], "**80.0%** is the target amount of test coverage")
},
},
{
Expand All @@ -137,8 +137,8 @@ func TestTestingLinter(t *stdtesting.T) {
require.Contains(t, report.Details[testing.RuleTestsPass], "all **4** tests in your project passed")
// require.Equal(t, 0, report.Scores[testing.RuleTestsFolder])
require.EqualValues(t, 50, report.Scores[testing.RuleTestCoverage])
require.Contains(t, report.Details[testing.RuleTestCoverage], "achieved 50.0% line test coverage")
require.Contains(t, report.Details[testing.RuleTestCoverage], "100.0% is the target amount of test coverage")
require.Contains(t, report.Details[testing.RuleTestCoverage], "achieved **50.0%** line test coverage")
require.Contains(t, report.Details[testing.RuleTestCoverage], "**100.0%** is the target amount of test coverage")
},
},
{
Expand All @@ -159,8 +159,8 @@ func TestTestingLinter(t *stdtesting.T) {
require.Contains(t, report.Details[testing.RuleTestsPass], "all **4** tests in your project passed")
// require.Equal(t, 0, report.Scores[testing.RuleTestsFolder])
require.EqualValues(t, 100, report.Scores[testing.RuleTestCoverage])
require.Contains(t, report.Details[testing.RuleTestCoverage], "achieved 50.0% line test coverage")
require.Contains(t, report.Details[testing.RuleTestCoverage], "which meets the target of 50.0% test coverage")
require.Contains(t, report.Details[testing.RuleTestCoverage], "achieved **50.0%** line test coverage")
require.Contains(t, report.Details[testing.RuleTestCoverage], "which meets the target of **50.0%** test coverage")
},
},
{
Expand All @@ -182,7 +182,7 @@ func TestTestingLinter(t *stdtesting.T) {
// require.Equal(t, 0, report.Scores[testing.RuleTestsFolder])
require.EqualValues(t, 100, report.Scores[testing.RuleTestCoverage])
require.Contains(t, report.Details[testing.RuleTestCoverage], "Wow! Congratulations!")
require.Contains(t, report.Details[testing.RuleTestCoverage], "100% line test coverage")
require.Contains(t, report.Details[testing.RuleTestCoverage], "**100%** line test coverage")
},
},
{
Expand Down

0 comments on commit a549c9b

Please sign in to comment.