Skip to content

Commit 620848a

Browse files
committed
refactor(test/mock): use tuples for topical_doc_data::TEST_CASES
1 parent e19fc92 commit 620848a

File tree

2 files changed

+28
-24
lines changed

2 files changed

+28
-24
lines changed

src/test/mock/topical_doc_data.rs

+21-21
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,23 @@ use std::path::PathBuf;
33

44
// Paths are written as a string in the UNIX format to make it easy
55
// to maintain.
6-
static TEST_CASES: &[&[&str]] = &[
7-
&["core", "core/index.html"],
8-
&["core::arch", "core/arch/index.html"],
9-
&["fn", "std/keyword.fn.html"],
10-
&["keyword:fn", "std/keyword.fn.html"],
11-
&["primitive:fn", "std/primitive.fn.html"],
12-
&["macro:file!", "std/macro.file!.html"],
13-
&["macro:file", "std/macro.file.html"],
14-
&["std::fs", "std/fs/index.html"],
15-
&["std::fs::read_dir", "std/fs/fn.read_dir.html"],
16-
&["std::io::Bytes", "std/io/struct.Bytes.html"],
17-
&["std::iter::Sum", "std/iter/trait.Sum.html"],
18-
&["std::io::error::Result", "std/io/error/type.Result.html"],
19-
&["usize", "std/primitive.usize.html"],
20-
&["eprintln", "std/macro.eprintln.html"],
21-
&["alloc::format", "alloc/macro.format.html"],
22-
&["std::mem::MaybeUninit", "std/mem/union.MaybeUninit.html"],
6+
static TEST_CASES: &[(&[&str], &str)] = &[
7+
(&["core"], "core/index.html"),
8+
(&["core::arch"], "core/arch/index.html"),
9+
(&["fn"], "std/keyword.fn.html"),
10+
(&["keyword:fn"], "std/keyword.fn.html"),
11+
(&["primitive:fn"], "std/primitive.fn.html"),
12+
(&["macro:file!"], "std/macro.file!.html"),
13+
(&["macro:file"], "std/macro.file.html"),
14+
(&["std::fs"], "std/fs/index.html"),
15+
(&["std::fs::read_dir"], "std/fs/fn.read_dir.html"),
16+
(&["std::io::Bytes"], "std/io/struct.Bytes.html"),
17+
(&["std::iter::Sum"], "std/iter/trait.Sum.html"),
18+
(&["std::io::error::Result"], "std/io/error/type.Result.html"),
19+
(&["usize"], "std/primitive.usize.html"),
20+
(&["eprintln"], "std/macro.eprintln.html"),
21+
(&["alloc::format"], "alloc/macro.format.html"),
22+
(&["std::mem::MaybeUninit"], "std/mem/union.MaybeUninit.html"),
2323
];
2424

2525
fn repath(origin: &str) -> String {
@@ -30,15 +30,15 @@ fn repath(origin: &str) -> String {
3030
repathed.into_os_string().into_string().unwrap()
3131
}
3232

33-
pub fn test_cases<'a>() -> impl Iterator<Item = (&'a str, String)> {
34-
TEST_CASES.iter().map(|x| (x[0], repath(x[1])))
33+
pub fn test_cases<'a>() -> impl Iterator<Item = (&'a [&'a str], String)> {
34+
TEST_CASES.iter().map(|(args, path)| (*args, repath(path)))
3535
}
3636

3737
pub fn unique_paths() -> impl Iterator<Item = String> {
3838
// Hashset used to test uniqueness of values through insert method.
3939
let mut unique_paths = HashSet::new();
4040
TEST_CASES
4141
.iter()
42-
.filter(move |e| unique_paths.insert(e[1]))
43-
.map(|e| repath(e[1]))
42+
.filter(move |(_, p)| unique_paths.insert(p))
43+
.map(|(_, p)| repath(p))
4444
}

tests/suite/cli_rustup.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -2640,16 +2640,20 @@ async fn docs_topical_with_path() {
26402640
.expect_ok(&["rustup", "toolchain", "install", "nightly"])
26412641
.await;
26422642

2643-
for (topic, path) in mock::topical_doc_data::test_cases() {
2644-
let mut cmd = clitools::cmd(&cx.config, "rustup", ["doc", "--path", topic]);
2643+
for (args, path) in mock::topical_doc_data::test_cases() {
2644+
let mut cmd = clitools::cmd(
2645+
&cx.config,
2646+
"rustup",
2647+
["doc", "--path"].iter().chain(args.iter()),
2648+
);
26452649
clitools::env(&cx.config, &mut cmd);
26462650

26472651
let out = cmd.output().unwrap();
26482652
eprintln!("{:?}", String::from_utf8(out.stderr).unwrap());
26492653
let out_str = String::from_utf8(out.stdout).unwrap();
26502654
assert!(
26512655
out_str.contains(&path),
2652-
"comparing path\ntopic: '{topic}'\nexpected path: '{path}'\noutput: {out_str}\n\n\n",
2656+
"comparing path\nargs: '{args:?}'\nexpected path: '{path}'\noutput: {out_str}\n\n\n",
26532657
);
26542658
}
26552659
}

0 commit comments

Comments
 (0)