-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhello_error.ml
107 lines (105 loc) · 3.9 KB
/
hello_error.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
(*******************************************************************************)
(* Vcs - a Versatile OCaml Library for Git Operations *)
(* Copyright (C) 2024 Mathieu Barbin <[email protected]> *)
(* *)
(* This file is part of Vcs. *)
(* *)
(* Vcs is free software; you can redistribute it and/or modify it under *)
(* the terms of the GNU Lesser General Public License as published by the *)
(* Free Software Foundation either version 3 of the License, or any later *)
(* version, with the LGPL-3.0 Linking Exception. *)
(* *)
(* Vcs is distributed in the hope that it will be useful, but WITHOUT ANY *)
(* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS *)
(* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License and *)
(* the file `NOTICE.md` at the root of this repository for more details. *)
(* *)
(* You should have received a copy of the GNU Lesser General Public License *)
(* and the LGPL-3.0 Linking Exception along with this library. If not, see *)
(* <http://www.gnu.org/licenses/> and <https://spdx.org>, respectively. *)
(*******************************************************************************)
(* In this test we run a function from the Vcs API, let it raise an exception
and show how to catch it. This allows for a basic coverage of the raising
case of the API too. *)
let%expect_test "hello error" =
Eio_main.run
@@ fun env ->
let vcs = Vcs_git_eio.create ~env in
let invalid_path = Absolute_path.v "/invalid/path" in
let redact_sexp sexp =
(* Because the actual error may become too brittle overtime, we actually
redact it. *)
Vcs_test_helpers.redact_sexp sexp ~fields:[ "error" ]
in
let () =
match Vcs.init vcs ~path:invalid_path with
| _ -> assert false
| exception Vcs.E err -> print_s (redact_sexp [%sexp (err : Vcs.Err.t)])
in
[%expect
{|
((steps (
(Vcs.init ((path /invalid/path)))
((prog git)
(args (init .))
(exit_status Unknown)
(cwd /invalid/path)
(stdout "")
(stderr ""))))
(error <REDACTED>))
|}];
(* Let's do the same with the non-raising interfaces. *)
let () =
match Vcs.Or_error.init vcs ~path:invalid_path with
| Ok _ -> assert false
| Error err -> print_s (redact_sexp [%sexp (err : Error.t)])
in
[%expect
{|
((steps (
(Vcs.init ((path /invalid/path)))
((prog git)
(args (init .))
(exit_status Unknown)
(cwd /invalid/path)
(stdout "")
(stderr ""))))
(error <REDACTED>))
|}];
let () =
match Vcs.Result.init vcs ~path:invalid_path with
| Ok _ -> assert false
| Error err -> print_s (redact_sexp [%sexp (err : Vcs.Err.t)])
in
[%expect
{|
((steps (
(Vcs.init ((path /invalid/path)))
((prog git)
(args (init .))
(exit_status Unknown)
(cwd /invalid/path)
(stdout "")
(stderr ""))))
(error <REDACTED>))
|}];
let () =
match Vcs.Rresult.init vcs ~path:invalid_path with
| Ok _ -> assert false
| Error err -> print_s (redact_sexp [%sexp (err : Vcs.Rresult.err)])
in
[%expect
{|
(Vcs (
(steps (
(Vcs.init ((path /invalid/path)))
((prog git)
(args (init .))
(exit_status Unknown)
(cwd /invalid/path)
(stdout "")
(stderr ""))))
(error <REDACTED>)))
|}];
()
;;