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

added automatic keyword assignment support to test macro #38270

Merged
merged 6 commits into from
Jan 7, 2021

Conversation

DebadityaPal
Copy link
Contributor

@DebadityaPal DebadityaPal commented Nov 2, 2020

As seen in #38215 , while passing keywords without assignment to test macro, the keyword is ignored. In these cases the keyword is passed as a Symbol in the metaprogram, I modified the macro functions so that it does not get ignored.
fixes #38215

@DebadityaPal DebadityaPal changed the title added automatic keyword assignment support to @test macro added automatic keyword assignment support to test macro Nov 2, 2020
@simeonschaub
Copy link
Member

Awesome, looks good to me! Could you also add a test for this case? Have a look in stdlib/Test/test/runtests.jl, there are already some tests cases with isapprox there.

@simeonschaub simeonschaub added needs tests Unit tests are required for this change testsystem The unit testing framework and Test stdlib kind:bugfix This change fixes an existing bug labels Nov 2, 2020
@DebadityaPal
Copy link
Contributor Author

Sure, I shall add the necessary tests.

@DebadityaPal
Copy link
Contributor Author

The required tests have been added.

@simeonschaub simeonschaub removed the needs tests Unit tests are required for this change label Nov 2, 2020
@JeffBezanson
Copy link
Sponsor Member

I don't understand the purpose of this whole block of code --- the escaped_kwargs get moved into a :parameters expression, which will also interpret them as keyword arguments, so why do the argument expressions need to be transformed? Replicating these cases from lowering is brittle. (Also missing the a.x => x = a.x case.)

@simeonschaub
Copy link
Member

I think kwargs are normalized to enable pretty printing for failed tests, where the actual values passed to a function call get interpolated for printing. E.g., this produces the following output:

julia> using Test

julia> a, b = 1, 2
(1, 2)

julia> @test isapprox(a, b, rtol=a/10)
Test Failed at REPL[62]:1
  Expression: isapprox(a, b, rtol = a / 10)
   Evaluated: isapprox(1, 2; rtol = 0.1)
ERROR: There was an error during testing

I don't think there's a much better way around doing this transformation for the automatic keyword assignment syntax. The ; a.x case is a good point though, that should also be added.

@JeffBezanson
Copy link
Sponsor Member

I see. We don't need to refactor this now but it would be better to "parse" the arguments out of the expression just once, instead of parsing, re-forming an Expr, and then re-parsing in eval_test.

@DebadityaPal
Copy link
Contributor Author

Actually when the argument expression contains an unassigned keyword like @test isapprox(1,2; atol) here atol is parsed as a symbol and not as a keyword. The first round of parsing allows us to explicitly set that along with the other keywords before evaluating the Expr. Also i am slightly confused with the a.x syntax, could you just show me an example and then i can start working on it.

@simeonschaub
Copy link
Member

simeonschaub commented Nov 4, 2020

here atol is parsed as a symbol and not as a keyword

Yes, semantically it's a keyword argument, but you are right, in the AST it's just a symbol.

Also i am slightly confused with the a.x syntax, could you just show me an example and then i can start working on it.

The basic gist is that isapprox(x, y; a.atol) is lowered to be the same as isapprox(x, y; atol=a.atol) (a could be defined as a = (; atol = 0.1), for example). See #34331 for more details.

@simeonschaub
Copy link
Member

@DebadityaPal Do you want to update this for the ; a.x case as well? Alternatively, I think we could also just merge this now and address that in a separate PR.

@simeonschaub simeonschaub added this to the 1.6 blockers milestone Jan 7, 2021
@simeonschaub simeonschaub added backport 1.5 backport 1.6 Change should be backported to release-1.6 labels Jan 7, 2021
@DebadityaPal
Copy link
Contributor Author

I would prefer to work on that issue over a second PR, as it could take me some time and it wouldn't be fruitful if the current changes are put on hold for that.

@simeonschaub simeonschaub reopened this Jan 7, 2021
@DebadityaPal
Copy link
Contributor Author

Nevermind my previous comment, I have added the a.x syntax and a unit test to go with it.

@simeonschaub
Copy link
Member

Awesome, thank you!

@simeonschaub simeonschaub added the status:merge me PR is reviewed. Merge when all tests are passing label Jan 7, 2021
Co-authored-by: Simeon Schaub <[email protected]>
@simeonschaub simeonschaub merged commit 6c42190 into JuliaLang:master Jan 7, 2021
@DebadityaPal DebadityaPal deleted the dp/test_macro_update branch January 8, 2021 06:00
KristofferC pushed a commit that referenced this pull request Jan 9, 2021
* added automatic keyword assignment support to @test macro

* added some tests for test macro using atol keyword

* x = a.x syntax support added

* Update stdlib/Test/src/Test.jl

Co-authored-by: Simeon Schaub <[email protected]>

Co-authored-by: Simeon Schaub <[email protected]>
(cherry picked from commit 6c42190)
@DilumAluthge DilumAluthge removed the status:merge me PR is reviewed. Merge when all tests are passing label Jan 11, 2021
@vchuravy vchuravy mentioned this pull request Jan 21, 2021
27 tasks
vchuravy pushed a commit that referenced this pull request Jan 21, 2021
* added automatic keyword assignment support to @test macro

* added some tests for test macro using atol keyword

* x = a.x syntax support added

* Update stdlib/Test/src/Test.jl

Co-authored-by: Simeon Schaub <[email protected]>

Co-authored-by: Simeon Schaub <[email protected]>
(cherry picked from commit 6c42190)
@KristofferC KristofferC removed the backport 1.6 Change should be backported to release-1.6 label Feb 1, 2021
KristofferC pushed a commit that referenced this pull request Feb 1, 2021
* added automatic keyword assignment support to @test macro

* added some tests for test macro using atol keyword

* x = a.x syntax support added

* Update stdlib/Test/src/Test.jl

Co-authored-by: Simeon Schaub <[email protected]>

Co-authored-by: Simeon Schaub <[email protected]>
(cherry picked from commit 6c42190)
ElOceanografo pushed a commit to ElOceanografo/julia that referenced this pull request May 4, 2021
…8270)

* added automatic keyword assignment support to @test macro

* added some tests for test macro using atol keyword

* x = a.x syntax support added

* Update stdlib/Test/src/Test.jl

Co-authored-by: Simeon Schaub <[email protected]>

Co-authored-by: Simeon Schaub <[email protected]>
staticfloat pushed a commit that referenced this pull request Dec 23, 2022
* added automatic keyword assignment support to @test macro

* added some tests for test macro using atol keyword

* x = a.x syntax support added

* Update stdlib/Test/src/Test.jl

Co-authored-by: Simeon Schaub <[email protected]>

Co-authored-by: Simeon Schaub <[email protected]>
(cherry picked from commit 6c42190)
vchuravy pushed a commit to JuliaLang/Test.jl that referenced this pull request Oct 7, 2023
…ulia#38270)

* added automatic keyword assignment support to @test macro

* added some tests for test macro using atol keyword

* x = a.x syntax support added

* Update stdlib/Test/src/Test.jl

Co-authored-by: Simeon Schaub <[email protected]>

Co-authored-by: Simeon Schaub <[email protected]>
(cherry picked from commit 740c19d)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind:bugfix This change fixes an existing bug testsystem The unit testing framework and Test stdlib
Projects
None yet
Development

Successfully merging this pull request may close these issues.

kwargs bug in Test.@test
6 participants