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

[Groundwork for #1201] Rename or remove clashing variables #1239

Merged
merged 8 commits into from
Nov 30, 2021

Conversation

lawrence-forooghian
Copy link
Collaborator

@lawrence-forooghian lawrence-forooghian commented Nov 29, 2021

What does this do?

Removes or renames some variables at the spec / describe / context level.

Does it change the behaviour of the test suite?

No, it's just a refactor (moving variable declarations inside other ones, or renaming variables).

Why are we doing this?

It’s groundwork for removing the Quick testing framework using an automated migrator tool (#1201). The migrator that I’m writing will pull all spec / describe / context level variable and function declarations in a file into a flattened file-wide list of global declarations. This might lead to clashes if multiple contexts use the same variable name. So we rename / remove things to avoid these clashes.

Note

I had hoped to avoid this step, by making the migrator automatically rename variables to avoid clashes. I had a solution almost working with swift-refactor but for some reason that tool wasn't correctly updating variable references inside helper function declarations. I decided not to investigate this further, since it would probably end up taking a lot of time for something that could be fixed relatively quickly by hand. It's a shame, though.

These variables are actually only used to set up some other variables,
so we move them inside those variables’ declarations.

The motivation for this change is that it’s groundwork for removing the
Quick testing framework using an automated migrator tool (#1201). The
migrator that I’m writing will pull all `spec` / `describe` / `context`
level local variables to a single namespace for the whole file, so we
need to avoid clashes. The easiest way in this particular case is to
just remove the variables.
The motivation here is the same as dcf3e13 — avoiding clashes when the
variables are pulled out to a file-wide namespace.
The motivation for this change is that it’s groundwork for removing the
Quick testing framework using an automated migrator tool (#1201). The
migrator that I’m writing will pull all `spec` / `describe` / `context`
level local variables outside of the class declaration and into
fileprivate global variables. But if we let the migrator hoist this
particular variable to a global with the same name, then it’ll be
shadowed by XCTestCase’s `name` property, which we don’t want.
@lawrence-forooghian lawrence-forooghian force-pushed the 1201-rename-clashing-identifiers branch from b0e3190 to f4c0e1f Compare November 29, 2021 18:42
@lawrence-forooghian lawrence-forooghian changed the title 1201 rename clashing identifiers [Groundwork for #1201] Rename or remove clashing variables Nov 29, 2021
@lawrence-forooghian lawrence-forooghian self-assigned this Nov 29, 2021
@lawrence-forooghian lawrence-forooghian marked this pull request as ready for review November 29, 2021 20:09
Copy link
Contributor

@lukasz-szyszkowski lukasz-szyszkowski left a comment

Choose a reason for hiding this comment

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

I know it's just 'beautification' of the code but if it's possible you should create extension for 'JSON' type that will encode it. I don't like code repetition for encoding.
If it's not possible just ignore this comment 😁

@lawrence-forooghian
Copy link
Collaborator Author

I know it's just 'beautification' of the code but if it's possible you should create extension for 'JSON' type that will encode it. I don't like code repetition for encoding.
If it's not possible just ignore this comment 😁

@lukasz-szyszkowski I'd quite like to keep the scope of this PR limited to just the necessary refactorings, since it's already quite a large one as it is. Perhaps you'd like to create an issue if you think it's a problem worth fixing?

@lawrence-forooghian lawrence-forooghian merged commit 0bf0031 into main Nov 30, 2021
@lawrence-forooghian lawrence-forooghian deleted the 1201-rename-clashing-identifiers branch November 30, 2021 00:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants