Skip to main content

tests

Function tests 

Source
pub fn tests(
    base: &str,
    changed: Option<&[String]>,
    members: &[Member],
) -> TestChoice
Expand description

The tests for the files changed that differ from the merge base with base (01M49HAZA5K08XW2JQ11TG87JP): the tests of each crate with a changed file, and of each crate that depends on one of them, also through another crate. Each file outside the crates, for example Cargo.lock, the justfile or a page of the book, needs the tests of each crate: a test can read it. None says that git cannot compare with base: then each crate.

use hygiene::ci::{tests, Member, Tests};

let member = |name: &str, deps: &[&str]| Member {
    name: name.into(),
    dir: format!("crates/{name}"),
    deps: deps.iter().map(|&d| d.into()).collect(),
};
let members = [
    member("riff-core", &[]),
    member("riff-server", &["riff-core"]),
    member("riff", &["riff-core", "riff-server"]),
    member("reqs", &[]),
];
let changed = ["crates/riff-server/src/lib.rs".to_owned()];
let choice = tests("origin/main", Some(&changed), &members);
assert_eq!(choice.tests.args(), "-p riff -p riff-server");

let core = ["crates/riff-core/src/record.rs".to_owned()];
let choice = tests("origin/main", Some(&core), &members);
assert_eq!(choice.tests.args(), "-p riff -p riff-core -p riff-server");

let book = ["docs/src/development.md".to_owned()];
let choice = tests("origin/main", Some(&book), &members);
assert_eq!(choice.tests, Tests::Workspace);
assert_eq!(
    choice.to_string(),
    "just check runs the tests of each crate: docs/src/development.md is in no crate, \
     and a test can read it"
);

assert_eq!(tests("origin/main", Some(&[]), &members).tests, Tests::None);