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

Allow for non-unit return types #22

Merged
merged 1 commit into from
Jul 26, 2019

Conversation

Baccata
Copy link
Collaborator

@Baccata Baccata commented Jul 24, 2019

This changes the internal API to allow to return some other types than Unit, so that people can use leverage the macro to declare their own assertion functions, returing Either/Try, etc.

@Baccata
Copy link
Collaborator Author

Baccata commented Jul 24, 2019

Guess I'm gonna need some assistance for the dotty part of this ^^

@eed3si9n
Copy link
Owner

@Baccata Nice. Thanks for the contribution.

The original Recorder had a comment that suggests the original author wanted to do something similar - https://github.com/pniederw/expecty/blob/543da8cdc6b07695d7aa0d3ded6839306ebfade3/src/main/scala/org/expecty/Recorder.scala

// should have two type parameters; one for recorded type, another for returned type
// so far failed to implement the macro side of this

@Baccata
Copy link
Collaborator Author

Baccata commented Jul 25, 2019

one for recorded type

done here : 7c9fbe7

@Baccata
Copy link
Collaborator Author

Baccata commented Jul 25, 2019

@eed3si9n I've attempted fixing the dotty layer, but I'm a bit stuck :

[error] -- [E007] Type Mismatch Error: /Users/oliviermelois/lab/expecty/shared/src/main/scala-3/com/eed3si9n/expecty/RecorderMacro.scala:151:8 
[error] 151 |        Block(
[error]     |        ^
[error]     |        Found:    quoted.Expr[Any]
[error]     |        Required: quoted.Expr[A]
[error] 152 |          recordExpressions(termArg),
[error] 153 |          '{ recorderRuntime.completeRecording() }.unseal
[error] 154 |        ).seal

@Baccata
Copy link
Collaborator Author

Baccata commented Jul 25, 2019

@eed3si9n, nevermind, looks like bda6427 did the trick ^^

inline def apply(recording: Boolean): Unit =
abstract class Recorder[R, A] {
def listener: RecorderListener[R, A]
inline def apply(recording: R): Unit =

Choose a reason for hiding this comment

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

Should this return A?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

good catch 😸

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed in 4122318

@eed3si9n
Copy link
Owner

Awesome. Could you squash your commits please, and I think it's ready to merge.

This adds input/output type parameters to the Recorder :
* allows non boolean arguments to be captured
* allow non-unit types to be returned

The goal is to broaden the usage of this library, by letting people
extend the Recoder class to potentially capture other types / return
error-capable datatypes, etc
@Baccata Baccata force-pushed the allow-for-non-unit-return-types branch from 4122318 to 8e1daf7 Compare July 25, 2019 20:54
@Baccata
Copy link
Collaborator Author

Baccata commented Jul 25, 2019

Done in 8e1daf7

@eed3si9n eed3si9n merged commit 1726269 into eed3si9n:master Jul 26, 2019
@Baccata Baccata deleted the allow-for-non-unit-return-types branch July 26, 2019 06:10
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