From 5f7791bf16eb1da3ac7f414d9a839b30f85f6920 Mon Sep 17 00:00:00 2001 From: Michael Myers Date: Mon, 15 Feb 2016 11:57:14 -0500 Subject: [PATCH 1/6] ignore jetbrains IDE files --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index 5f29f280..1c89fd50 100644 --- a/.gitignore +++ b/.gitignore @@ -44,3 +44,6 @@ cobertura.xml html *.gcda *.gcno + +# JetBrains IDE +.idea/ \ No newline at end of file From 5adfbd11a50fe4913cfe9e9a0d86450ba1acbd8f Mon Sep 17 00:00:00 2001 From: Michael Myers Date: Mon, 15 Feb 2016 11:57:34 -0500 Subject: [PATCH 2/6] add teamcity as flag --- bin/slather | 3 +++ 1 file changed, 3 insertions(+) diff --git a/bin/slather b/bin/slather index d1e3c2cf..557f1330 100755 --- a/bin/slather +++ b/bin/slather @@ -15,6 +15,7 @@ Clamp do option ["--circleci"], :flag, "Indicate that the builds are running on CircleCI" option ["--jenkins"], :flag, "Indicate that the builds are running on Jenkins" option ["--buildkite"], :flag, "Indicate that the builds are running on Buildkite" + option ["--teamcity"], :flag, "Indicate that the builds are running on TeamCity" option ["--coveralls", "-c"], :flag, "Post coverage results to coveralls" option ["--simple-output", "-s"], :flag, "Output coverage results to the terminal" @@ -81,6 +82,8 @@ Clamp do project.ci_service = :jenkins elsif buildkite? project.ci_service = :buildkite + elsif teamcity? + project.ci_service = :teamcity end end From 6c659e41b885236d4ba41f699629ff41ef1eaf21 Mon Sep 17 00:00:00 2001 From: Michael Myers Date: Mon, 15 Feb 2016 12:00:01 -0500 Subject: [PATCH 3/6] added build statistic reporting for teamcity with addition to spec --- lib/slather/coverage_service/simple_output.rb | 16 +++++++++++ .../coverage_service/simple_output_spec.rb | 27 ++++++++++++++++++- 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/lib/slather/coverage_service/simple_output.rb b/lib/slather/coverage_service/simple_output.rb index dfebd065..daca8c23 100644 --- a/lib/slather/coverage_service/simple_output.rb +++ b/lib/slather/coverage_service/simple_output.rb @@ -26,6 +26,22 @@ def post puts "#{coverage_file.source_file_pathname_relative_to_repo_root}: #{lines_tested} of #{total_lines} lines (#{percentage}%)" end + + # check if there needs to be custom reporting based on the ci service + if ci_service == :teamcity + # TeamCity Build Statistic Reporting + # + # Reporting format ##teamcity[buildStatisticValue key='' value=''] + # key='CodeCoverageAbsLCovered' is total number of lines covered + # key='CodeCoverageAbsLTotal' is total number of lines + # + # Sources: + # - https://confluence.jetbrains.com/display/TCDL/Build+Script+Interaction+with+TeamCity#BuildScriptInteractionwithTeamCity-ReportingBuildStatistics + # - https://confluence.jetbrains.com/display/TCDL/Custom+Chart#CustomChart-listOfDefaultStatisticValues + puts "##teamcity[buildStatisticValue key='CodeCoverageAbsLCovered' value='%i']" % total_project_lines_tested + puts "##teamcity[buildStatisticValue key='CodeCoverageAbsLTotal' value='%i']" % total_project_lines + end + total_percentage = '%.2f' % [(total_project_lines_tested / total_project_lines.to_f) * 100.0] puts "Test Coverage: #{total_percentage}%" end diff --git a/spec/slather/coverage_service/simple_output_spec.rb b/spec/slather/coverage_service/simple_output_spec.rb index 49f1e518..a8a69fbd 100644 --- a/spec/slather/coverage_service/simple_output_spec.rb +++ b/spec/slather/coverage_service/simple_output_spec.rb @@ -6,7 +6,7 @@ proj = Slather::Project.open(FIXTURES_PROJECT_PATH) proj.build_directory = TEMP_DERIVED_DATA_PATH proj.input_format = "profdata" - proj.configure + proj.send(:configure) proj end @@ -30,5 +30,30 @@ fixtures_project.post end + + describe 'ci_service reporting output' do + + context "ci_service is :teamcity" do + before(:each) { fixtures_project.ci_service = :teamcity } + + it "should print out the coverage" do + ["spec/fixtures/fixtures/fixtures.m: 3 of 6 lines (50.00%)", + "spec/fixtures/fixtures/more_files/Branches.m: 13 of 30 lines (43.33%)", + "spec/fixtures/fixturesTests/BranchesTests.m: 16 of 16 lines (100.00%)", + "spec/fixtures/fixturesTests/fixturesTests.m: 12 of 12 lines (100.00%)", + "spec/fixtures/fixturesTests/peekaviewTests.m: 11 of 11 lines (100.00%)", + "##teamcity[buildStatisticValue key='CodeCoverageAbsLCovered' value='55']", + "##teamcity[buildStatisticValue key='CodeCoverageAbsLTotal' value='75']", + "Test Coverage: 73.33%" + ].each do |line| + expect(fixtures_project).to receive(:puts).with(line) + end + + fixtures_project.post + end + end + + end + end end From 83c90f27272800aa10152fbf669c9f0eda42d331 Mon Sep 17 00:00:00 2001 From: Michael Myers Date: Mon, 15 Feb 2016 13:54:00 -0500 Subject: [PATCH 4/6] adds example usage to readme --- README.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/README.md b/README.md index df006546..23f1f494 100644 --- a/README.md +++ b/README.md @@ -174,6 +174,14 @@ $ slather coverage --html path/to/project.xcodeproj This will make a directory named `html` in your root directory (unless `--output-directory` is specified) and will generate all the reports as static html pages inside the directory. It will print out the report's path by default, but you can also specify `--show` flag to open it in your browser automatically. +### TeamCity Reporting + +To report the coverage statistics to TeamCity: + +```sh +$ slather coverage --teamcity -s +``` + ### Coverage for code included via CocoaPods If you're trying to compute the coverage of code that has been included via From 2ba735ed1b656ae5d33793a53965f77822ee717d Mon Sep 17 00:00:00 2001 From: Michael Myers Date: Tue, 23 Feb 2016 15:47:34 -0500 Subject: [PATCH 5/6] revert unnecessary send(:configure) --- spec/slather/coverage_service/simple_output_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/slather/coverage_service/simple_output_spec.rb b/spec/slather/coverage_service/simple_output_spec.rb index a8a69fbd..faa7c8a3 100644 --- a/spec/slather/coverage_service/simple_output_spec.rb +++ b/spec/slather/coverage_service/simple_output_spec.rb @@ -6,7 +6,7 @@ proj = Slather::Project.open(FIXTURES_PROJECT_PATH) proj.build_directory = TEMP_DERIVED_DATA_PATH proj.input_format = "profdata" - proj.send(:configure) + proj.configure proj end From b7a6f4b231f8194952c020a81891a7374ee98288 Mon Sep 17 00:00:00 2001 From: Michael Myers Date: Tue, 23 Feb 2016 15:56:15 -0500 Subject: [PATCH 6/6] changelog entry --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 27439280..fb17e7dc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,9 @@ # CHANGELOG ## master +* Build Statistic Reporting for TeamCity + [Michael Myers](https://github.com/michaelmyers) + [#150](https://github.com/SlatherOrg/slather/pull/150) ## v2.0.0 * Correct html rendering when using profdata format