Skip to content

Commit

Permalink
refactor(test/mock): use tuples for topical_doc_data::TEST_CASES
Browse files Browse the repository at this point in the history
  • Loading branch information
rami3l committed Nov 26, 2024
1 parent 43757fb commit 53aea77
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 24 deletions.
42 changes: 21 additions & 21 deletions src/test/mock/topical_doc_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -30,15 +30,15 @@ fn repath(origin: &str) -> String {
repathed.into_os_string().into_string().unwrap()
}

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

pub fn unique_paths() -> impl Iterator<Item = String> {
// Hashset used to test uniqueness of values through insert method.
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))
}
11 changes: 8 additions & 3 deletions tests/suite/cli_rustup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -2640,16 +2641,20 @@ 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();
eprintln!("{:?}", String::from_utf8(out.stderr).unwrap());
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",
);
}
}
Expand Down

0 comments on commit 53aea77

Please sign in to comment.