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

Update cli_platform tests to use 'const' correctly #1753

Merged
merged 1 commit into from
May 14, 2024

Conversation

charlespierce
Copy link
Contributor

Info

The tests of the platform resolution for the various 'volta run' scenarios were using a lazily-loaded 'const' value. Clippy raised some warnings about those, as 'const' values are actually duplicated for each location they are used, so the interior mutability wasn't helpful.

It seems that the Lazy behavior was actually a way to work around the fact that Version doesn't have a 'const' constructor, however all of the fields are pub, so we can construct the values directly. This allows us to have a true const value and use it in each test without needing extra interior mutability or cloning.

Changes

  • Updated the NODE_VERSION, NPM_VERSION, and YARN_VERSION constants used in the cli_platform tests to be directly defined, rather than lazy loaded.
  • Changed all call sites to use the constants directly, instead of cloning.

Tested

  • Ran the affected tests and verified that they still pass as expected.

The tests of the platform resolution for the various 'volta run'
scenarios were using a lazily-loaded 'const' value. Clippy raised
some warnings about those, as 'const' values are actually duplicated
for each location they are used, so the interior mutability wasn't
helpful.

It seems that the `Lazy` behavior was actually a way to work around
the fact that `Version` doesn't have a 'const' constructor, however
all of the fields are `pub`, so we can construct the values directly.
This allows us to have a true `const` value and use it in each test
without needing extra interior mutability or cloning.
Copy link
Contributor

@chriskrycho chriskrycho left a comment

Choose a reason for hiding this comment

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

Love it!

@chriskrycho chriskrycho merged commit 2d899f9 into volta-cli:main May 14, 2024
11 checks passed
@charlespierce charlespierce deleted the const_borrows branch May 16, 2024 02:49
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.

None yet

2 participants