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

Example line numbers do not seem to match the source #18

Closed
kaukas opened this issue Jan 5, 2021 · 4 comments
Closed

Example line numbers do not seem to match the source #18

kaukas opened this issue Jan 5, 2021 · 4 comments
Assignees
Labels
bug Something isn't working

Comments

@kaukas
Copy link

kaukas commented Jan 5, 2021

Having a spec file

require "./spec_helper"

Spectator.describe Thing do
  it "works" do
    expect(false).to eq(true)
  end
end

crystal spec reports

     Failure: false does not equal true

         actual: false
       expected: true

     # spec/bisect_spec.cr:21

The example is defined at line 4 but (I suppose) after macro expansion it appears on line 21. This is a problem in case one uses tools like vim-test which run the spec-under-cursor using the line number of it.

Can anything be done to make the line numbers match?

@kaukas
Copy link
Author

kaukas commented Jan 6, 2021

Actually, I am not sure what's happening with the line numbers.

require "./spec_helper"

Spectator.describe Bisect do
  it "fails on an empty array" do
    expect(false).to eq(true)
  end

  it "returns the only item" do
    expect(false).to eq(true)
  end

  it "calls the block and returns the item that the block is truthy for" do
    expect(false).to eq(true)
  end

  it "first verifies that all items are truthy" do
    expect(false).to eq(true)
  end
end

prints

Failed examples:

crystal spec spec/bisect_spec.cr:21 # Bisect fails on an empty array
crystal spec spec/bisect_spec.cr:7 # Bisect returns the only item
crystal spec spec/bisect_spec.cr:11 # Bisect calls the block and returns the item that the block is truthy for
crystal spec spec/bisect_spec.cr:15 # Bisect first verifies that all items are truthy

So the order is correct but the line numbers are somewhat random.

Also, the spec spec defined on lines 4-6

  it "one" do
    false.should eq(true)
  end

can be invoked by calling any of

crystal spec spec/test_spec.cr:4
crystal spec spec/test_spec.cr:5
crystal spec spec/test_spec.cr:6

For spectator, only the exact line works.

@icy-arctic-fox icy-arctic-fox added the bug Something isn't working label Jan 6, 2021
@icy-arctic-fox
Copy link
Owner

There seems to be some issue with macro expansion and the original AST position information.

This should be fixed in the upcoming v0.10.0 code, I've verified the line numbers match up there. The fix can probably be back-ported to v0.9 of Spectator.

As for multi-line matching, that will likely need additional work to make possible.

@icy-arctic-fox
Copy link
Owner

This should be fixed in the latest release (0.9.31). Can you try it out and make sure it works on your end before we close this issue?

@icy-arctic-fox icy-arctic-fox self-assigned this Jan 8, 2021
@kaukas
Copy link
Author

kaukas commented Jan 11, 2021

I can confirm that running by line number picks the right it, thank you! That was very quick!

As you said, anywhere else in the spec still does not work.

@kaukas kaukas closed this as completed Jan 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants