mirror of
https://github.com/RGBCube/alejandra
synced 2025-07-30 12:07:46 +00:00
Make tests green on systems with different number of physical CPUs
Also pretty print the assert_eq call of the big output.txt comparisson to be actually able to see where things fail with diff.
This commit is contained in:
parent
7da44e0943
commit
3ce9e7d115
4 changed files with 17 additions and 2 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -21,6 +21,7 @@ dependencies = [
|
|||
"clap",
|
||||
"futures",
|
||||
"num_cpus",
|
||||
"pretty_assertions",
|
||||
"rand",
|
||||
"toml",
|
||||
"walkdir",
|
||||
|
|
|
@ -30,3 +30,6 @@ license = "Unlicense"
|
|||
name = "alejandra_cli"
|
||||
repository = "https://github.com/kamadorueda/alejandra"
|
||||
version = "3.1.0"
|
||||
|
||||
[dev-dependencies]
|
||||
pretty_assertions = "1.3.0"
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
use std::env;
|
||||
use std::fs::read_to_string;
|
||||
use std::io::Read;
|
||||
|
||||
|
@ -145,8 +146,15 @@ pub fn main() -> ! {
|
|||
let include: Vec<&str> =
|
||||
args.include.iter().map(String::as_str).collect::<Vec<&str>>();
|
||||
|
||||
let threads =
|
||||
args.threads.map_or_else(num_cpus::get_physical, Into::<usize>::into);
|
||||
// Try CLI value, then env var, then fall back to number of physical CPUs.
|
||||
let threads: usize = if let Some(cli_threads) = args.threads {
|
||||
cli_threads.into() // convert u8 to usize
|
||||
} else {
|
||||
env::var("ALEJANDRA_THREADS")
|
||||
.ok()
|
||||
.and_then(|v| v.parse::<usize>().ok())
|
||||
.unwrap_or_else(num_cpus::get_physical)
|
||||
};
|
||||
|
||||
let verbosity = match args.quiet {
|
||||
0 => Verbosity::Everything,
|
||||
|
|
|
@ -4,6 +4,8 @@ use std::path::PathBuf;
|
|||
use std::process::Command;
|
||||
use std::process::Stdio;
|
||||
|
||||
use pretty_assertions::assert_eq;
|
||||
|
||||
#[derive(Debug)]
|
||||
struct TestCase {
|
||||
args: &'static [&'static str],
|
||||
|
@ -126,6 +128,7 @@ fn cases() {
|
|||
output_got.push_str(&format!("args: {:?}\n", case.args));
|
||||
|
||||
let mut child = Command::new("cargo")
|
||||
.env("ALEJANDRA_THREADS", "4")
|
||||
.args(["run", "--quiet", "--"])
|
||||
.args(case.args)
|
||||
.stdin(Stdio::piped())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue