Prevent ANSI colors & styles to appear in JSON output.

This commit is contained in:
KtorZ
2024-11-13 12:52:12 +01:00
parent d24a71ee04
commit fafb89d838
3 changed files with 72 additions and 54 deletions

View File

@@ -3,9 +3,8 @@ use aiken_lang::{
ast::OnTestFailure,
expr::UntypedExpr,
format::Formatter,
test_framework::{PropertyTestResult, TestResult, UnitTestResult},
test_framework::{AssertionStyleOptions, PropertyTestResult, TestResult, UnitTestResult},
};
use owo_colors::Stream::Stderr;
use serde_json::json;
#[derive(Debug, Default, Clone, Copy)]
@@ -53,7 +52,7 @@ fn fmt_test_json(result: &TestResult<UntypedExpr, UntypedExpr>) -> serde_json::V
if !result.is_success() {
if let Some(assertion) = assertion {
test["assertion"] = json!({
"message": assertion.to_string(Stderr, false),
"message": assertion.to_string(false, &AssertionStyleOptions::new(None)),
"expected_to_fail": matches!(unit_test.on_test_failure, OnTestFailure::SucceedEventually | OnTestFailure::SucceedImmediately),
});
}

View File

@@ -4,7 +4,7 @@ use aiken_lang::{
ast::OnTestFailure,
expr::UntypedExpr,
format::Formatter,
test_framework::{PropertyTestResult, TestResult, UnitTestResult},
test_framework::{AssertionStyleOptions, PropertyTestResult, TestResult, UnitTestResult},
};
use owo_colors::{OwoColorize, Stream::Stderr};
use uplc::machine::cost_model::ExBudget;
@@ -288,12 +288,12 @@ fn fmt_test(
test = format!(
"{test}\n{}",
assertion.to_string(
Stderr,
match unit_test.on_test_failure {
OnTestFailure::FailImmediately => false,
OnTestFailure::SucceedEventually | OnTestFailure::SucceedImmediately =>
true,
}
},
&AssertionStyleOptions::new(Some(&Stderr))
),
);
}