Skip to content

Commit

Permalink
test: add skipped tests with alcotest
Browse files Browse the repository at this point in the history
  • Loading branch information
Khady committed Dec 21, 2024
1 parent e2ed16d commit 2d0698b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
6 changes: 3 additions & 3 deletions alcotest/test/alcotest_report.expected
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<testsuites><testsuite package="junit_alcotest" id="0" name="My first test" timestamp="2013-05-24T10:23:58" hostname="localhost" tests="4" failures="0" errors="2" time="0"><properties></properties><testcase name="Test with unexpected exception" classname="My first test.Basic tests" time="0"><error message="test crashed" type="exception raised">Invalid_argument(&quot;7&quot;)</error></testcase><testcase name="Capitalize" classname="My first test.Basic tests" time="0"></testcase><testcase name="Add entries" classname="My first test.Basic tests" time="0"></testcase><testcase name="Test with wrong result" classname="My first test.Basic tests" time="0"><error message="test crashed" type="exception raised">Alcotest assertion failure
<testsuites><testsuite package="junit_alcotest" id="0" name="Skip test suite" timestamp="2013-05-24T10:23:58" hostname="localhost" tests="2" failures="0" errors="0" time="0"><properties></properties><testcase name="Capitalize" classname="Skip test suite.Skipped tests" time="0"></testcase><testcase name="Add entries" classname="Skip test suite.Skipped tests" time="0"></testcase></testsuite><testsuite package="junit_alcotest" id="1" name="My first test" timestamp="2013-05-24T10:23:58" hostname="localhost" tests="4" failures="0" errors="2" time="0"><properties></properties><testcase name="Test with unexpected exception" classname="My first test.Basic tests" time="0"><error message="test crashed" type="exception raised">Invalid_argument(&quot;7&quot;)</error></testcase><testcase name="Capitalize" classname="My first test.Basic tests" time="0"></testcase><testcase name="Add entries" classname="My first test.Basic tests" time="0"></testcase><testcase name="Test with wrong result" classname="My first test.Basic tests" time="0"><error message="test crashed" type="exception raised">Alcotest assertion failure
&#27;[1mFile &quot;alcotest/junit_alcotest.ml&quot;, line 20, character 6:
&#27;[0m&#27;[31mFAIL&#27;[0m string_of_int equals to '7'

Expected: `&#27;[32m&quot;7&quot;&#27;[0m'
Received: `&#27;[31m&quot;8&quot;&#27;[0m'

</error></testcase></testsuite><testsuite package="junit_alcotest" id="1" name="My second test" timestamp="2013-05-24T10:23:58" hostname="localhost" tests="4" failures="0" errors="2" time="0"><properties></properties><testcase name="Test with unexpected exception" classname="My second test.Basic tests" time="0"><error message="test crashed" type="exception raised">Invalid_argument(&quot;7&quot;)</error></testcase><testcase name="Capitalize" classname="My second test.Basic tests" time="0"></testcase><testcase name="Add entries" classname="My second test.Basic tests" time="0"></testcase><testcase name="Test with wrong result" classname="My second test.Basic tests" time="0"><error message="test crashed" type="exception raised">Alcotest assertion failure
</error></testcase></testsuite><testsuite package="junit_alcotest" id="2" name="My second test" timestamp="2013-05-24T10:23:58" hostname="localhost" tests="4" failures="0" errors="2" time="0"><properties></properties><testcase name="Test with unexpected exception" classname="My second test.Basic tests" time="0"><error message="test crashed" type="exception raised">Invalid_argument(&quot;7&quot;)</error></testcase><testcase name="Capitalize" classname="My second test.Basic tests" time="0"></testcase><testcase name="Add entries" classname="My second test.Basic tests" time="0"></testcase><testcase name="Test with wrong result" classname="My second test.Basic tests" time="0"><error message="test crashed" type="exception raised">Alcotest assertion failure
&#27;[1mFile &quot;alcotest/junit_alcotest.ml&quot;, line 20, character 6:
&#27;[0m&#27;[31mFAIL&#27;[0m string_of_int equals to '7'

Expected: `&#27;[32m&quot;7&quot;&#27;[0m'
Received: `&#27;[31m&quot;8&quot;&#27;[0m'

</error></testcase></testsuite><testsuite package="junit_alcotest" id="2" name="Success test suite" timestamp="2013-05-24T10:23:58" hostname="localhost" tests="2" failures="0" errors="0" time="0"><properties></properties><testcase name="Capitalize" classname="Success test suite.Good tests" time="0"></testcase><testcase name="Add entries" classname="Success test suite.Good tests" time="0"></testcase></testsuite></testsuites>
</error></testcase></testsuite><testsuite package="junit_alcotest" id="3" name="Success test suite" timestamp="2013-05-24T10:23:58" hostname="localhost" tests="2" failures="0" errors="0" time="0"><properties></properties><testcase name="Capitalize" classname="Success test suite.Good tests" time="0"></testcase><testcase name="Add entries" classname="Success test suite.Good tests" time="0"></testcase></testsuite></testsuites>
13 changes: 11 additions & 2 deletions alcotest/test/alcotest_report.ml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ let capit () =
A.(check char) "Check A" 'A' (To_test.capit 'a')

let plus () =
A.(check int)"Sum equals to 7" 7 (To_test.plus [1;1;2;3])
A.(check int) "Sum equals to 7" 7 (To_test.plus [1;1;2;3])

let wrong_result () =
A.(check string) "string_of_int equals to '7'" "7" (string_of_int 8)
Expand All @@ -30,13 +30,22 @@ let success_test_set = [
A.test_case "Add entries" `Slow plus;
]

let skipped_test_set = [
A.test_case "Skipped quick" `Quick (fun () -> A.skip ());
A.test_case "Skipped slow" `Slow (fun () -> A.skip ());
]

let timestamp =
match Ptime.of_date_time ((2013, 5, 24), ((10, 23, 58), 0)) with
| Some t -> t
| None -> assert false

let alcotest path =
let package = "junit_alcotest" in
let (testsuite0, _) = JA.run_and_report ~package ~timestamp "Skip test suite" [
"Skipped tests", success_test_set;
]
in
let (testsuite1, _) = JA.run_and_report ~package ~timestamp "My first test" [
"Basic tests", test_set;
]
Expand All @@ -49,7 +58,7 @@ let alcotest path =
"Good tests", success_test_set;
]
in
let report = Junit.make [testsuite1; testsuite2; testsuite3] in
let report = Junit.make [testsuite0; testsuite1; testsuite2; testsuite3] in
begin match path with
| None ->
let xml_report = Junit.to_xml report in
Expand Down

0 comments on commit 2d0698b

Please sign in to comment.