Skip to content

Commit 4353d58

Browse files
committed
feat: add test execution in debug mode
1 parent d4d9a38 commit 4353d58

File tree

2 files changed

+65
-13
lines changed

2 files changed

+65
-13
lines changed

src/lib.rs

Lines changed: 58 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1072,6 +1072,9 @@ pub async fn debug_recipe(
10721072
) -> miette::Result<()> {
10731073
let recipe_path = get_recipe_path(&debug_data.recipe_path)?;
10741074

1075+
let is_test_mode = debug_data.test_index.is_some();
1076+
let test_index = debug_data.test_index.unwrap_or(0);
1077+
10751078
let build_data = BuildData {
10761079
build_platform: debug_data.build_platform,
10771080
target_platform: debug_data.target_platform,
@@ -1177,22 +1180,64 @@ pub async fn debug_recipe(
11771180
}
11781181
}
11791182

1180-
tracing::info!("\nTo run the actual build, use:");
1181-
tracing::info!(
1182-
"rattler-build build --recipe {}",
1183-
output.build_configuration.directories.recipe_path.display()
1184-
);
1185-
tracing::info!("Or run the build script directly with:");
1186-
if cfg!(windows) {
1187-
tracing::info!(
1188-
"cd {} && ./conda_build.bat",
1189-
output.build_configuration.directories.work_dir.display()
1190-
);
1183+
if is_test_mode {
1184+
// Test mode: setup test environment and run specific test
1185+
let tests = &output.recipe.tests;
1186+
1187+
if tests.is_empty() {
1188+
return Err(miette::miette!(
1189+
"No tests found in recipe. Cannot run tests in debug mode."
1190+
));
1191+
}
1192+
1193+
if test_index >= tests.len() {
1194+
return Err(miette::miette!(
1195+
"Test index {} out of range. Recipe has {} test(s).",
1196+
test_index,
1197+
tests.len()
1198+
));
1199+
}
1200+
1201+
tracing::info!("\n=== Test Debug Mode ===");
1202+
tracing::info!("Running test {} of {}", test_index, tests.len() - 1);
1203+
tracing::info!("Available tests:");
1204+
for (idx, test) in tests.iter().enumerate() {
1205+
let test_type = match test {
1206+
crate::recipe::parser::TestType::Python { .. } => "Python",
1207+
crate::recipe::parser::TestType::Perl { .. } => "Perl",
1208+
crate::recipe::parser::TestType::R { .. } => "R",
1209+
crate::recipe::parser::TestType::Ruby { .. } => "Ruby",
1210+
crate::recipe::parser::TestType::Command(_) => "Command",
1211+
crate::recipe::parser::TestType::Downstream(_) => "Downstream",
1212+
crate::recipe::parser::TestType::PackageContents { .. } => "PackageContents",
1213+
};
1214+
let marker = if idx == test_index { ">>>" } else { " " };
1215+
tracing::info!("{} Test {}: {}", marker, idx, test_type);
1216+
}
1217+
1218+
tracing::info!("\nTest environment will be prepared for test index {}.", test_index);
1219+
tracing::info!("\nTo execute tests after setting up the environment, use:");
1220+
tracing::info!(" rattler-build test <package_file>");
1221+
tracing::info!("\nNote: The test environment has been created, but the package must be built first before running tests.");
11911222
} else {
1223+
// Build mode: provide instructions to run the build script
1224+
tracing::info!("\nTo run the actual build, use:");
11921225
tracing::info!(
1193-
"cd {} && ./conda_build.sh",
1194-
output.build_configuration.directories.work_dir.display()
1226+
"rattler-build build --recipe {}",
1227+
output.build_configuration.directories.recipe_path.display()
11951228
);
1229+
tracing::info!("Or run the build script directly with:");
1230+
if cfg!(windows) {
1231+
tracing::info!(
1232+
"cd {} && ./conda_build.bat",
1233+
output.build_configuration.directories.work_dir.display()
1234+
);
1235+
} else {
1236+
tracing::info!(
1237+
"cd {} && ./conda_build.sh",
1238+
output.build_configuration.directories.work_dir.display()
1239+
);
1240+
}
11961241
}
11971242
}
11981243

src/opt.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -895,6 +895,10 @@ pub struct DebugOpts {
895895
/// Name of the specific output to debug (only required when a recipe has multiple outputs)
896896
#[arg(long, help = "Name of the specific output to debug")]
897897
pub output_name: Option<String>,
898+
899+
/// Run tests in debug mode.
900+
#[arg(long, help = "Run tests in debug mode. Optionally specify the test index (default: 0)")]
901+
pub test: Option<Option<usize>>,
898902
}
899903

900904
#[derive(Debug, Clone)]
@@ -916,6 +920,8 @@ pub struct DebugData {
916920
pub common: CommonData,
917921
/// Name of the specific output to debug (if recipe has multiple outputs)
918922
pub output_name: Option<String>,
923+
/// Test index to run in debug mode (if Some). None means no test execution.
924+
pub test_index: Option<usize>,
919925
}
920926

921927
impl DebugData {
@@ -933,6 +939,7 @@ impl DebugData {
933939
channels: opts.channels,
934940
common: CommonData::from_opts_and_config(opts.common, config.unwrap_or_default()),
935941
output_name: opts.output_name,
942+
test_index: opts.test.flatten().or(opts.test.and(Some(0))),
936943
}
937944
}
938945
}

0 commit comments

Comments
 (0)