about summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
authorChris Denton <chris@chrisdenton.dev>2024-05-17 08:22:29 +0000
committerChris Denton <chris@chrisdenton.dev>2024-07-31 12:44:47 +0000
commitedc97a0df2fbff05dd03483938425d1590440c82 (patch)
tree7dff4500729076e934fb9bc8ffc3aa728e187364 /tests
parent83dcdb3a5dad0ed1e3e1fadc848d3f7727b41aa5 (diff)
downloadrust-edc97a0df2fbff05dd03483938425d1590440c82.tar.gz
rust-edc97a0df2fbff05dd03483938425d1590440c82.zip
Fix verbatim paths used with include!
When using `concat!` to join paths, the Unix path separator (`/`) is often used. This breaks on Windows if the base path is a verbatim path (i.e. starts with `\\?\`).
Diffstat (limited to 'tests')
-rw-r--r--tests/run-make/import-macro-verbatim/include/include.txt1
-rw-r--r--tests/run-make/import-macro-verbatim/rmake.rs8
-rw-r--r--tests/run-make/import-macro-verbatim/verbatim.rs12
3 files changed, 21 insertions, 0 deletions
diff --git a/tests/run-make/import-macro-verbatim/include/include.txt b/tests/run-make/import-macro-verbatim/include/include.txt
new file mode 100644
index 00000000000..63d71b14c1d
--- /dev/null
+++ b/tests/run-make/import-macro-verbatim/include/include.txt
@@ -0,0 +1 @@
+static TEST: &str = "Hello World!";
diff --git a/tests/run-make/import-macro-verbatim/rmake.rs b/tests/run-make/import-macro-verbatim/rmake.rs
new file mode 100644
index 00000000000..d2bf626e0aa
--- /dev/null
+++ b/tests/run-make/import-macro-verbatim/rmake.rs
@@ -0,0 +1,8 @@
+//@ only-windows other platforms do not have Windows verbatim paths
+use run_make_support::rustc;
+fn main() {
+    // Canonicalizing the path ensures that it's verbatim (i.e. starts with `\\?\`)
+    let mut path = std::fs::canonicalize(file!()).unwrap();
+    path.pop();
+    rustc().input("verbatim.rs").env("VERBATIM_DIR", path).run();
+}
diff --git a/tests/run-make/import-macro-verbatim/verbatim.rs b/tests/run-make/import-macro-verbatim/verbatim.rs
new file mode 100644
index 00000000000..56a83673c1f
--- /dev/null
+++ b/tests/run-make/import-macro-verbatim/verbatim.rs
@@ -0,0 +1,12 @@
+//! Include a file by concating the verbatim path using `/` instead of `\`
+
+include!(concat!(env!("VERBATIM_DIR"), "/include/include.txt"));
+fn main() {
+    assert_eq!(TEST, "Hello World!");
+
+    let s = include_str!(concat!(env!("VERBATIM_DIR"), "/include/include.txt"));
+    assert_eq!(s, "static TEST: &str = \"Hello World!\";\n");
+
+    let b = include_bytes!(concat!(env!("VERBATIM_DIR"), "/include/include.txt"));
+    assert_eq!(b, b"static TEST: &str = \"Hello World!\";\n");
+}