Skip to content

Commit

Permalink
Merge pull request #524 from moonbitlang/panic_test_for_doctest
Browse files Browse the repository at this point in the history
fix: support panic test for doctest
  • Loading branch information
Young-Flash authored Dec 12, 2024
2 parents 1d00d44 + 5d3f50f commit 054f627
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
6 changes: 3 additions & 3 deletions crates/moon/tests/test_cases/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7985,14 +7985,14 @@ fn test_run_doc_test() {
test block 4
test block 5
doc_test 5 from greet.mbt
test username/hello/lib/hello.mbt::1 failed
test username/hello/lib/hello.mbt::doc_test hello.mbt 9 4 failed
expect test failed at $ROOT/src/lib/hello.mbt:12:5-12:19
Diff:
----
1256
----
test username/hello/lib/hello.mbt::2 failed: FAILED: $ROOT/src/lib/hello.mbt:22:5-22:31 this is a failure
test username/hello/lib/hello.mbt::doc_test hello.mbt 19 4 failed: FAILED: $ROOT/src/lib/hello.mbt:22:5-22:31 this is a failure
test username/hello/lib/greet.mbt::2 failed
expect test failed at $ROOT/src/lib/greet.mbt:22:7-22:21
Diff:
Expand Down Expand Up @@ -8025,7 +8025,7 @@ fn test_run_doc_test() {
doc_test 2 from hello.mbt
doc_test 2 from hello.mbt
test username/hello/lib/hello.mbt::2 failed: FAILED: $ROOT/src/lib/hello.mbt:22:5-22:31 this is a failure
test username/hello/lib/hello.mbt::doc_test hello.mbt 19 4 failed: FAILED: $ROOT/src/lib/hello.mbt:22:5-22:31 this is a failure
test block 2
test block 2
test username/hello/lib/greet.mbt::3 failed: FAILED: $ROOT/src/lib/greet.mbt:31:7-31:31 another failure
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ pub fn greet3() -> String {
}

/// ```moonbit
/// test {
/// test "panic test" {
///
///
///
/// println("test block 4")
///
/// panic()
/// }
///
///
Expand Down
10 changes: 9 additions & 1 deletion crates/moonbuild/src/runtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ pub struct TestStatistics {
#[serde(skip_serializing)]
#[serde(default)]
pub is_doc_test: bool,
#[serde(skip_serializing)]
#[serde(default)]
pub original_filename: Option<String>,
}

impl std::fmt::Display for TestStatistics {
Expand Down Expand Up @@ -195,6 +198,7 @@ async fn run(
}
// this is a hack for doc test, make the doc test patch filename be the original file name
if ts.is_doc_test {
ts.original_filename = Some(ts.filename.clone());
ts.filename = ts.filename.replace(MOON_DOC_TEST_POSTFIX, "");
ts.message = ts.message.replace(MOON_DOC_TEST_POSTFIX, "");
}
Expand All @@ -206,7 +210,11 @@ async fn run(
let filename = &test_statistic.filename;
let index = &test_statistic.index.parse::<u32>().unwrap();
let test_name = file_test_info_map
.get(filename)
.get(&if test_statistic.is_doc_test {
test_statistic.original_filename.clone().unwrap()
} else {
filename.to_string()
})
.and_then(|m| m.get(index))
.and_then(|s| s.as_ref())
.unwrap_or(&test_statistic.index);
Expand Down

0 comments on commit 054f627

Please sign in to comment.