From 33d4725463e839060c70254b0c879ad5e27a3cfb Mon Sep 17 00:00:00 2001 From: Rain Date: Mon, 8 Apr 2024 19:46:11 -0700 Subject: [PATCH] exit via ExitCode rather than process::exit This should fix #20. --- src/macros.rs | 4 ++-- src/runner.rs | 12 +++++++++--- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/macros.rs b/src/macros.rs index 57d87941a..2503835b9 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -8,7 +8,7 @@ #[macro_export] macro_rules! harness { ( $( $name:path, $root:expr, $pattern:expr ),+ $(,)* ) => { - fn main() { + fn main() -> ::std::process::ExitCode { let mut requirements = Vec::new(); $( @@ -22,7 +22,7 @@ macro_rules! harness { ); )+ - $crate::runner(&requirements); + $crate::runner(&requirements) } }; } diff --git a/src/runner.rs b/src/runner.rs index 27bede8b3..b4176d215 100644 --- a/src/runner.rs +++ b/src/runner.rs @@ -1,20 +1,26 @@ // Copyright (c) The datatest-stable Contributors // SPDX-License-Identifier: MIT OR Apache-2.0 -use std::path::Path; +use std::{path::Path, process::ExitCode}; use crate::{utils, Result}; use camino::{Utf8Path, Utf8PathBuf}; use libtest_mimic::{Arguments, Trial}; #[doc(hidden)] -pub fn runner(requirements: &[Requirements]) { +pub fn runner(requirements: &[Requirements]) -> ExitCode { let args = Arguments::from_args(); let mut tests: Vec<_> = requirements.iter().flat_map(|req| req.expand()).collect(); tests.sort_unstable_by(|a, b| a.name().cmp(b.name())); - libtest_mimic::run(&args, tests).exit() + let conclusion = libtest_mimic::run(&args, tests); + if conclusion.has_failed() { + // libtest-mimic uses exit code 101 for test failures -- retain the same behavior. + 101.into() + } else { + ExitCode::SUCCESS + } } #[doc(hidden)]