diff --git a/Cargo.lock b/Cargo.lock index 74e0fc1..dcffa54 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -192,9 +192,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.152" +version = "0.2.153" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "13e3bf6590cbc649f4d1a3eefc9d5d6eb746f5200ffb04e5e142700b8faa56e7" +checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd" [[package]] name = "memchr" diff --git a/README.md b/README.md index 0d10011..d3cb96c 100644 --- a/README.md +++ b/README.md @@ -2,8 +2,9 @@ Simple program that runs test cases specified in an autograding.json file and reports results. Useful for previewing how GitHub will run your autograder and project. -This will only work on Linux as it uses `bash`. Also most GitHub auto-graders runs on the Ubuntu runner image so the commands -are gonna be Linux specific anyway. +> [!INFO] +> While this works on Windows, the GitHub classroom runner uses Linux by default, and so some professors may write commands +> specific to Linux meaning they won't work for you. ## Usage diff --git a/src/runner.rs b/src/runner.rs index f66d94e..c0aba17 100644 --- a/src/runner.rs +++ b/src/runner.rs @@ -7,10 +7,22 @@ use std::{ use anyhow::{anyhow, Result}; use wait_timeout::ChildExt; +#[cfg(not(windows))] +fn spawn_cmd(cmd: &str) -> Command { + let mut command = Command::new("bash"); + command.arg("-c").arg(cmd); + command +} + +#[cfg(windows)] +fn spawn_cmd(cmd: &str) -> Command { + let mut command = Command::new("PowerShell"); + command.arg("-Command").arg(cmd); + command +} + pub fn setup_phase(cmd: &str) -> Result<()> { - let mut child = Command::new("bash") - .arg("-c") - .arg(cmd) + let mut child = spawn_cmd(cmd) .spawn() .map_err(|e| anyhow!("Failed to spawn shell: {e:?}"))?; @@ -39,9 +51,7 @@ where } pub fn run_phase(cmd: &str, input: &str, timeout: u64) -> Result { - let mut child = Command::new("bash") - .arg("-c") - .arg(cmd) + let mut child = spawn_cmd(cmd) .stdin(Stdio::piped()) .stdout(Stdio::piped()) .stderr(Stdio::piped())