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

use is_juliarepr more in show.jl testing #54304

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

LilithHafner
Copy link
Member

It used to be used a bunch, now it's used almost always where the construct appears.

@LilithHafner LilithHafner added test This change adds or pertains to unit tests domain:display and printing Aesthetics and correctness of printed representations of objects. labels Apr 29, 2024
test/show.jl Outdated Show resolved Hide resolved
@@ -248,6 +248,8 @@ end
@test repr(:(∓ 1)) == ":(∓1)"
@test repr(:(± 1)) == ":(±1)"

eval_parse_repr(x) = eval(Meta.parse(repr(x)))
eval_parse_repr_test(x) = @test eval_parse_repr(x) == x
Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes the line numbers reported by a test failure worse.

julia> using Test

julia> @test 1==2
Test Failed at REPL[2]:1 <---- Just entered
  Expression: 1 == 2
   Evaluated: 1 == 2

ERROR: There was an error during testing

julia> @test 1==3
Test Failed at REPL[3]:1 <---- Just entered
  Expression: 1 == 3
   Evaluated: 1 == 3

ERROR: There was an error during testing

julia> test_eq_1(x) = @test x == 1
test_eq_1 (generic function with 1 method)

julia> test_eq_1(2)
Test Failed at REPL[4]:1 <----- where function defined
  Expression: x == 1
   Evaluated: 2 == 1

ERROR: There was an error during testing

julia> test_eq_1(3)
Test Failed at REPL[4]:1 <----- where function defined
  Expression: x == 1
   Evaluated: 3 == 1

ERROR: There was an error during testing

Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So just make it return a bool and add back the @test.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can have either line numbers or display the actual/expected values. I prefer displaying the actual/expected values (this) because we can always get line numbers from stack traces.

Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you mean? As is, this is just worse than before. Finding the line number in the stacktrace is often not easy.

Just inline it back if it is an issue. Going around DRY-ing test code is seldom a good idea.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you mean?

julia> f(x) = x == 5
f (generic function with 1 method)

julia> @test f(4)
Test Failed at REPL[15]:1
  Expression: f(4)

ERROR: There was an error during testing

julia> g(x) = @test x == 5
g (generic function with 1 method)

julia> g(4)
Test Failed at REPL[16]:1
  Expression: x == 5
   Evaluated: 4 == 5

ERROR: There was an error during testing

Copy link
Sponsor Member

@KristofferC KristofferC left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should not make the errors worse than before (e.g. the line for the test failure)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
domain:display and printing Aesthetics and correctness of printed representations of objects. test This change adds or pertains to unit tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants