From a549c9b971c95717fc2a47860aa7a37185af91c7 Mon Sep 17 00:00:00 2001 From: Bart van Oort Date: Wed, 23 Jun 2021 17:24:16 +0200 Subject: [PATCH] Irons out some kinks in the formatting of details for `testing` rules --- linters/testing/linter.go | 12 ++++++++---- linters/testing/linter_test.go | 14 +++++++------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/linters/testing/linter.go b/linters/testing/linter.go index 7f7b019..730078b 100644 --- a/linters/testing/linter.go +++ b/linters/testing/linter.go @@ -223,11 +223,11 @@ 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." } @@ -235,7 +235,11 @@ Please make sure your test report file is a valid Cobertura-compatible XML file. //--------------------------------------------------------------------------------------- -const howToMakeJUnitXML = "When using `pytest` to run your project's tests, use the `--junitxml=` 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=` 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 diff --git a/linters/testing/linter_test.go b/linters/testing/linter_test.go index dd9bbff..7e37e5c 100644 --- a/linters/testing/linter_test.go +++ b/linters/testing/linter_test.go @@ -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") }, }, { @@ -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") }, }, { @@ -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") }, }, { @@ -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") }, }, {