File: test_lwt_io_non_block.ml

package info (click to toggle)
lwt 5.9.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,284 kB
  • sloc: ml: 22,030; ansic: 7,167; makefile: 92; python: 62
file content (51 lines) | stat: -rw-r--r-- 1,652 bytes parent folder | download | duplicates (4)
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
(* This file is part of Lwt, released under the MIT license. See LICENSE.md for
   details, or visit https://github.com/ocsigen/lwt/blob/master/LICENSE.md. *)



open Test
open Lwt.Infix

let test_file = "Lwt_io_test"
let file_contents = "test file content"

let suite = suite "lwt_io non blocking io" [
  test ~sequential:true "file does not exist"
    (fun () -> Lwt_unix.file_exists test_file >|= fun r -> not r);

  test ~sequential:true "file does not exist (invalid path)"
    (fun () -> Lwt_unix.file_exists (test_file ^ "/foo") >|= fun r -> not r);

  test ~sequential:true "file does not exist (LargeFile)"
    (fun () -> Lwt_unix.LargeFile.file_exists test_file >|= fun r -> not r);

  test ~sequential:true "file does not exist (LargeFile, invalid path)"
    (fun () -> Lwt_unix.LargeFile.file_exists (test_file ^ "/foo") >|= fun r -> not r);

  test ~sequential:true "create file"
    (fun () ->
      Lwt_io.open_file ~mode:Lwt_io.output test_file >>= fun out_chan ->
      Lwt_io.write out_chan file_contents >>= fun () ->
      Lwt_io.close out_chan >>= fun () ->
      Lwt.return_true);

  test ~sequential:true "file exists"
    (fun () -> Lwt_unix.file_exists test_file);

  test ~sequential:true "file exists (LargeFile)"
    (fun () -> Lwt_unix.LargeFile.file_exists test_file);


  test ~sequential:true "read file"
    (fun () ->
      Lwt_io.open_file ~mode:Lwt_io.input test_file >>= fun in_chan ->
      Lwt_io.read in_chan >>= fun s ->
      Lwt_io.close in_chan >>= fun () ->
      Lwt.return (s = file_contents));

  test ~sequential:true "remove file"
    (fun () ->
      Unix.unlink test_file;
      Lwt.return_true);

]