Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions cargo-rbmt/src/bench.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
//! Benchmark testing tasks.

use crate::environment::{get_crate_dirs, quiet_println};
use crate::quiet_cmd;
use crate::environment::{cargo, get_crate_dirs, quiet_println};
use crate::toolchain::{check_toolchain, Toolchain};
use xshell::Shell;

Expand All @@ -22,7 +21,7 @@ pub fn run(sh: &Shell, packages: &[String]) -> Result<(), Box<dyn std::error::Er
// Use pushd pattern to change and restore directory.
let _dir = sh.push_dir(crate_dir);

quiet_cmd!(sh, "cargo bench")
cargo(sh, "bench")
.env("RUSTFLAGS", "--cfg=bench")
.run()?;
}
Expand Down
6 changes: 3 additions & 3 deletions cargo-rbmt/src/docs.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Documentation building tasks.

use crate::quiet_cmd;
use crate::environment::cargo;
use crate::toolchain::{check_toolchain, Toolchain};
use xshell::Shell;

Expand All @@ -11,7 +11,7 @@ use xshell::Shell;
pub fn run(sh: &Shell, packages: &[String]) -> Result<(), Box<dyn std::error::Error>> {
check_toolchain(sh, Toolchain::Stable)?;

let mut cmd = quiet_cmd!(sh, "cargo doc --all-features --no-deps");
let mut cmd = cargo(sh, "doc --all-features --no-deps");

// Add package filters if specified.
for package in packages {
Expand All @@ -30,7 +30,7 @@ pub fn run(sh: &Shell, packages: &[String]) -> Result<(), Box<dyn std::error::Er
pub fn run_docsrs(sh: &Shell, packages: &[String]) -> Result<(), Box<dyn std::error::Error>> {
check_toolchain(sh, Toolchain::Nightly)?;

let mut cmd = quiet_cmd!(sh, "cargo doc --all-features --no-deps");
let mut cmd = cargo(sh, "doc --all-features --no-deps");

// Add package filters if specified.
for package in packages {
Expand Down
8 changes: 8 additions & 0 deletions cargo-rbmt/src/environment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,11 @@ pub fn get_crate_dirs(

Ok(crate_dirs)
}

/// Helper function to run cargo commands with CI flags.
///
/// The locked flag ensures using existing Cargo.lock file without
/// updating dependencies.
pub fn cargo<'a>(sh: &'a Shell, args: &str) -> xshell::Cmd<'a> {
quiet_cmd!(sh, "cargo --locked {args}")
}
5 changes: 2 additions & 3 deletions cargo-rbmt/src/integration.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
//! Integration test tasks for packages with bitcoind-tests or similar test packages.

use crate::environment::{get_crate_dirs, quiet_println, CONFIG_FILE_PATH};
use crate::quiet_cmd;
use crate::environment::{cargo, get_crate_dirs, quiet_println, CONFIG_FILE_PATH};
use serde::Deserialize;
use std::path::{Path, PathBuf};
use xshell::{cmd, Shell};
Expand Down Expand Up @@ -110,7 +109,7 @@ pub fn run(sh: &Shell, packages: &[String]) -> Result<(), Box<dyn std::error::Er
// Run tests for each version.
for version in &versions_to_test {
quiet_println(&format!(" Testing with version: {}", version));
quiet_cmd!(sh, "cargo test --features={version}").run()?;
cargo(sh, "test --features={version}").run()?;
}
}

Expand Down
27 changes: 10 additions & 17 deletions cargo-rbmt/src/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ use std::fs;
use std::path::Path;
use xshell::Shell;

use crate::environment::{get_crate_dirs, quiet_println, CONFIG_FILE_PATH};
use crate::quiet_cmd;
use crate::environment::{cargo, get_crate_dirs, quiet_println, CONFIG_FILE_PATH};
use crate::toolchain::{check_toolchain, Toolchain};

/// Lint configuration loaded from rbmt.toml.
Expand Down Expand Up @@ -58,15 +57,12 @@ fn lint_workspace(sh: &Shell) -> Result<(), Box<dyn std::error::Error>> {
quiet_println("Linting workspace...");

// Run clippy on workspace with all features.
quiet_cmd!(
sh,
"cargo clippy --workspace --all-targets --all-features --keep-going"
)
.args(&["--", "-D", "warnings"])
.run()?;
cargo(sh, "clippy --workspace --all-targets --all-features --keep-going")
.args(&["--", "-D", "warnings"])
.run()?;

// Run clippy on workspace without features.
quiet_cmd!(sh, "cargo clippy --workspace --all-targets --keep-going")
cargo(sh, "clippy --workspace --all-targets --keep-going")
.args(&["--", "-D", "warnings"])
.run()?;

Expand All @@ -93,12 +89,9 @@ fn lint_crates(sh: &Shell, packages: &[String]) -> Result<(), Box<dyn std::error
let _old_dir = sh.push_dir(&crate_dir);

// Run clippy without default features.
quiet_cmd!(
sh,
"cargo clippy --all-targets --no-default-features --keep-going"
)
.args(&["--", "-D", "warnings"])
.run()?;
cargo(sh, "clippy --all-targets --no-default-features --keep-going")
.args(&["--", "-D", "warnings"])
.run()?;
}

Ok(())
Expand All @@ -112,7 +105,7 @@ fn check_duplicate_deps(sh: &Shell) -> Result<(), Box<dyn std::error::Error>> {
let allowed_duplicates = &config.allowed_duplicates;

// Run cargo tree to find duplicates.
let output = quiet_cmd!(sh, "cargo tree --target=all --all-features --duplicates")
let output = cargo(sh, "tree --target=all --all-features --duplicates")
.ignore_status()
.read()?;

Expand All @@ -130,7 +123,7 @@ fn check_duplicate_deps(sh: &Shell) -> Result<(), Box<dyn std::error::Error>> {

if !duplicates.is_empty() {
// Show full tree for context.
quiet_cmd!(sh, "cargo tree --target=all --all-features --duplicates").run()?;
cargo(sh, "tree --target=all --all-features --duplicates").run()?;
eprintln!("Error: Found duplicate dependencies in workspace!");
for dup in &duplicates {
eprintln!(" {}", dup);
Expand Down
4 changes: 4 additions & 0 deletions cargo-rbmt/src/lock.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
//! Manage cargo lock files for minimal and recent dependency versions.
//!
//! Note: This module uses `quiet_cmd!` directly instead of the `cargo()` helper
//! because these commands intentionally generate and modify lockfiles. Using
//! `--locked` would prevent the dependency resolution we need here.

use crate::environment::quiet_println;
use crate::quiet_cmd;
Expand Down
81 changes: 16 additions & 65 deletions cargo-rbmt/src/test.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
//! Build and test tasks with feature matrix testing.
//! Test tasks with feature matrix testing.

use crate::environment::{get_crate_dirs, quiet_println, CONFIG_FILE_PATH};
use crate::quiet_cmd;
use crate::environment::{cargo, get_crate_dirs, quiet_println, CONFIG_FILE_PATH};
use crate::toolchain::{check_toolchain, Toolchain};
use serde::Deserialize;
use std::ffi::OsStr;
Expand Down Expand Up @@ -134,7 +133,7 @@ impl TestConfig {
}
}

/// Run build and test for all crates with the specified toolchain.
/// Run tests for all crates with the specified toolchain.
pub fn run(
sh: &Shell,
toolchain: Toolchain,
Expand All @@ -158,13 +157,12 @@ pub fn run(
Ok(())
}

/// Run basic build, test, and examples.
/// Run basic test and examples.
fn do_test(sh: &Shell, config: &TestConfig) -> Result<(), Box<dyn std::error::Error>> {
quiet_println("Running basic tests");

// Basic build and test.
quiet_cmd!(sh, "cargo build").run()?;
quiet_cmd!(sh, "cargo test").run()?;
// Basic test (includes build).
cargo(sh, "test").run()?;

// Run examples.
for example in &config.examples {
Expand All @@ -174,26 +172,18 @@ fn do_test(sh: &Shell, config: &TestConfig) -> Result<(), Box<dyn std::error::Er
1 => {
// Format: "name" - run with default features.
let name = parts[0];
quiet_cmd!(sh, "cargo run --locked --example {name}").run()?;
cargo(sh, "run --example {name}").run()?;
}
2 => {
let name = parts[0];
let features = parts[1];

if features == "-" {
// Format: "name:-" - run with no-default-features.
quiet_cmd!(
sh,
"cargo run --locked --no-default-features --example {name}"
)
.run()?;
cargo(sh, "run --no-default-features --example {name}").run()?;
} else {
// Format: "name:features" - run with specific features.
quiet_cmd!(
sh,
"cargo run --locked --example {name} --features={features}"
)
.run()?;
cargo(sh, "run --example {name} --features={features}").run()?;
}
}
_ => {
Expand All @@ -218,16 +208,7 @@ fn do_feature_matrix(sh: &Shell, config: &TestConfig) -> Result<(), Box<dyn std:
for features in &config.exact_features {
let features_str = features.join(" ");
quiet_println(&format!("Testing exact features: {}", features_str));
quiet_cmd!(
sh,
"cargo build --no-default-features --features={features_str}"
)
.run()?;
quiet_cmd!(
sh,
"cargo test --no-default-features --features={features_str}"
)
.run()?;
cargo(sh, "test --no-default-features --features={features_str}").run()?;
}
return Ok(());
}
Expand All @@ -236,20 +217,17 @@ fn do_feature_matrix(sh: &Shell, config: &TestConfig) -> Result<(), Box<dyn std:
if !config.features_with_no_std.is_empty() {
let no_std = FeatureFlag::NoStd;
quiet_println("Testing no-std");
quiet_cmd!(sh, "cargo build --no-default-features --features={no_std}").run()?;
quiet_cmd!(sh, "cargo test --no-default-features --features={no_std}").run()?;
cargo(sh, "test --no-default-features --features={no_std}").run()?;

loop_features(sh, Some(FeatureFlag::NoStd), &config.features_with_no_std)?;
} else {
quiet_println("Testing no-default-features");
quiet_cmd!(sh, "cargo build --no-default-features").run()?;
quiet_cmd!(sh, "cargo test --no-default-features").run()?;
cargo(sh, "test --no-default-features").run()?;
}

// Test all features.
quiet_println("Testing all-features");
quiet_cmd!(sh, "cargo build --all-features").run()?;
quiet_cmd!(sh, "cargo test --all-features").run()?;
cargo(sh, "test --all-features").run()?;

// Test features with std.
if !config.features_with_std.is_empty() {
Expand Down Expand Up @@ -301,48 +279,21 @@ fn loop_features<S: AsRef<str>>(
// Test all features together.
let all_features = combine_features(base, features);
quiet_println(&format!("Testing features: {}", all_features));
quiet_cmd!(
sh,
"cargo build --no-default-features --features={all_features}"
)
.run()?;
quiet_cmd!(
sh,
"cargo test --no-default-features --features={all_features}"
)
.run()?;
cargo(sh, "test --no-default-features --features={all_features}").run()?;

// Test each feature individually and all pairs (only if more than one feature).
if features.len() > 1 {
for i in 0..features.len() {
let feature_combo = combine_features(base, &features[i..=i]);
quiet_println(&format!("Testing features: {}", feature_combo));
quiet_cmd!(
sh,
"cargo build --no-default-features --features={feature_combo}"
)
.run()?;
quiet_cmd!(
sh,
"cargo test --no-default-features --features={feature_combo}"
)
.run()?;
cargo(sh, "test --no-default-features --features={feature_combo}").run()?;

// Test all pairs with features[i].
for j in (i + 1)..features.len() {
let pair = [&features[i], &features[j]];
let feature_combo = combine_features(base, &pair);
quiet_println(&format!("Testing features: {}", feature_combo));
quiet_cmd!(
sh,
"cargo build --no-default-features --features={feature_combo}"
)
.run()?;
quiet_cmd!(
sh,
"cargo test --no-default-features --features={feature_combo}"
)
.run()?;
cargo(sh, "test --no-default-features --features={feature_combo}").run()?;
}
}
}
Expand Down