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

Convert FakeClock to a struct. #71

Merged
merged 1 commit into from
Jul 17, 2023
Merged

Convert FakeClock to a struct. #71

merged 1 commit into from
Jul 17, 2023

Conversation

DPJacques
Copy link
Collaborator

@DPJacques DPJacques commented Jul 17, 2023

This change ensures future modifications to FakeClock will not break users.

However, this change does break current users who use FakeClock as an argument, return value, or embed it in a struct or interface.

With limtied exception, build errors can be fixed by running:

$ grep -rl 'clockwork.FakeClock' /path/to/code_base | \
    xargs sed -i 's/clockwork.FakeClock/*clockwork.FakeClock/g'

Other rare build errors and their fixes are:

  • When returning a pointer to concrete type as a clockwork.FakeClock: return the pointer to concrete type instead.
  • When using clockwork.FakeClock in an interface composition: replace with the functions required by the interface.
  • When using clockwork.FakeClock as an argument, replace with concrete type or define a new interface.

The alternative approach would have been to use type aliases. However, this does not provide a benefit over direct replacement, because the migration is more complicated, harder to execute, needs to be done to the same code points, and results in runtime failures when type converting (whereas this approach only fails at compile-time).

This change ensures future modifications to FakeClock will not break users.

However, this change does break current users who use FakeClock as an argument,
return value, or embed it in a struct or interface.

With limtied exception, build errors can be fixed by running:
```
$ grep -rl 'clockwork.FakeClock' /path/to/code_base | \
    xargs sed -i 's/clockwork.FakeClock/*clockwork.FakeClock/g'
```

Other errors and their fixes are:
- When returning a pointer to concrete type as a clockwork.FakeClock: return
  the pointer to concrete type.
- When using FakeClock in an interface composition: relace with the functions
  required by the interface.
- When using FakeClock as an argument, replace with concerete type or define a
  new interface.

The anternative approach would have been to use type alaises. However, this
does not provide a benefit over direct replacement, because the migration is
more complicated, harder to execute, needs to be done to the same code points,
and results in runtime failures (whereas this approach can be complie-time
checked).
@DPJacques DPJacques added enhancement release-note/breaking-change Release note: Breaking Changes release-note/enhancement Release note: Enhancements labels Jul 17, 2023
@DPJacques DPJacques merged commit b120971 into master Jul 17, 2023
8 checks passed
@DPJacques DPJacques deleted the struct branch June 3, 2024 03:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement release-note/breaking-change Release note: Breaking Changes release-note/enhancement Release note: Enhancements
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant