Skip to content

Update repo for Crystal 1+ and document how to run the tests; maybe add an example shard that uses it #17

@drhuffman12

Description

@drhuffman12

I tried forking and updating/fixing this repo, but am having issues. What am I missing?

Please add to the doc's re running the tests (and update the repo to work with Crystal 1+). I think the coverage process is not counting the lines that the specs are actually covering.

  • Update the repo to work with Crystal 1+. (See also Support crystal 1.0.0 #15.)
  • Update the documentation.
    • How to run the tests of this repo?
    • How to use the coverage script on another repo?
    • What the coverage report should look like (e.g.: screenshots)?
  • Fix the coverage script so that the lines covered by the tests are getting counted in the coverage report. (Please forgive me if I'm misunderstanding how to run the coverage script.)
  • Maybe also add an example shard that uses this tool.

For details, see below...

I see spec/run.sh which includes:

#!/bin/sh
crystal src/coverage/cli.cr -- spec/template.cr --use-require="./src/coverage/runtime" -p

I had errors when running that. First, ameba needed to be switched from veelenga/ameba to crystal-ameba/ameba.

The next error was:

$ spec/run.sh
Showing last frame. Use --error-trace for full trace.

In src/coverage/inject/cli.cr:11:20

 11 | OptionParser.parse! do |parser|
                   ^-----
Error: undefined method 'parse!' for OptionParser.class

I chased down that issue and some others in a fork/branch (drhuffman12#1) and I seemed to get the scripts to work eventially. I added an example shard (drhuffman12/crystal-coverage-example#1) using my fork. I had mixed success.

In my example shard, I tried running the coverage script via:

  • lib/coverage/bin/crystal-coverage src/**/*.cr
    • The generated web pages just found one of the src files, possibly just the 'first' found?
  • lib/coverage/bin/crystal-coverage spec/**/*_spec.cr
    • The generated web pages found all 'src' and 'spec' files. Should we just show the 'src' files in the gen'd web page?

It looks like the coverage calculations/process is broken; it runs and generates the web pages but no tests seem to get logged as line coverages. Maybe I'm doing something wrong? In my example shard, I put in two duplicate classes (only diff by class name) and added more tests for one class than the other. However, the coverage for both is identical and the method that I added a test for isn't showing any code coverage:

image

Tests added for some Bar methods...

require "./../spec_helper"

describe Crystal::Coverage::Example::Bar do
  describe "#initialize" do
    it "creates a Bar" do
      var1 = "1 string"
      var2 = 2
      var3 = 3
      bar = Crystal::Coverage::Example::Bar.new(var1: var1, var2: var2)
      bar.should_not be_nil
    end
    context "initializes" do
      it "@var1" do
        var1 = "1 string"
        var2 = 2
        var3 = 3
        bar = Crystal::Coverage::Example::Bar.new(var1: var1, var2: var2)
        bar.var1.should eq(var1)
      end
      it "@var2" do
        var1 = "1 string"
        var2 = 2
        var3 = 3
        bar = Crystal::Coverage::Example::Bar.new(var1: var1, var2: var2)
        bar.var2.should eq(var2)
      end
    end
  end

  describe "#baz" do
    it "creates a Bar" do
      var1 = "1 string"
      var2 = 2
      var3 = 3
      bar = Crystal::Coverage::Example::Bar.new(var1: var1, var2: var2)
      bar.var2.should eq(var2)
      bar.baz
      bar.var2.should eq(var2 * 2)
    end
  end
end

... But, these test's don't seem to register with the coverage script:

image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions