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

📎 Small refactor for the test infrastructure of biome_cli #669

Closed
ematipico opened this issue Nov 4, 2023 · 3 comments
Closed

📎 Small refactor for the test infrastructure of biome_cli #669

ematipico opened this issue Nov 4, 2023 · 3 comments
Assignees
Labels
A-CLI Area: CLI A-Tooling Area: internal tools good first issue Good for newcomers S-Help-wanted Status: you're familiar with the code base and want to help the project

Comments

@ematipico
Copy link
Member

ematipico commented Nov 4, 2023

Description

I recently created a small utility:

pub fn assert_file_contents(fs: &MemoryFileSystem, path: &Path, expected_content: &str) {
let mut file = fs.open(path).expect("file was removed");
let mut content = String::new();
file.read_to_string(&mut content)
.expect("failed to read file from memory FS");
assert_eq!(
content,
expected_content,
"file {} doesn't match the expected content",
path.display()
);
}

This utility is used to make assertions around file contents easier and less code repetition.

The task is to replace code like this:

let mut file = fs
.open(file_path)
.expect("formatting target file was removed by the CLI");
let mut content = String::new();
file.read_to_string(&mut content)
.expect("failed to read file from memory FS");
assert_eq!(content, UNFORMATTED);
drop(file);

And replace it with the usage of the utility.

If/when working on it, search for drop( inside the tests, and that's where you want to do the substitution.

All tests must pass, and all snapshots must stay the same. If anything changes, something went wrong.

@ematipico ematipico added good first issue Good for newcomers S-Help-wanted Status: you're familiar with the code base and want to help the project A-CLI Area: CLI A-Tooling Area: internal tools labels Nov 4, 2023
@msdlisper
Copy link
Contributor

It does reduce a lot of boilerplate code, can I try to accomplish this task?

@Conaclos
Copy link
Member

Conaclos commented Nov 4, 2023

@msdlisper You are welcome :)

@msdlisper
Copy link
Contributor

@Conaclos Could you check the code for me? :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-CLI Area: CLI A-Tooling Area: internal tools good first issue Good for newcomers S-Help-wanted Status: you're familiar with the code base and want to help the project
Projects
None yet
Development

No branches or pull requests

3 participants