Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "Update coverage.py parser" #120

Merged
merged 1 commit into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ jobs:
crystal: 1.9
- name: Install dependencies
run: shards install
- name: Install coverage.py
run: "pip install --upgrade pip && pip install coverage && pip install pytest"
- name: Run tests
run: crystal spec --verbose --order random --error-on-warnings

Expand Down Expand Up @@ -53,10 +51,8 @@ jobs:
run: |
sudo apt-get update
sudo apt-get install kcov
- name: Install coverage.py
run: "pip install --upgrade pip && pip install coverage && pip install pytest"
- name: Generate coverage
run: bin/crkcov --kcov-args --exclude-pattern=/usr/include,/usr/lib,lib/,spec/ --coverage-dir ${{ github.workspace }}/coverage
run: bin/crkcov --kcov-args --exclude-pattern=/usr/include,/usr/lib,lib/,spec/
- name: Report coverage
env:
COVERALLS_REPO_TOKEN: ${{ github.token }}
Expand Down
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,3 @@
/docs/
/insecure_private_keys
/lib/
.coverage
coverage.xml
2 changes: 1 addition & 1 deletion shard.lock
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ shards:

spectator:
git: https://gitlab.com/arctic-fox/spectator.git
version: 0.12.0
version: 0.11.6

sqlite3:
git: https://github.com/crystal-lang/crystal-sqlite3.git
Expand Down
2 changes: 1 addition & 1 deletion spec/coverage_reporter/api/jobs_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ Spectator.describe CoverageReporter::Api::Jobs do

after_each do
WebMock.reset
ENV.delete("COVERALLS_RUN_AT")
ENV.clear
end

it "calls the /jobs endpoint" do
Expand Down
2 changes: 0 additions & 2 deletions spec/coverage_reporter/api/webhook_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ Spectator.describe CoverageReporter::Api::Webhook do
"X-Coveralls-Reporter" => "coverage-reporter",
"X-Coveralls-Reporter-Version" => CoverageReporter::VERSION,
"X-Coveralls-Source" => "cli",
"Accept" => "*/*",
"User-Agent" => "Crystal #{Crystal::VERSION}",
}
end

Expand Down
108 changes: 7 additions & 101 deletions spec/coverage_reporter/config_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -11,112 +11,15 @@ Spectator.describe CoverageReporter::Config do
)
end

before_each { ENV.clear }
after_each { ENV.clear }

let(repo_token) { nil }
let(path) { "" }
let(job_flag_name) { nil }
let(compare_ref) { nil }
let(compare_sha) { nil }

before_each { delete_env_vars }
after_each { delete_env_vars }

def delete_env_vars
ENV.delete("APPVEYOR")
ENV.delete("APPVEYOR_BUILD_VERSION")
ENV.delete("APPVEYOR_REPO_BRANCH")
ENV.delete("APPVEYOR_REPO_COMMIT")
ENV.delete("APPVEYOR_REPO_NAME")
ENV.delete("BUILDKITE")
ENV.delete("BUILDKITE_BUILD_NUMBER")
ENV.delete("BUILDKITE_BUILD_ID")
ENV.delete("BUILDKITE_PULL_REQUEST")
ENV.delete("BUILDKITE_BRANCH")
ENV.delete("BUILDKITE_COMMIT")
ENV.delete("CF_BRANCH")
ENV.delete("CF_BUILD_ID")
ENV.delete("CF_PULL_REQUEST_ID")
ENV.delete("CF_BRANCH")
ENV.delete("CF_REVISION")
ENV.delete("CI_BRANCH")
ENV.delete("CI_BUILD_NUMBER")
ENV.delete("CI_BUILD_URL")
ENV.delete("CI_COMMIT")
ENV.delete("CI_COMMIT_ID")
ENV.delete("CI_JOB_ID")
ENV.delete("CI_NAME")
ENV.delete("CI_PULL_REQUEST")
ENV.delete("CI_XCODE_PROJECT")
ENV.delete("CI_PULL_REQUEST_NUMBER")
ENV.delete("CIRCLECI")
ENV.delete("CIRCLE_WORKFLOW_ID")
ENV.delete("CIRCLE_BUILD_NUM")
ENV.delete("CIRCLE_BRANCH")
ENV.delete("CIRCLE_BUILD_URL")
ENV.delete("COVERALLS_REPO_TOKEN")
ENV.delete("COVERALLS_RUN_LOCALLY")
ENV.delete("COVERALLS_SERVICE_NAME")
ENV.delete("COVERALLS_SERVICE_NUMBER")
ENV.delete("COVERALLS_SERVICE_JOB_ID")
ENV.delete("COVERALLS_GIT_BRANCH")
ENV.delete("COVERALLS_GIT_COMMIT")
ENV.delete("DRONE")
ENV.delete("DRONE_BUILD_NUMBER")
ENV.delete("DRONE_PULL_REQUEST")
ENV.delete("DRONE_BRANCH")
ENV.delete("DRONE_COMMIT")
ENV.delete("GITHUB_ACTIONS")
ENV.delete("GITHUB_HEAD_REF")
ENV.delete("GITHUB_JOB")
ENV.delete("GITHUB_REF")
ENV.delete("GITHUB_REF_NAME")
ENV.delete("GITHUB_REPOSITORY")
ENV.delete("GITHUB_RUN_ATTEMPT")
ENV.delete("GITHUB_RUN_ID")
ENV.delete("GITHUB_SERVER_URL")
ENV.delete("GITHUB_SHA")
ENV.delete("GITLAB_CI")
ENV.delete("CI_JOB_NAME")
ENV.delete("CI_PIPELINE_IID")
ENV.delete("CI_COMMIT_REF_NAME")
ENV.delete("CI_COMMIT_SHA")
ENV.delete("CI_JOB_URL")
ENV.delete("CI_PIPELINE_URL")
ENV.delete("CI_MERGE_REQUEST_IID")
ENV.delete("JENKINS_HOME")
ENV.delete("BUILD_ID")
ENV.delete("BUILD_NUMBER")
ENV.delete("BRANCH_NAME")
ENV.delete("ghprbPullId")
ENV.delete("SEMAPHORE")
ENV.delete("SEMAPHORE_WORKFLOW_ID")
ENV.delete("SEMAPHORE_GIT_WORKING_BRANCH")
ENV.delete("SEMAPHORE_GIT_PR_NUMBER")
ENV.delete("SEMAPHORE_GIT_SHA")
ENV.delete("SEMAPHORE_ORGANIZATION_URL")
ENV.delete("SEMAPHORE_JOB_ID")
ENV.delete("SURF_SHA1")
ENV.delete("SURF_REF")
ENV.delete("TDDIUM")
ENV.delete("TDDIUM_SESSION_ID")
ENV.delete("TDDIUM_TID")
ENV.delete("TDDIUM_PR_ID")
ENV.delete("TDDIUM_CURRENT_BRANCH")
ENV.delete("TRAVIS")
ENV.delete("TRAVIS_PULL_REQUEST")
ENV.delete("TRAVIS_BRANCH")
ENV.delete("TRAVIS_JOB_NUMBER")
ENV.delete("TRAVIS_BUILD_NUMBER")
ENV.delete("TF_BUILD")
ENV.delete("BUILD_BUILDID")
ENV.delete("SYSTEM_PULLREQUEST_PULLREQUESTNUMBER")
ENV.delete("BUILD_SOURCEBRANCHNAME")
ENV.delete("BUILD_SOURCEVERSION")
ENV.delete("WERCKER")
ENV.delete("WERCKER_BUILD_ID")
ENV.delete("WERCKER_GIT_BRANCH")
ENV.delete("WERCKER_GIT_COMMIT")
end

describe ".new" do
context "without repo_token" do
it "raises an exception" do
Expand Down Expand Up @@ -165,7 +68,9 @@ Spectator.describe CoverageReporter::Config do
end

context "with ENV preset" do
before_each { ENV["COVERALLS_REPO_TOKEN"] = "env-token" }
before_each do
ENV["COVERALLS_REPO_TOKEN"] = "env-token"
end

it "doesn't raise an exception" do
expect { subject }.not_to raise_error
Expand Down Expand Up @@ -245,6 +150,7 @@ Spectator.describe CoverageReporter::Config do
end

context "for generic CI" do
# Imagine we are on Circle
before_each do
ENV["CIRCLECI"] = "1"
ENV["CIRCLE_WORKFLOW_ID"] = "circle-service-number"
Expand Down
41 changes: 5 additions & 36 deletions spec/coverage_reporter/parsers/coveragepy_parser_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,6 @@ require "../../spec_helper"
Spectator.describe CoverageReporter::CoveragepyParser do
subject { described_class.new(nil) }

before_all do
error = IO::Memory.new
output = IO::Memory.new
process_status = Process.run(
command: "coverage run -m pytest",
chdir: "spec/fixtures/python",
shell: true,
error: error,
output: output
)
unless process_status.success?
raise "Failed: #{error}\n#{output}"
end
end

after_all do
File.delete("spec/fixtures/python/.coverage")
end

describe "#matches?" do
it "matches only SQLite3 db file" do
expect(subject.matches?("spec/fixtures/python/.coverage")).to eq true
Expand All @@ -33,24 +14,12 @@ Spectator.describe CoverageReporter::CoveragepyParser do
describe "#parse" do
let(filename) { "spec/fixtures/python/.coverage" }

context "with valid coverage file" do
it "reads the coverage" do
reports = subject.parse(filename)

expect(reports.size).to eq 4
expect(reports.map(&.to_h.transform_keys(&.to_s)))
.to eq YAML.parse(File.read("#{__DIR__}/coveragepy_results.yml"))
end
end

context "with invalid coverage file" do
let(filename) { "spec/fixtures/simplecov/with-only-lines.resultset.json" }

it "raises an error" do
io_memory = IO::Memory.new("some error")
it "reads the coverage" do
result = subject.parse(filename)

expect { subject.parse(filename, io_memory) }.to raise_error(CoverageReporter::CoveragepyParser::ParserError, "some error")
end
expect(result.size).to eq 20
expect(result.map(&.to_h.transform_keys(&.to_s)))
.to eq YAML.parse(File.read("#{__DIR__}/coveragepy_results.yml"))
end
end
end
Loading
Loading