From 53aea77ed8d80c9accba8e7624e831b9da0c06d2 Mon Sep 17 00:00:00 2001 From: rami3l Date: Tue, 26 Nov 2024 21:47:30 +0800 Subject: [PATCH] refactor(test/mock): use tuples for `topical_doc_data::TEST_CASES` --- src/test/mock/topical_doc_data.rs | 42 +++++++++++++++---------------- tests/suite/cli_rustup.rs | 11 +++++--- 2 files changed, 29 insertions(+), 24 deletions(-) diff --git a/src/test/mock/topical_doc_data.rs b/src/test/mock/topical_doc_data.rs index e8f93a37be..e97d9bb6ea 100644 --- a/src/test/mock/topical_doc_data.rs +++ b/src/test/mock/topical_doc_data.rs @@ -3,23 +3,23 @@ use std::path::PathBuf; // Paths are written as a string in the UNIX format to make it easy // to maintain. -static TEST_CASES: &[&[&str]] = &[ - &["core", "core/index.html"], - &["core::arch", "core/arch/index.html"], - &["fn", "std/keyword.fn.html"], - &["keyword:fn", "std/keyword.fn.html"], - &["primitive:fn", "std/primitive.fn.html"], - &["macro:file!", "std/macro.file!.html"], - &["macro:file", "std/macro.file.html"], - &["std::fs", "std/fs/index.html"], - &["std::fs::read_dir", "std/fs/fn.read_dir.html"], - &["std::io::Bytes", "std/io/struct.Bytes.html"], - &["std::iter::Sum", "std/iter/trait.Sum.html"], - &["std::io::error::Result", "std/io/error/type.Result.html"], - &["usize", "std/primitive.usize.html"], - &["eprintln", "std/macro.eprintln.html"], - &["alloc::format", "alloc/macro.format.html"], - &["std::mem::MaybeUninit", "std/mem/union.MaybeUninit.html"], +static TEST_CASES: &[(&[&str], &str)] = &[ + (&["core"], "core/index.html"), + (&["core::arch"], "core/arch/index.html"), + (&["fn"], "std/keyword.fn.html"), + (&["keyword:fn"], "std/keyword.fn.html"), + (&["primitive:fn"], "std/primitive.fn.html"), + (&["macro:file!"], "std/macro.file!.html"), + (&["macro:file"], "std/macro.file.html"), + (&["std::fs"], "std/fs/index.html"), + (&["std::fs::read_dir"], "std/fs/fn.read_dir.html"), + (&["std::io::Bytes"], "std/io/struct.Bytes.html"), + (&["std::iter::Sum"], "std/iter/trait.Sum.html"), + (&["std::io::error::Result"], "std/io/error/type.Result.html"), + (&["usize"], "std/primitive.usize.html"), + (&["eprintln"], "std/macro.eprintln.html"), + (&["alloc::format"], "alloc/macro.format.html"), + (&["std::mem::MaybeUninit"], "std/mem/union.MaybeUninit.html"), ]; fn repath(origin: &str) -> String { @@ -30,8 +30,8 @@ fn repath(origin: &str) -> String { repathed.into_os_string().into_string().unwrap() } -pub fn test_cases<'a>() -> impl Iterator { - TEST_CASES.iter().map(|x| (x[0], repath(x[1]))) +pub fn test_cases<'a>() -> impl Iterator { + TEST_CASES.iter().map(|(args, path)| (*args, repath(path))) } pub fn unique_paths() -> impl Iterator { @@ -39,6 +39,6 @@ pub fn unique_paths() -> impl Iterator { let mut unique_paths = HashSet::new(); TEST_CASES .iter() - .filter(move |e| unique_paths.insert(e[1])) - .map(|e| repath(e[1])) + .filter(move |(_, p)| unique_paths.insert(p)) + .map(|(_, p)| repath(p)) } diff --git a/tests/suite/cli_rustup.rs b/tests/suite/cli_rustup.rs index 687eaf7ff4..e472be0758 100644 --- a/tests/suite/cli_rustup.rs +++ b/tests/suite/cli_rustup.rs @@ -4,6 +4,7 @@ use std::fs; use std::path::{PathBuf, MAIN_SEPARATOR}; use std::{env::consts::EXE_SUFFIX, path::Path}; +use itertools::chain; use rustup::for_host; use rustup::test::{ mock::{ @@ -2640,8 +2641,12 @@ async fn docs_topical_with_path() { .expect_ok(&["rustup", "toolchain", "install", "nightly"]) .await; - for (topic, path) in mock::topical_doc_data::test_cases() { - let mut cmd = clitools::cmd(&cx.config, "rustup", ["doc", "--path", topic]); + for (args, path) in mock::topical_doc_data::test_cases() { + let mut cmd = clitools::cmd( + &cx.config, + "rustup", + chain!(["doc", "--path"], args.iter().cloned()), + ); clitools::env(&cx.config, &mut cmd); let out = cmd.output().unwrap(); @@ -2649,7 +2654,7 @@ async fn docs_topical_with_path() { let out_str = String::from_utf8(out.stdout).unwrap(); assert!( out_str.contains(&path), - "comparing path\ntopic: '{topic}'\nexpected path: '{path}'\noutput: {out_str}\n\n\n", + "comparing path\nargs: '{args:?}'\nexpected path: '{path}'\noutput: {out_str}\n\n\n", ); } }