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

Canonicalize paths to fix path matching #143

Merged
merged 3 commits into from
Apr 13, 2019

Conversation

cjpearce
Copy link
Contributor

This PR should fix #126. The main solution to the issue was using canonicalize() on the paths we create for the exercises from info.toml and any user-specified paths, so that path ends_with matching will work correctly.

As adding calls to the canonicalize function everywhere requires unwrapping, I also decided to extract a struct representing an exercise and use serde to deserialize the paths from the info.toml file up front. I also tried to move the path handling out into the exercise.rs file and down into main.rs so that it doesn't create as much clutter. There was already a lot of unwrapping and path handling in the other files and I felt like it was getting a bit too repetitive.

If the approach is going too far (too many changes etc.) I'm happy to try to produce a smaller PR that fixes the bug without any refactoring.

@cjpearce cjpearce changed the title Extract exercise struct to encapsulate path logic Canonicalize on paths to fix path matching Apr 11, 2019
@cjpearce cjpearce changed the title Canonicalize on paths to fix path matching Canonicalize paths to fix path matching Apr 11, 2019
@cjpearce cjpearce force-pushed the fix-exercise-path-matching branch from 848922a to d01a71f Compare April 12, 2019 07:58
@cjpearce
Copy link
Contributor Author

After doing some more testing, I've discovered that I've created a panic when an incorrect filename is supplied. I'll tidy up the error handling to avoid this.

Copy link
Contributor

@komaeda komaeda left a comment

Choose a reason for hiding this comment

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

Thanks so much for DRYing this code up a bit! Some tiny nits and the thing you mentioned, and then we should be good to go!

src/exercise.rs Outdated

#[test]
fn test_clean() {
std::fs::File::create(&temp_file()).unwrap();
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it's fine to use this

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've tried to clean that up a bit by adding a use declaration in a test module. Putting the use at the top gives 'unused' warnings when doing a normal build. I couldn't spot a clear convention for this situation online but I'm open to suggestions if you have any ideas. I'm mainly trying to keep that test alive since it was in the original utilities.rs file.

src/exercise.rs Outdated
mode: Mode::Test,
};
exercise.clean();
assert!(!std::path::Path::new(&temp_file()).exists());
Copy link
Contributor

Choose a reason for hiding this comment

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

same as above

@komaeda
Copy link
Contributor

komaeda commented Apr 13, 2019

@bors r+

@bors
Copy link
Contributor

bors commented Apr 13, 2019

📌 Commit 77de6e5 has been approved by komaeda

@bors
Copy link
Contributor

bors commented Apr 13, 2019

⌛ Testing commit 77de6e5 with merge 8387de6...

bors added a commit that referenced this pull request Apr 13, 2019
Canonicalize paths to fix path matching

This PR should fix #126. The main solution to the issue was using `canonicalize()` on the paths we create for the exercises from `info.toml` and any user-specified paths, so that path `ends_with` matching will work correctly.

As adding calls to the canonicalize function everywhere requires unwrapping, I also decided to extract a struct representing an exercise and use serde to deserialize the paths from the `info.toml` file up front. I also tried to move the path handling out into the `exercise.rs` file and down into `main.rs` so that it doesn't create as much clutter. There was already a lot of unwrapping and path handling in the other files and I felt like it was getting a bit too repetitive.

If the approach is going too far (too many changes etc.) I'm happy to try to produce a smaller PR that fixes the bug without any refactoring.
@bors
Copy link
Contributor

bors commented Apr 13, 2019

☀️ Test successful - checks-travis
Approved by: komaeda
Pushing 8387de6 to master...

@bors bors merged commit 77de6e5 into rust-lang:master Apr 13, 2019
pedantic79 pushed a commit to pedantic79/rustlings that referenced this pull request Apr 11, 2020
…komaeda

Canonicalize paths to fix path matching

This PR should fix rust-lang#126. The main solution to the issue was using `canonicalize()` on the paths we create for the exercises from `info.toml` and any user-specified paths, so that path `ends_with` matching will work correctly.

As adding calls to the canonicalize function everywhere requires unwrapping, I also decided to extract a struct representing an exercise and use serde to deserialize the paths from the `info.toml` file up front. I also tried to move the path handling out into the `exercise.rs` file and down into `main.rs` so that it doesn't create as much clutter. There was already a lot of unwrapping and path handling in the other files and I felt like it was getting a bit too repetitive.

If the approach is going too far (too many changes etc.) I'm happy to try to produce a smaller PR that fixes the bug without any refactoring.
ppp3 pushed a commit to ppp3/rustlings that referenced this pull request May 23, 2022
…komaeda

Canonicalize paths to fix path matching

This PR should fix rust-lang#126. The main solution to the issue was using `canonicalize()` on the paths we create for the exercises from `info.toml` and any user-specified paths, so that path `ends_with` matching will work correctly.

As adding calls to the canonicalize function everywhere requires unwrapping, I also decided to extract a struct representing an exercise and use serde to deserialize the paths from the `info.toml` file up front. I also tried to move the path handling out into the `exercise.rs` file and down into `main.rs` so that it doesn't create as much clutter. There was already a lot of unwrapping and path handling in the other files and I felt like it was getting a bit too repetitive.

If the approach is going too far (too many changes etc.) I'm happy to try to produce a smaller PR that fixes the bug without any refactoring.
dmoore04 pushed a commit to dmoore04/rustlings that referenced this pull request Sep 11, 2022
…komaeda

Canonicalize paths to fix path matching

This PR should fix rust-lang#126. The main solution to the issue was using `canonicalize()` on the paths we create for the exercises from `info.toml` and any user-specified paths, so that path `ends_with` matching will work correctly.

As adding calls to the canonicalize function everywhere requires unwrapping, I also decided to extract a struct representing an exercise and use serde to deserialize the paths from the `info.toml` file up front. I also tried to move the path handling out into the `exercise.rs` file and down into `main.rs` so that it doesn't create as much clutter. There was already a lot of unwrapping and path handling in the other files and I felt like it was getting a bit too repetitive.

If the approach is going too far (too many changes etc.) I'm happy to try to produce a smaller PR that fixes the bug without any refactoring.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-source Area: CLI source C-bug Category: Bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

"watch" is broken on windows
3 participants