open Webtest.Suite
open Webtest.Utils

let test_bracket_succeed () =
  let state = ref `uninitialised in
  let setup () = state := `test_start; state in
  let teardown state =
    assert_equal !state `test_end;
    state := `torn_down
  in
  Sync.bracket
    setup
    (fun state ->
      assert_equal !state `test_start;
      state := `test_end)
    teardown ();
  assert_equal !state `torn_down

let test_bracket_fail () =
  let state = ref `uninitialised in
  let setup () = state := `test_start; state in
  let teardown state =
    state := `torn_down
  in
  try
    Sync.bracket
      setup
      (fun state ->
        assert_equal !state `test_start;
        assert_equal 5 6)
      teardown ();
  with TestFailure "not equal" ->
    assert_equal !state `torn_down

let test_bracket_error () =
  let state = ref `uninitialised in
  let setup () = state := `test_start; state in
  let teardown state =
    state := `torn_down
  in
  try
    Sync.bracket
      setup
      (fun state ->
        assert_equal !state `test_start;
        failwith "error")
      teardown ();
  with Failure "error" ->
    assert_equal !state `torn_down

let suite =
  "sync" >::: [
    "test_bracket_succeed" >:: test_bracket_succeed;
    "test_bracket_fail" >:: test_bracket_fail;
    "test_bracket_error" >:: test_bracket_error;
  ]

open Webtest.Suite

let test_bracket_succeed () =
  let state = ref `uninitialised in
  let setup () = state := `test_start; state in
  let teardown state =
    assert_equal !state `test_end;
    state := `torn_down
  in
  Sync.bracket
    setup
    (fun state ->
      assert_equal !state `test_start;
      state := `test_end)
    teardown ();
  assert_equal !state `torn_down

let test_bracket_fail () =
  let state = ref `uninitialised in
  let setup () = state := `test_start; state in
  let teardown state =
    state := `torn_down
  in
  try
    Sync.bracket
      setup
      (fun state ->
        assert_equal !state `test_start;
        assert_equal 5 6)
      teardown ();
  with TestFailure "not equal" ->
    assert_equal !state `torn_down

let test_bracket_error () =
  let state = ref `uninitialised in
  let setup () = state := `test_start; state in
  let teardown state =
    state := `torn_down
  in
  try
    Sync.bracket
      setup
      (fun state ->
        assert_equal !state `test_start;
        failwith "error")
      teardown ();
  with Failure "error" ->
    assert_equal !state `torn_down

let suite =
  "sync" >::: [
    "test_bracket_succeed" >:: test_bracket_succeed;
    "test_bracket_fail" >:: test_bracket_fail;
    "test_bracket_error" >:: test_bracket_error;
  ]

Remove an unused module open
Remove an unused module open

Signed-off-by: John Else <37b74501daa612e48fea94f9846ed4ddeb6a8f07@gmail.com>
