Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unicode characters are printed incorrectly with check string #408

Open
feverdreme opened this issue Jun 17, 2024 · 0 comments
Open

Unicode characters are printed incorrectly with check string #408

feverdreme opened this issue Jun 17, 2024 · 0 comments

Comments

@feverdreme
Copy link

When using Alcotest.check with Alcotest.string as its testable and there is a failure, alcotest prints the expected and received outputs incorrectly if they are Unicode characters.

Here is a minimum example:

open Alcotest

let foo () =
  check string "Dummy test" "" ""

let () =
  run "Test" [
    "Test", [
      test_case "test_case" `Quick foo;
    ];
  ]

Clearly the expected and received values are different, and here is the result:

File "test/dune", line 2, characters 7-22:
2 |  (name test_my_project)
           ^^^^^^^^^^^^^^^
Testing `Test'.
This run has ID `AT8IJ0GN'.

> [FAIL]        Test          0   test_case.

┌──────────────────────────────────────────────────────────────────────────────┐
│ [FAIL]        Test          0   test_case.                                   │
└──────────────────────────────────────────────────────────────────────────────┘
ASSERT Dummy test
FAIL Dummy test

   Expected: `"\226\136\128"'
   Received: `"\226\136\131"'

Raised at Alcotest_engine__Test.check in file "src/alcotest-engine/test.ml", line 200, characters 4-261
Called from Alcotest_engine__Core.Make.protect_test.(fun) in file "src/alcotest-engine/core.ml", line 181, characters 17-23
Called from Alcotest_engine__Monad.Identity.catch in file "src/alcotest-engine/monad.ml", line 24, characters 31-35

Logs saved to `~/Documents/alcotestbug/_build/default/test/_build/_tests/Test/Test.000.output'.
 ──────────────────────────────────────────────────────────────────────────────

Full test results in `~/Documents/alcotestbug/_build/default/test/_build/_tests/Test'.
1 failure! in 0.000s. 1 test run.

I tested this when using custom pretty printers and there was no such error.

open Alcotest

type t = {name: string}

let pp_person fmt person =
  Fmt.pf fmt "{ foo = %s }" person.name

let person_testable = testable pp_person (=)

(* Test the find_person function with a pattern match *)
let test_find_person () =
  check person_testable "Dummy test" {name = ""} {name = ""}

let () =
  run "Test" [
    "Test", [
      test_case "test_case" `Quick test_find_person;
    ];
  ]
File "test/dune", line 2, characters 7-22:
2 |  (name test_my_project)
           ^^^^^^^^^^^^^^^
Testing `Test'.
This run has ID `MJPDELRM'.

> [FAIL]        Test          0   test_case.

┌──────────────────────────────────────────────────────────────────────────────┐
│ [FAIL]        Test          0   test_case.                                   │
└──────────────────────────────────────────────────────────────────────────────┘
ASSERT Dummy test
FAIL Dummy test

   Expected: `{ foo = ∀ }'
   Received: `{ foo = ∃ }'

Raised at Alcotest_engine__Test.check in file "src/alcotest-engine/test.ml", line 200, characters 4-261
Called from Alcotest_engine__Core.Make.protect_test.(fun) in file "src/alcotest-engine/core.ml", line 181, characters 17-23
Called from Alcotest_engine__Monad.Identity.catch in file "src/alcotest-engine/monad.ml", line 24, characters 31-35

Logs saved to `~/Documents/alcotestbug/_build/default/test/_build/_tests/Test/Test.000.output'.
 ──────────────────────────────────────────────────────────────────────────────

Full test results in `~/Documents/alcotestbug/_build/default/test/_build/_tests/Test'.
1 failure! in 0.000s. 1 test run.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant