Fix failing test under Windows - #529
Conversation
Replace `NamedTempFile` with a regular file inside a `TempDir`, so the file is closed and can be renamed or replaced by in-place editing on Windows. `TempDir` also simplifies cleanup by automatically removing the file, backup, and directory when dropped.
|
sure, thanks |
There was a problem hiding this comment.
Pull request overview
Warning
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
This PR updates sed in-place editing tests to avoid Windows file-handle/rename issues by replacing NamedTempFile usage with a closed regular file inside a TempDir.
Changes:
- Replace
NamedTempFilewithtempfile::tempdir()+std::fs::write()to ensure files are closed before in-place editing. - Rely on
TempDirdrop for cleanup instead of manually closing/removing temp and backup files.
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
|
|
||
| // Get the file path before converting to TempPath | ||
| let path = temp.path().to_path_buf(); | ||
| std::fs::write(&path, "hello, world\n")?; |
|
|
||
| let path = temp.path().to_path_buf(); | ||
| let temp_path = temp.into_temp_path(); | ||
| std::fs::write(&path, b"hello, world\n")?; |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #529 +/- ##
=======================================
Coverage 83.18% 83.18%
=======================================
Files 13 13
Lines 7001 7001
Branches 398 398
=======================================
Hits 5824 5824
Misses 1174 1174
Partials 3 3
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Replace
NamedTempFilewith a regular file inside aTempDir, so the file is closed and can be renamed or replaced by in-place editing on Windows.TempDiralso simplifies cleanup by automatically removing the file, backup, and directory when dropped.@sylvestre : Let's wait for all the CI results before merging this. The tests used to work fine. In the F command CI one of the tests when run for the coverage analysis failed, so this attempts to fix them with more robust handling of temporary files.