Skip to content

Make #[files(...)] work on Windows#322

Merged
la10736 merged 2 commits intola10736:masterfrom
twz123:windows-support
Jul 26, 2025
Merged

Make #[files(...)] work on Windows#322
la10736 merged 2 commits intola10736:masterfrom
twz123:windows-support

Conversation

@twz123
Copy link
Copy Markdown
Contributor

@twz123 twz123 commented Jul 21, 2025

The resolver produces canonicalized paths, which have the verbatim path prefix \\?\ on Windows. This caused the calculation of relative paths to break, resulting in strange test names being generated.

As a workaround, canonicalize the base path as well, so that it gets the prefix, too. This makes relative path resolution work again. As a consequence, though, we need to ignore not found errors during canonicalization. Some tests use fake resolvers which produce non-existing paths. Ignoring not found errors makes them pass.

Also, fix the tests so that they work on Windows. There have been many hard-coded slashes, and often, paths have been injected into contexts where backslashes need to be escaped, such as in TOML strings, regular expressions, or Rust code.

Fixes #287.

twz123 added 2 commits July 21, 2025 14:07
The resolver produces canonicalized paths, which have the verbatim path
prefix "\\?\" on Windows. This caused the calculation of relative paths
to break, resulting in strange test names being generated.

As a workaround, canonicalize the base path as well, so that it
gets the prefix, too. This makes relative path resolution work
again. As a consequence, though, we need to ignore not found errors
during canonicalization. Some tests use fake resolvers which produce
non-existing paths. Ignoring not found errors makes them pass.

Also, fix the tests so that they work on Windows. There have been many
hard-coded slashes, and often, paths have been injected into contexts
where backslashes need to be escaped, such as in TOML strings, regular
expressions, or Rust code.

Signed-off-by: Tom Wieczorek <tom@bibbu.net>
Signed-off-by: Tom Wieczorek <tom@bibbu.net>
@twz123 twz123 force-pushed the windows-support branch from b672f64 to 8c84aff Compare July 21, 2025 12:07
Copy link
Copy Markdown
Owner

@la10736 la10736 left a comment

Choose a reason for hiding this comment

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

GREAT WORK!!!!!

Thanks

Comment on lines +41 to +51
env:
RSTEST_TEST_CHANNEL: stable
run: cargo test --all --verbose
- name: Run tests beta
run: RSTEST_TEST_CHANNEL=beta cargo test --all --verbose
env:
RSTEST_TEST_CHANNEL: beta
run: cargo test --all --verbose
- name: Run tests nightly
run: RSTEST_TEST_CHANNEL=nightly cargo test --all --verbose
env:
RSTEST_TEST_CHANNEL: nightly
run: cargo test --all --verbose
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Thanks... much better.

Comment on lines +19 to +23
strategy:
matrix:
runs-on:
- ubuntu-latest
- windows-latest
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

I'm trying to avoid windows at all... but you're right, I really need it.

Comment on lines +8 to +15
const SRC_LIB_RS: &str = {
const SEP: u8 = std::path::MAIN_SEPARATOR as u8;
const SRC_LIB_RS: [u8; 11] = [
SEP, b's', b'r', b'c', SEP, b'l', b'i', b'b', b'.', b'r', b's',
];
unsafe { std::str::from_utf8_unchecked(&SRC_LIB_RS) }
};

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Sure there isn't any simpler way to make a portable static path? Maybe use OnceLock or a function to get it is better, it's test code: performance is a detail against readability.

Comment on lines 589 to +591
let base_dir = match refs.base_dir()? {
Some(mut p) => {
if p.is_relative() {
p = default_base_dir.join(p);
}
p.canonicalize().map_err(|e| {
refs.glob[0].error(&format!("Cannot canonicalize base dir due {e}"))
})?
}
Some(p) if p.is_relative() => default_base_dir.join(p),
Some(p) => p,
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Right nicer

@la10736 la10736 merged commit 80f0b95 into la10736:master Jul 26, 2025
3 checks passed
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.

#[files] produces incorrect test names on Windows

2 participants