File: test_framework_demo.ml

package info (click to toggle)
ocaml-obuild 0.2.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,456 kB
  • sloc: ml: 14,491; sh: 211; ansic: 34; makefile: 11
file content (75 lines) | stat: -rw-r--r-- 2,174 bytes parent folder | download
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
open Test_framework
open Test_helpers

(** Demo tests showing the new test framework capabilities *)

let test_string_contains_success () =
  assert_string_contains
    ~haystack:"Hello, World!"
    ~needle:"World"
    ~name:"string contains"

let test_string_contains_failure () =
  let result = assert_string_contains
    ~haystack:"Hello, World!"
    ~needle:"Missing"
    ~name:"string missing" in
  match result with
  | TestFailure _ -> Success  (* We expect this to fail *)
  | Success -> TestFailure "Should have failed"

let test_no_exception_success () =
  assert_no_exception
    ~test_func:(fun () -> 1 + 1)
    ~name:"simple math"

let test_exception_message () =
  assert_exception_message
    ~test_func:(fun () -> failwith "custom error message")
    ~expected_substring:"custom error"
    ~name:"exception contains message"

let test_meta_parse_minimal () =
  assert_meta_parses
    ~content:minimal_meta
    ~name:"minimal meta parses"

let test_meta_parse_field () =
  assert_meta_field
    ~content:minimal_meta
    ~pkg_name:"test"
    ~field_name:"version"
    ~expected_value:"1.0.0"
    ~test_name:"meta version field"

let test_meta_parse_error_demo () =
  assert_meta_parse_error
    ~content:"archive(byte \"missing equals\""
    ~expected_msg:"expecting ')'"
    ~name:"meta parse error"

let test_expr_parse_demo () =
  assert_expr_parses
    ~content:"(>= 1.0)"
    ~name:"expr parses"

let test_libname_parse_demo () =
  assert_libname_parse
    ~input:"foo.bar.baz"
    ~expected_main:"foo"
    ~expected_subs:["bar"; "baz"]
    ~name:"libname parse"

let all_tests = [
  make_test "string_contains_success" test_string_contains_success;
  make_test "string_contains_failure" test_string_contains_failure;
  make_test "no_exception_success" test_no_exception_success;
  make_test "exception_message" test_exception_message;
  make_test "meta_parse_minimal" test_meta_parse_minimal;
  make_test "meta_parse_field" test_meta_parse_field;
  make_test "meta_parse_error_demo" test_meta_parse_error_demo;
  make_test "expr_parse_demo" test_expr_parse_demo;
  make_test "libname_parse_demo" test_libname_parse_demo;
]

let () = run_tests all_tests