Skip to content

Commit 8d05562

Browse files
committed
Hide C-string tests from old toolchain versions
1 parent 7c92efb commit 8d05562

File tree

5 files changed

+42
-25
lines changed

5 files changed

+42
-25
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424
strategy:
2525
fail-fast: false
2626
matrix:
27-
rust: [nightly, beta, stable, 1.76.0, 1.60.0]
27+
rust: [nightly, beta, stable, 1.77.0, 1.76.0, 1.60.0]
2828
timeout-minutes: 45
2929
steps:
3030
- uses: actions/checkout@v5

Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ categories = ["rust-patterns", "text-processing", "no-std", "no-std::no-alloc"]
66
description = "Indented document literals"
77
documentation = "https://docs.rs/indoc"
88
edition = "2021"
9+
exclude = ["build.rs"]
910
keywords = ["heredoc", "nowdoc", "multiline", "string", "literal"]
1011
license = "MIT OR Apache-2.0"
1112
repository = "https://github.com/dtolnay/indoc"
@@ -19,6 +20,9 @@ rustversion = "1.0"
1920
trybuild = { version = "1.0.108", features = ["diff"] }
2021
unindent = { version = "0.2.3", path = "unindent" }
2122

23+
[build-dependencies]
24+
rustversion = "1.0"
25+
2226
[workspace]
2327
members = ["unindent"]
2428

build.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
fn main() {
2+
// Warning: build.rs is not published to crates.io.
3+
4+
println!("cargo:rustc-check-cfg=cfg(indoc_test_cstr)");
5+
6+
if rustversion::cfg!(since(1.77)) {
7+
println!("cargo:rustc-cfg=indoc_test_cstr");
8+
}
9+
}

tests/test_cstr/mod.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
use indoc::indoc;
2+
3+
#[test]
4+
fn c_string() {
5+
let indoc = indoc! {c"
6+
a
7+
8+
\\b
9+
c"
10+
};
11+
let expected = c"a\n\n \\b\nc";
12+
assert_eq!(indoc, expected);
13+
}
14+
15+
#[test]
16+
fn raw_c_string() {
17+
let indoc = indoc! {cr#"
18+
"a"
19+
20+
\\b
21+
c"#
22+
};
23+
let expected = c"\"a\"\n\n \\\\b\nc";
24+
assert_eq!(indoc, expected);
25+
}

tests/test_indoc.rs

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
#[cfg(indoc_test_cstr)]
2+
mod test_cstr;
3+
14
use indoc::indoc;
25

36
const HELP: &str = indoc! {"
@@ -29,18 +32,6 @@ fn carriage_return() {
2932
assert_eq!(indoc, expected);
3033
}
3134

32-
#[test]
33-
fn c_string() {
34-
let indoc = indoc! {c"
35-
a
36-
37-
\\b
38-
c"
39-
};
40-
let expected = c"a\n\n \\b\nc";
41-
assert_eq!(indoc, expected);
42-
}
43-
4435
#[test]
4536
fn empty_string() {
4637
let indoc = indoc! {""};
@@ -125,18 +116,6 @@ fn raw_byte_string() {
125116
assert_eq!(indoc, expected);
126117
}
127118

128-
#[test]
129-
fn raw_c_string() {
130-
let indoc = indoc! {cr#"
131-
"a"
132-
133-
\\b
134-
c"#
135-
};
136-
let expected = c"\"a\"\n\n \\\\b\nc";
137-
assert_eq!(indoc, expected);
138-
}
139-
140119
#[test]
141120
fn raw_string() {
142121
let indoc = indoc! {r#"

0 commit comments

Comments
 (0)