windows: Fix tests on Windows (#22616)
Release Notes: - N/A --------- Co-authored-by: Mikayla <mikayla.c.maki@gmail.com>
This commit is contained in:
parent
c252b5db16
commit
74c4dbd237
56 changed files with 1540 additions and 856 deletions
18
crates/util_macros/Cargo.toml
Normal file
18
crates/util_macros/Cargo.toml
Normal file
|
@ -0,0 +1,18 @@
|
|||
[package]
|
||||
name = "util_macros"
|
||||
version = "0.1.0"
|
||||
edition.workspace = true
|
||||
publish.workspace = true
|
||||
license = "GPL-3.0-or-later"
|
||||
|
||||
[lints]
|
||||
workspace = true
|
||||
|
||||
[lib]
|
||||
path = "src/util_macros.rs"
|
||||
proc-macro = true
|
||||
doctest = false
|
||||
|
||||
[dependencies]
|
||||
quote.workspace = true
|
||||
syn.workspace = true
|
1
crates/util_macros/LICENSE-APACHE
Symbolic link
1
crates/util_macros/LICENSE-APACHE
Symbolic link
|
@ -0,0 +1 @@
|
|||
../../LICENSE-APACHE
|
56
crates/util_macros/src/util_macros.rs
Normal file
56
crates/util_macros/src/util_macros.rs
Normal file
|
@ -0,0 +1,56 @@
|
|||
#![cfg_attr(not(target_os = "windows"), allow(unused))]
|
||||
|
||||
use proc_macro::TokenStream;
|
||||
use quote::quote;
|
||||
use syn::{parse_macro_input, LitStr};
|
||||
|
||||
/// This macro replaces the path separator `/` with `\` for Windows.
|
||||
/// But if the target OS is not Windows, the path is returned as is.
|
||||
///
|
||||
/// # Example
|
||||
/// ```rust
|
||||
/// # use util_macros::separator;
|
||||
/// let path = separator!("path/to/file");
|
||||
/// #[cfg(target_os = "windows")]
|
||||
/// assert_eq!(path, "path\\to\\file");
|
||||
/// #[cfg(not(target_os = "windows"))]
|
||||
/// assert_eq!(path, "path/to/file");
|
||||
/// ```
|
||||
#[proc_macro]
|
||||
pub fn separator(input: TokenStream) -> TokenStream {
|
||||
let path = parse_macro_input!(input as LitStr);
|
||||
let path = path.value();
|
||||
|
||||
#[cfg(target_os = "windows")]
|
||||
let path = path.replace("/", "\\");
|
||||
|
||||
TokenStream::from(quote! {
|
||||
#path
|
||||
})
|
||||
}
|
||||
|
||||
/// This macro replaces the path prefix `file:///` with `file:///C:/` for Windows.
|
||||
/// But if the target OS is not Windows, the URI is returned as is.
|
||||
///
|
||||
/// # Example
|
||||
/// ```rust
|
||||
/// use util_macros::uri;
|
||||
///
|
||||
/// let uri = uri!("file:///path/to/file");
|
||||
/// #[cfg(target_os = "windows")]
|
||||
/// assert_eq!(uri, "file:///C:/path/to/file");
|
||||
/// #[cfg(not(target_os = "windows"))]
|
||||
/// assert_eq!(uri, "file:///path/to/file");
|
||||
/// ```
|
||||
#[proc_macro]
|
||||
pub fn uri(input: TokenStream) -> TokenStream {
|
||||
let uri = parse_macro_input!(input as LitStr);
|
||||
let uri = uri.value();
|
||||
|
||||
#[cfg(target_os = "windows")]
|
||||
let uri = uri.replace("file:///", "file:///C:/");
|
||||
|
||||
TokenStream::from(quote! {
|
||||
#uri
|
||||
})
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue