Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@dkarlinsky
Copy link
Contributor

@dkarlinsky dkarlinsky commented Nov 21, 2020

image

Most tests verifying assert output are failing and need to be fixed.

@dkarlinsky dkarlinsky changed the title zio-test: make assert captures expression and source location using macro zio-test: make assert capture expression and source location using macro Nov 21, 2020
@adamgfraser
Copy link
Contributor

@dkarlinsky Great! How does this interrelate with #4242 by @hmemcpy?

@dkarlinsky
Copy link
Contributor Author

It doesn't yet. We talked about it and agreed that I'd rebase on top of @hmemcpy 's PR, once it's merged.

@adamgfraser
Copy link
Contributor

@dkarlinsky @hmemcpy Can we circle up on the two open PRs we have on this? It seems like this PR has a way of capturing the source information that results in fewer changes to the public API. @hmemcpy Does the way the information is being captured here give you the ability to access it and do what you want with it?

@hmemcpy
Copy link
Contributor

hmemcpy commented Nov 24, 2020

I need to take a better look at this, but I think this could work for my case too! It seems to be extracting the location from the tree rather than capturing it in a separate object... Might work! This would mean I'd have to have to change the implementation of test and testM to point to the private macro-based implementation, but their public signature wouldn't change!

I'll experiment with it. Thanks!

@dkarlinsky
Copy link
Contributor Author

It doesn't yet. We talked about it and agreed that I'd rebase on top of @hmemcpy 's PR, once it's merged.

Looking at @hmemcpy 's PR again, there doesn't seem to be an actual overlap in code.
So maybe they can proceed in parallel

@hmemcpy
Copy link
Contributor

hmemcpy commented Nov 24, 2020

I want to give it a try your way, capture the Tree of the label element of test/testM, so I don't have to introduce the implicit parameter. I can piggyback off your changes, so if you can finish this PR, I'll rebase mine on top instead!

@adamgfraser
Copy link
Contributor

adamgfraser commented Nov 24, 2020

@dkarlinsky You've definitely tackled it slightly different ways but are trying to address similar goals. Anyway, I think the approach suggested by @hmemcpy makes sense.

@hmemcpy
Copy link
Contributor

hmemcpy commented Nov 24, 2020

So good news - it indeed works! I was able to capture the location info of the test/testM inside a macro without needing to change the public API!

This means that similarly to assert, the test methods will move into the CompileVariant interface, implemented by a macro that will call into the original implementation, but augmenting it with the location.

I'd still like to put my changes in next, are you close to finishing the PR, @dkarlinsky?

@dkarlinsky
Copy link
Contributor Author

dkarlinsky commented Nov 24, 2020

So good news - it indeed works! I was able to capture the location info of the test/testM inside a macro without needing to change the public API!

This means that similarly to assert, the test methods will move into the CompileVariant interface, implemented by a macro that will call into the original implementation, but augmenting it with the location.

I'd still like to put my changes in next, are you close to finishing the PR, @dkarlinsky?

Just need to fix all the broken testis in DefaultTestReporterSpec and SummaryBuilderSpec that verify assert output.
Might be a little tricky, as now the output includes the absolute path to the source file.
(I would really prefer to make the path relative to the source root, but can't find anything in macro reflect api that helps figure out what the root is)

@hmemcpy
Copy link
Contributor

hmemcpy commented Nov 24, 2020

I think if you keep just the filename, IntelliJ will be smart enough to hyperlink it anyway. Not sure this would work for the console output. But I agree, relative path to the source would be better.

@dkarlinsky
Copy link
Contributor Author

I think if you keep just the filename, IntelliJ will be smart enough to hyperlink it anyway. Not sure this would work for the console output. But I agree, relative path to the source would be better.

Didn't work for me in console output - if it's just the file name, no hyperlink :(

@dkarlinsky dkarlinsky force-pushed the zio-test-assert-macro branch from baebdd3 to 051cd77 Compare November 26, 2020 09:43
@dkarlinsky dkarlinsky marked this pull request as ready for review November 26, 2020 09:45
@hmemcpy
Copy link
Contributor

hmemcpy commented Nov 26, 2020

Hallelujah 🤣

@dkarlinsky
Copy link
Contributor Author

Hallelujah 🤣

Yay! Finally! 😅

@hmemcpy
Copy link
Contributor

hmemcpy commented Nov 27, 2020

@adamgfraser would love if you could take a look.

Copy link
Contributor

@adamgfraser adamgfraser left a comment

Choose a reason for hiding this comment

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

I think this looks really good!

For the rendering of the results, right now we're also labeling the assert with the left hand side of the assertion. Do you think that is necessary or maybe we can just render the line of the failing test as a new line? Just wondering if it could be confusing if users can add their own labeling and now we are adding this labeling? Also happy to address the rendering in a follow up PR.

image

@dkarlinsky
Copy link
Contributor Author

I think this looks really good!

For the rendering of the results, right now we're also labeling the assert with the left hand side of the assertion. Do you think that is necessary or maybe we can just render the line of the failing test as a new line? Just wondering if it could be confusing if users can add their own labeling and now we are adding this labeling? Also happy to address the rendering in a follow up PR.

image

@adamgfraser
I'm not crazy about the way it is rendered either. Adding a label to the assert was just the easiest way to do this.
Ideally I think the label (expression + source location) should go into AssertionValue as a new field, not on the Assertion that it contains.
And yes, I would prefer to address this as a separate PR.

@adamgfraser
Copy link
Contributor

@dkarlinsky Sounds good to me!

@adamgfraser adamgfraser merged commit 94b896f into zio:master Nov 27, 2020
atooni pushed a commit to blended-zio/zio that referenced this pull request Dec 1, 2020
…macro (zio#4427)

* zio-test|assert captures expression and source location using macro

* prepend `_root_` in macros; fix; fmt

* rename `zio.test.assertRuntime` to `assertImpl` and made it package private

* DefaultTestReporterSpec passes for 2.x and dotty

* fixing line numbers after fix and fmt

* fixed ZTestFrameworkSpec;
ignoring line numbers in test output - otherwise the tests get too brittle.

* fixed SummaryBuilderSpec

* fixed MavenJunitSpec

* fix + fmt

* fixing fatal "unused import" in 2.13

* dropping lihaoyi sourcecode dependency in favor of small local macro

* fixing ZTestFrameworkSpec for scala 3

* fix linesIterator deprecation in 2.11
@dkarlinsky dkarlinsky deleted the zio-test-assert-macro branch January 6, 2021 11:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants