package ppx_expect_nobase

  1. Overview
  2. Docs
Cram like framework for OCaml (with stripped dependencies)

Install

dune-project
 Dependency

Authors

Maintainers

Sources

ppx_expect_nobase-0.17.3.0.tbz
sha256=ff2cb97c867a4bd3a0778ff0924c1cb8a82c7c531f81f2b0aa220b7c29758e40
sha512=3eae2efe081aeed87d44d46f960a66744ed6d90c78f07ba91639ff2694aea655d4b71c5865d97dd88c1681e3752b90c06c252595f67ff135fcce87c38085b81f

doc/src/ppx_expect_nobase.runtime/current_file.ml.html

Source file current_file.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
let raise_s s = failwith (Sexplib0.Sexp.to_string_hum s)
let sexp_of_string = Sexplib0.Sexp_conv.sexp_of_string
let current = ref None

let set ~filename_rel_to_project_root =
  match !current with
  | None -> current := Some filename_rel_to_project_root
  | Some current ->
    raise_s
      (Sexplib0.Sexp.message
         "Expect_test_collector.set: there is already an active file"
         [ "old_file", sexp_of_string current
         ; "new_file", sexp_of_string filename_rel_to_project_root
         ])
;;

let unset () =
  match !current with
  | Some _ -> current := None
  | None ->
    raise_s
      (Sexplib0.Sexp.message "Expect_test_collector.unset: there is no active file" [])
;;

let get () =
  match !current with
  | Some fn -> fn
  | None ->
    raise_s
      (Sexplib0.Sexp.message "Expect_test_collector.get: there is no active file" [])
;;

let initial_dir = lazy (Stdlib.Sys.getcwd ())
(* let dir_or_error = Or_error.try_with ~backtrace:true Stdlib.Sys.getcwd in
  lazy (Or_error.ok_exn dir_or_error) *)

let absolute_path file =
  if Stdlib.Filename.is_relative file
  then Stdlib.Filename.concat (Lazy.force initial_dir) file
  else file
;;

let verify_that_file_is_current_exn ~line_number ~filename_rel_to_project_root =
  let registering_tests_for = get () in
  if not (String.equal filename_rel_to_project_root registering_tests_for)
  then
    Printf.ksprintf
      failwith
      "Trying to run an expect test from the wrong file.\n\
       - test declared at %s:%d\n\
       - trying to run it from %s\n"
      filename_rel_to_project_root
      line_number
      registering_tests_for
  else ()
;;