janestreet / ppx_expect

Cram like framework for OCaml
MIT License
146 stars 28 forks source link

Crash upon let%expect_test right before EOF with no newline #27

Open aantron opened 3 years ago

aantron commented 3 years ago

With test.ml:

let%expect_test _ = print_endline "foo"

dune:

(library
 (name test)
 (inline_tests)
 (preprocess (pps ppx_expect)))

and ppx_expect 1.14.1, I get

inline_test_runner_test alias pkg/ppx-expect-bug/runtest (exit 2)
(cd _build/default/pkg/ppx-expect-bug && .test.inline-tests/inline_test_runner_test.exe inline-test-runner test -source-tree-root ../.. -diff-cmd -)
Fatal error: exception ("Expect test evaluator bug" (exn (Invalid_argument "index out of bounds"))
  (backtrace
     "Raised at Base__Exn.protectx in file \"src/exn.ml\", line 71, characters 4-114\
    \nCalled from Ppx_expect_evaluator.process_group.write_corrected in file \"evaluator/ppx_expect_evaluator.ml\" (inlined), line 181, characters 6-88\
    \nCalled from Ppx_expect_evaluator.process_group in file \"evaluator/ppx_expect_evaluator.ml\", line 191, characters 10-45\
    \nCalled from Ppx_expect_evaluator.evaluate_tests.(fun) in file \"evaluator/ppx_expect_evaluator.ml\", line 218, characters 6-83\
    \n")
  (filename pkg/ppx-expect-bug/test.ml))
Raised at Base__Error.raise in file "src/error.ml" (inlined), line 8, characters 14-30
Called from Base__Error.raise_s in file "src/error.ml", line 9, characters 19-40
Called from Base__List.count_map in file "src/list.ml", line 387, characters 13-17
Called from Base__List.map in file "src/list.ml" (inlined), line 418, characters 15-31
Called from Ppx_expect_evaluator.evaluate_tests in file "evaluator/ppx_expect_evaluator.ml" (inlined), line 216, characters 5-486
Called from Ppx_expect_evaluator.evaluate_tests in file "evaluator/ppx_expect_evaluator.ml", line 215, characters 2-572
Called from Stdlib__list.map in file "list.ml", line 92, characters 20-23
Called from Stdlib__list.map in file "list.ml", line 92, characters 32-39
Called from Ppx_inline_test_lib__Runtime.exit in file "runtime-lib/runtime.ml", line 615, characters 2-49
Called from Dune__exe__Inline_test_runner_test in file "pkg/ppx-expect-bug/.test.inline-tests/inline_test_runner_test.ml-gen", line 1, characters 9-44

Note that there is no newline in test.ml. ppx_expect works fine if I add the newline.

I didn't try with ppx_expect master because the metadata appears to require ppxlib < 0.18.0.

ghost commented 3 years ago

Thanks for the report. We should indeed fix this.

I didn't try with ppx_expect master because the metadata appears to require ppxlib < 0.18.0.

We recentely updated our internal copy of ppxlib, so this should be fixed by the next push to github.