Skip to content

Commit fcd336b

Browse files
Add basics for test command in build system
1 parent 0348a5f commit fcd336b

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

Diff for: build_system/src/main.rs

+5
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ mod build;
55
mod config;
66
mod prepare;
77
mod rustc_info;
8+
mod test;
89
mod utils;
910

1011
macro_rules! arg_error {
@@ -23,13 +24,15 @@ Available commands for build_system:
2324
2425
prepare : Run prepare command
2526
build : Run build command
27+
test : Run test command
2628
--help : Show this message"
2729
);
2830
}
2931

3032
pub enum Command {
3133
Prepare,
3234
Build,
35+
Test,
3336
}
3437

3538
fn main() {
@@ -40,6 +43,7 @@ fn main() {
4043
let command = match env::args().nth(1).as_deref() {
4144
Some("prepare") => Command::Prepare,
4245
Some("build") => Command::Build,
46+
Some("test") => Command::Test,
4347
Some("--help") => {
4448
usage();
4549
process::exit(0);
@@ -55,6 +59,7 @@ fn main() {
5559
if let Err(e) = match command {
5660
Command::Prepare => prepare::run(),
5761
Command::Build => build::run(),
62+
Command::Test => test::run(),
5863
} {
5964
eprintln!("Command failed to run: {e:?}");
6065
process::exit(1);

Diff for: build_system/src/test.rs

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
use crate::utils::run_command_with_output;
2+
3+
fn get_args<'a>(args: &mut Vec<&'a dyn AsRef<std::ffi::OsStr>>, extra_args: &'a Vec<String>) {
4+
for extra_arg in extra_args {
5+
args.push(extra_arg);
6+
}
7+
}
8+
9+
pub fn run() -> Result<(), String> {
10+
let mut args: Vec<&dyn AsRef<std::ffi::OsStr>> = vec![&"bash", &"test.sh"];
11+
let extra_args = std::env::args().skip(2).collect::<Vec<_>>();
12+
get_args(&mut args, &extra_args);
13+
let current_dir = std::env::current_dir().map_err(|error| format!("`current_dir` failed: {:?}", error))?;
14+
run_command_with_output(args.as_slice(), Some(&current_dir))
15+
}

0 commit comments

Comments
 (0)