From 2e0320b64f8dc6cfa1c902bf4ee56f738846feba Mon Sep 17 00:00:00 2001 From: Jan Grodowski Date: Tue, 3 Dec 2024 23:08:11 +0100 Subject: [PATCH] Add tests for top-level blocks (closes #83, closes #135) --- CHANGELOG.md | 6 ++++++ spec/changeset_spec.rb | 4 ++-- spec/fixtures/Rakefile | 2 +- spec/fixtures/sinatra.rb | 4 ++++ spec/fixtures/test.git/index | Bin 494 -> 574 bytes .../f5/c5de24d9a10dec82ef9f5f16ed1e89cf30ac00 | Bin 0 -> 84 bytes spec/report_spec.rb | 15 ++++++++++++--- 7 files changed, 25 insertions(+), 6 deletions(-) create mode 100644 spec/fixtures/sinatra.rb create mode 100644 spec/fixtures/test.git/objects/f5/c5de24d9a10dec82ef9f5f16ed1e89cf30ac00 diff --git a/CHANGELOG.md b/CHANGELOG.md index 4cf1b27..79350ba 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). ## [Unreleased] +### Added +- Add support for including and exluding files by glob patterns, supplied through CLI args and the configuration file (#146) + +### Fixed +- Files that were changed but don't appear in the coverage report at all will now be reported as uncovered, as expected. +- Fixed an issue where top-level methods were not being considered (#135). This was caused by a bug in the tree traversal logic. # [0.5.0] - 2024-01-09 ### Changed diff --git a/spec/changeset_spec.rb b/spec/changeset_spec.rb index 5a4c7f3..49f3be4 100644 --- a/spec/changeset_spec.rb +++ b/spec/changeset_spec.rb @@ -12,7 +12,7 @@ ).update expect(changeset.files.keys).to match_array( - %w[file_one file_two staged_file class.rb module.rb] + %w[file_one file_two staged_file class.rb module.rb sinatra.rb] ) expect(changeset.files['file_two']).to eq([7, 10, 11]) end @@ -24,7 +24,7 @@ ).update expect(changeset.file_paths).to match_array( - %w[file_one file_three file_two staged_file class.rb module.rb] + %w[file_one file_three file_two staged_file class.rb module.rb sinatra.rb] ) expect(changeset.files['file_two']).to eq([7, 10, 11]) expect(changeset.files['file_three']).to eq([1, 2, 3, 4, 5, 6]) diff --git a/spec/fixtures/Rakefile b/spec/fixtures/Rakefile index a561c89..e5c6128 100644 --- a/spec/fixtures/Rakefile +++ b/spec/fixtures/Rakefile @@ -4,7 +4,7 @@ require 'bundler/gem_tasks' require 'rspec/core/rake_task' require 'rubocop/rake_task' -def rakefile # TODO: fix known issue of not parsing top-level expressions! +def rakefile desc 'Run RuboCop' RuboCop::RakeTask.new(:rubocop) diff --git a/spec/fixtures/sinatra.rb b/spec/fixtures/sinatra.rb new file mode 100644 index 0000000..f5c5de2 --- /dev/null +++ b/spec/fixtures/sinatra.rb @@ -0,0 +1,4 @@ +require 'sinatra' +get '/dummy_path' do + "This line is not covered" +end diff --git a/spec/fixtures/test.git/index b/spec/fixtures/test.git/index index 0d56d9285c6313181673b00cf48773d744b7f514..1ea5dd273014b3e10019268a1da7b575ce008137 100644 GIT binary patch delta 214 zcmaFIypKh}#WTp6fq{Vuh}qNqtBV*tXWWI*syi4N7=$J&)QCX%pYEZEZ?J)gd+|f{ zLDWxTtVv1tujdou|F#H5gUn&;Z#7|HXk5a;!1xttmk1Dhd_8(k<>o@(H%;&7$BVs{ z>pX9;hJk^rI5RJ?q$p9ZC<&+r48Zn!1wBKyfAR!IFOk3ImoLk^yt25e{>1LkVpoy< HF>1R3ZU#ep delta 134 zcmdnT@{U=-#WTp6fq{Vuh}qJfZT}>*|86~mp4Y(0z#uSDp+*GEKOiBFBEG=}DsFfV oS$q;BOnu4$Wbw%l7`;SFTfNKfXJorEG|ES^N__d})iF;709H6R`2YX_ diff --git a/spec/fixtures/test.git/objects/f5/c5de24d9a10dec82ef9f5f16ed1e89cf30ac00 b/spec/fixtures/test.git/objects/f5/c5de24d9a10dec82ef9f5f16ed1e89cf30ac00 new file mode 100644 index 0000000000000000000000000000000000000000..8cca3796dbda8fd5982e70e9865de028f3dde146 GIT binary patch literal 84 zcmV-a0IUCa0S(154uBvG1yE;B@x#*5#Knua8<0jwpePg*Z?A88K39)*nHt|CH3s!0 qPMafhvV!I?N_qFoX(WVd0K3K1k&`g~r7Dj4aN}SNOE4cVHyTFbwj>$= literal 0 HcmV?d00001 diff --git a/spec/report_spec.rb b/spec/report_spec.rb index 4d644d4..97ba2dc 100644 --- a/spec/report_spec.rb +++ b/spec/report_spec.rb @@ -21,7 +21,7 @@ it 'builds a report with coverage metrics' do report.build - expect(report.results.size).to eq(2) + expect(report.results.size).to eq(3) all = report.all_results expect(all[0]).to be_an(Undercover::Result) expect(all[0].coverage_f).to eq(0.8333) @@ -54,6 +54,15 @@ expect(unflagged[0].coverage_f).to eq(0.875) expect(unflagged[1].name).to eq('baz') expect(unflagged[1].coverage_f).to eq(1.0) + + # includes blocks at top-level (reproduce https://github.com/grodowski/undercover/issues/135) + top_level_results = report.results['sinatra.rb'].to_a + expect(top_level_results.size).to eq(1) + expect(top_level_results[0].name).to eq('block') + expect(top_level_results[0].coverage_f).to eq(0.0) + expect(top_level_results[0].flagged?).to eq(true) + expect(top_level_results[0].first_line).to eq(2) + expect(top_level_results[0].last_line).to eq(4) end it 'does not parse files outside of the lcov report' do @@ -67,13 +76,13 @@ it 'builds pathnames relative to --path' do report.build - expect(report.results.keys.sort).to eq(%w[class.rb module.rb]) + expect(report.results.keys.sort).to eq(%w[class.rb module.rb sinatra.rb]) end it 'builds does not mess up with result keys' do report.build - expect(report.results.keys.sort).to eq(%w[class.rb module.rb]) + expect(report.results.keys.sort).to eq(%w[class.rb module.rb sinatra.rb]) end context 'with mock changeset' do