diff options
Diffstat (limited to 'test')
| -rw-r--r-- | test/test_lectionary.ml | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/test/test_lectionary.ml b/test/test_lectionary.ml index 45a01ab..fba890a 100644 --- a/test/test_lectionary.ml +++ b/test/test_lectionary.ml @@ -53,8 +53,33 @@ let test_sexp_round_trip () = let l' = Lectionary.t_of_sexp (Lectionary.sexp_of_t l) in Alcotest.(check bool) "round trips" true (l = l') +let with_temp_file contents f = + let path = Filename.temp_file "lectionary_test" ".sexp" in + let oc = open_out path in + output_string oc contents; + close_out oc; + Fun.protect ~finally:(fun () -> Sys.remove path) (fun () -> f path) + +let load_is_error contents what = + with_temp_file contents (fun path -> + match Lectionary.load path with + | Error _ -> () + | Ok _ -> Alcotest.fail (what ^ ": expected Error, got Ok")) + +let test_load_never_raises () = + load_is_error "((ef-advent-sunday-1 (" "unterminated list"; + load_is_error "((ef-advent-sunday-1 ((part First) (reference \"x" "unterminated string"; + load_is_error "" "empty file"; + load_is_error "() ()" "more than one sexp"; + load_is_error "not-a-list" "wrong shape"; + load_is_error "((\"NOT A SLUG\" ()))" "invalid slug"; + match Lectionary.load "/nonexistent/path/lectionary.sexp" with + | Error _ -> () + | Ok _ -> Alcotest.fail "missing file: expected Error, got Ok" + let suite = [ ("find present", `Quick, test_find_present); ("find absent", `Quick, test_find_absent); ("duplicate slug rejected", `Quick, test_duplicate_slug_rejected); - ("sexp round-trip", `Quick, test_sexp_round_trip) ] + ("sexp round-trip", `Quick, test_sexp_round_trip); + ("load never raises", `Quick, test_load_never_raises) ] |
