text
stringlengths
0
601k
let same_class t1 t2 = let b = same_class t1 t2 in assert ( is_compressed t1 ) ; assert ( is_compressed t2 ) ; b ; ; let a = create 1 in let b = create 2 in assert ( not ( same_class a b ) ) ; union a b ; assert ( same_class a b ) ; let c = create 3 in assert ( not ( same_class a c ) ) ; assert ( not ( same_class b c )...
let impl_tests = let valid_test = { |
let fooooooooooooooo = let fooooooooooooo = let foooooooooooooo = foooooooooooooo in fooooo , fooooooo in fooooooooooooooooo ; foooooooooooooo } | in let invalid_after_eq_test = { | let fooooooooooooooo } =| in let invalid_after_in_test = { |
let fooooooooooooooooooooo = let foooooooooooooooooooo = let foooooooooooooooo = foooooooo in foooooo in } | in let invalid_seq_modules_test = { |
module M = struct let foooooo = foooo let foooooooooooooo = let foooooooooooo = fooooo end } | in let not_closed_module_test = { |
module M = struct let foo = foo let foo = } | in let not_closed_module_test_2 = { |
module M = struct let foo = foo in let not_closed_sig = { |
module K : sig type t let not_closed_begin = { | let x = if x then begin a } | in let not_closed_if = { | let x = if k } | in let not_closed_if_2 = { | let x = if k then } | in let invalid_if = { | let x = if k then else } | in let invalid_if_2 = { | let x = if k then x else } | in let not_closed_class = { | class c = ...
module K = struct let k ; ; begin let x = in ( ) ; ;
let foooooo = fooooo foooooooo
let k = } | in let _escape_error = { | let _expecting = { |
let f = function | 3 as 3 -> ( ) ; ;
let f = function | 3 :: -> ( ) ; ;
let f = function | 3 | -> ( ) ; ;
let f = function | List . ( -> ( ) ; ;
let f = function | ( 3 : 3 ) -> ( ) ; ;
let f = function | ( 3 , ) -> ( ) ; ;
let f = function | ( -> ( ) ; ;
let f = function | ( module -> ( ) ; ; } | in let _pr7847 = { | external x : unit -> ( int , int ) ` A . t = " x " } | in let unclosed_class_simpl_expr1 = { | method x = 1 let _unclosed_class_simpl_expr2 = { | class c = ( object end : object end } | in let _unclosed_class_simpl_expr3 = { | class c = ( object end } | in...
let f = function | List . ( _ ; ;
let f = function | ( _ ; ;
let f = function | ( _ : int ; ;
let f = function | ( module Foo : sig end ; ;
let f = function | { foo ; bar ; ; ;
let f = function | [ 1 ; 2 ; ; ;
let f = function | [ | 3 ; 4 ; ; ; } | in let unclosed_struct = { |
module M = struct type t = T [ ( " empty " , " " , [ ] ) ; ( " valid " , valid_test , [ ] ) ; ( " invalid after eq " , invalid_after_eq_test , [ ( ( 1 , 0 ) , ( 1 , 22 ) ) ] ) ; ( " invalid after in " , invalid_after_in_test , [ ( ( 2 , 0 ) , ( 8 , 4 ) ) ] ) ; ( " invalid seq modules " , invalid_seq_modules_test , [ ( ...
let intf_tests = let _unclosed_class_signature = { | class c : object } | in let _unclosed_paren_module_type = { | module M : ( sig end } | in let unclosed_sig = { |
module M : sig type t = T } | in [ ( " empty " , " " , [ ] ) ; ( " unclosed sig " , unclosed_sig , [ ( ( 2 , 0 ) , ( 3 , 12 ) ) ] ) ; ]
let check_tests checker tests = List . map ( fun ( name , input , locs ) -> ( name , ` Quick , fun ( ) -> checker ~ name ~ input ~ locs ) ) tests
let tests = [ ( " impl " , check_tests Utils . check_impl impl_tests ) ; ( " intf " , check_tests Utils . check_intf intf_tests ) ; ( " use_file " , check_tests Utils . check_use_file impl_tests ) ; ]
let ( ) = Alcotest . run " Parse_wyc " tests
( module struct let size = Key . create ~ name " : size " Int . sexp_of_t let name = Key . create ~ name " : name " String . sexp_of_t let foo = Key . create ~ name " : foo " Float . sexp_of_t let kids = Key . create ~ name " : kids " ( List . sexp_of_t sexp_of_t ) let % test _ = is_empty empty let test_contains t k v ...
module With_default = struct open ! With_default let % test_unit _ = let key = Key . create ~ default : 0 ~ name " : default 0 " Int . sexp_of_t in assert ( find empty key = 0 ) ; let t = set empty key 1 in assert ( find t key = 1 ) ; let t = set empty key 2 in assert ( find t key = 2 ) ; let t = change t key ~ f ( : ~...
module With_fold = struct open ! With_fold let % test_unit _ = let key = Key . create ~ init : 5 ~ f ( : + ) ~ name " : init 5 " Int . sexp_of_t in assert ( find empty key = 5 ) ; let t = add empty key 3 in assert ( find t key = 8 ) ; let t = change t key ~ f ( : ~- ) in assert ( find t key = - 8 ) ; ; let % test_unit ...
module Multi = struct open ! Multi let % test_unit _ = let key = Key . create ~ name " : int list " Int . sexp_of_t in assert ( find empty key = [ ] ) ; let t = add empty key 1 in assert ( find t key = [ 1 ] ) ; let t = set t key [ 2 ; 3 ] in assert ( find t key = [ 2 ; 3 ] ) ; let t = change t key ~ f ( : List . map ~...
let test_udp_send_recv packet = let open Osc_unix . Udp in let localhost = Unix . inet_addr_of_string " 127 . 0 . 0 . 1 " in let port = 4568 in let addr = Unix . ADDR_INET ( localhost , port ) in let buffer_length = 1024 in bracket ( fun ( ) -> let client = Client . create ( ) in let server = Server . create addr buffe...
let udp_send_recv = " udp_send_recv " >::: ( List . map ( fun ( name , packet ) -> name >:: ( fun ( ) -> test_udp_send_recv packet ) ) Test_common . test_packets_internal )
let suite = " unix_suite " >::: [ udp_send_recv ; ]
let ( ) = print_endline " -------- Unix tests " ; -------- Test_common . run suite
let run args = let out , inp = pipe ( ) in let in_chan = in_channel_of_descr out in set_binary_mode_in in_chan false ; let pid = create_process ( " . " / ^ prog_name ) ( Array . of_list ( prog_name :: args ) ) Unix . stdin inp Unix . stderr in List . iter ( fun arg -> let s = input_line in_chan in Printf . printf " % S...
let ( ) = List . iter run [ [ " " ; " " ; " \ t \ 011 " ] ; [ " a " ; " b " ; " c . txt " ] ; @! [ " " " ] ; \ [ " " ; " a " ; " " \ " \\\ " ] ; [ " \\ \\ " ] ; \\\\\\ [ " " \ hola " " ] ; \ [ " a \ tb " ] ; ]
let errors = [ E2BIG ; EACCES ; EAGAIN ; EBADF ; EBUSY ; ECHILD ; EDEADLK ; EDOM ; EEXIST ; EFAULT ; EFBIG ; EINTR ; EINVAL ; EIO ; EISDIR ; EMFILE ; EMLINK ; ENAMETOOLONG ; ENFILE ; ENODEV ; ENOENT ; ENOEXEC ; ENOLCK ; ENOMEM ; ENOSPC ; ENOSYS ; ENOTDIR ; ENOTEMPTY ; ENOTTY ; ENXIO ; EPERM ; EPIPE ; ERANGE ; EROFS ; E...
let unix_error_testable = Alcotest . testable ( fun ppf error -> let error_name = Unix_error . Internal_for_tests . get_constructor_name error in match error with | EUNKNOWNERR code -> Format . fprintf ppf " % s % d " error_name code | _ -> Format . fprintf ppf " % s " error_name ) ( = )
let json_encode_and_decode error = let open Data_encoding . Json in let encoding = Unix_error . encoding in destruct encoding @@ construct encoding error
let binary_encode_and_decode error = let open Data_encoding . Binary in let encoding = Unix_error . encoding in of_bytes_exn encoding @@ to_bytes_exn encoding error
let test_json ( ) = List . iter ( fun error -> let result = json_encode_and_decode error in Alcotest . ( check unix_error_testable ) " unix error equality " error result ) errors
let test_binary ( ) = List . iter ( fun error -> let result = binary_encode_and_decode error in Alcotest . ( check unix_error_testable ) " unix error equality " error result ) errors
let ( ) = let open Alcotest in run " Base . unix . unix_error " [ ( " encoding " , [ test_case " json encoding roundtrip " ` Quick test_json ; test_case " binary encoding roundtrip " ` Quick test_binary ; ] ) ; ]
let is_dead t = Result . is_error ( is_empty t )
let is_empty_exn t = ok_exn ( is_empty t )
let unpack t = let q = Queue . create ( ) in match unpack_into t q with | Ok ( ) -> Ok q | Error _ as err -> assert ( is_dead t ) ; if Queue . is_empty q then err else Ok q ; ; let buggy_unpack ~ state ( ) : ~ buf : _ ~ pos : _ ~ len : _ = ` Ok ( ( ) , 0 ) in let t = Unpack_buffer . Unpack_one . create ~ initial_state ...
module type Value = sig type t [ @@ deriving sexp_of ] include Equal . S with type t := t val pack : t list -> string val unpack_one : t Unpack_one . t end
let test ( type value ) ( module V : Value with type t = value ) values = let input = Bigstring . of_string ( V . pack values ) in let input_size = Bigstring . length input in let chunk_sizes = List . filter ~ f ( : fun n -> 1 <= n && n <= input_size ) [ 1 ; 2 ; 13 ; input_size / 4 ; input_size / 2 - 1 ; input_size / 2...
module Example = struct type t = { x : int ; y : int ; } [ @@ deriving bin_io ] let t = { x = 0 ; y = 0 ; } let pack ts = List . map ts ~ f ( : fun t -> Bin_prot . Utils . bin_dump ~ header : true bin_writer_t t ) |> Bigstring . concat ; ; let object_size = 3 let % expect_test " bin reading allocation " [ @ tags " 64 -...
let test_unzip_bug1 ( ) = let test data = let input = IO . input_string data in let unzipped = Unzip . inflate input in try let str = IO . read_all unzipped in assert ( str = " XY ) " with Unzip . Error Unzip . Invalid_data -> assert false in test " \ x78 \ xda \ x8b \ x88 \ x04 \ x00 \ x01 \ x0b \ x00 \ xb2 " ; test "...
let inputs = [ ( " a " , " \ x78 \ x01 \ x4b \ x04 \ x00 \ x00 \ x62 \ x00 \ x62 ) " ; ( " a " , " \ x78 \ x5e \ x4b \ x04 \ x00 \ x00 \ x62 \ x00 \ x62 ) " ; ( " a " , " \ x78 \ x9c \ x4b \ x04 \ x00 \ x00 \ x62 \ x00 \ x62 ) " ; ( " a " , " \ x78 \ xda \ x4b \ x04 \ x00 \ x00 \ x62 \ x00 \ x62 ) " ; ( " b " , " \ x78...
let test_unzip_gen_inputs ( ) = let test orig data = let input = IO . input_string data in let unzipped = Unzip . inflate input in try let str = IO . read_all unzipped in assert ( str = orig ) orig with Unzip . Error Unzip . Invalid_data -> assert false in List . iter ( fun ( orig , compressed ) compressed -> test orig...
let ( ) = Util . register " Unzip " [ " bug1 " , test_unzip_bug1 ; " gen_inputs " , test_unzip_gen_inputs ; ]
print_s [ % sexp ( is_none none : bool ) ] ; [ % expect { | true } ] | ; ; print_s [ % sexp ( is_some none : bool ) ] ; [ % expect { | false } ] | ; ; print_s [ % sexp ( is_none ( some 13 ) : bool ) ] ; [ % expect { | false } ] | ; ; print_s [ % sexp ( is_some ( some 13 ) : bool ) ] ; [ % expect { | true } ] | ; ; requ...
let url_string_url u = Url . url_of_string ( Url . string_of_url u )
let url = " http :// ocsigen . org / js_of_ocaml " / ( match Url . url_of_string url with | None -> print_endline " can ' t parse current url2 " | Some u -> ( match url_string_url u with | None -> print_endline " can ' t parse pretty - printed url " | Some v -> if u = v then ( ) else print_endline " no fixpoint " ) ) ;...
let mkdir ( ? perm = 0o750 ) dir = if not ( Sys . file_exists dir ) then Unix . mkdir dir perm
let mount_inside ~ dir ~ src ~ tgt ( ? fstype " " ) = ~ flags ( ? data " " ) = ( ) = let tgt = Filename . concat dir tgt in mkdir tgt ; mount ~ source : src ~ target : tgt ~ fstype flags ~ data
let mount_base dir = mount_inside ~ dir ~ src " : proc " ~ tgt " : proc " ~ fstype " : proc " ~ flags [ : MS_NOSUID ; MS_NOEXEC ; MS_NODEV ] ( ) ; mount_inside ~ dir ~ src " :/ sys " ~ tgt " : sys " ~ flags [ : MS_BIND ; MS_REC ] ( ) ; mount_inside ~ dir ~ src " :/ dev " ~ tgt " : dev " ~ flags [ : MS_BIND ; MS_REC ] (...
let do_chroot dest = Sys . chdir dest ; chroot " . " ; Sys . chdir " " /
let read_in_file fmt = Printf . ksprintf ( fun file -> let c = open_in file in let v = input_line c in close_in c ; v ) fmt
let test_userns_availability ( ) = let unpriviledge_userns_clone = " / proc / sys / kernel / unprivileged_userns_clone " in if Sys . file_exists unpriviledge_userns_clone then begin let v = read_in_file " % s " unpriviledge_userns_clone in if v <> " 1 " then begin Printf . eprintf " This kernel is configured to disable...
let write_in_file fmt = Printf . ksprintf ( fun file -> Printf . ksprintf ( fun towrite -> try let cout = open_out file in output_string cout towrite ; close_out cout with _ -> Printf . eprintf " Error during write of % s in % s \ n " towrite file ; exit 1 ) ) fmt
let command fmt = Printf . ksprintf ( fun cmd -> Sys . command cmd = 0 ) fmt
let command_no_fail ( ? error ( = fun ( ) -> ( ) ) ) fmt = Printf . ksprintf ( fun cmd -> let c = Sys . command cmd in if c <> 0 then begin Printf . eprintf " Error during : % s \ n " %! cmd ; error ( ) ; exit 1 ; end ) fmt
type gpg_t = | GPGNotAvailable | GPGAvailable of string
let gpg_setup ~ dir = let command_raise fmt = Printf . ksprintf ( fun cmd -> Printf . ksprintf ( fun msg -> let c = Sys . command cmd in if c <> 0 then begin Printf . eprintf " % s \ n " %! msg ; raise Exit end ) ) fmt in try command_raise " which gpg >/ dev / null 2 >& 1 " " The program gpg is not present : can ' t va...
let gpg_check file = function | GPGNotAvailable -> ( ) | GPGAvailable gpg_dir -> command_no_fail ~ error ( : fun ( ) -> Printf . eprintf " Invalid signature for % s \ n " %! file ) " GNUPGHOME =% S gpg -- verify % S > / dev / null 2 >& 1 " gpg_dir ( file " . ^ asc " )
let download ( ? quiet = true ) fmt = Printf . ksprintf ( fun src -> Printf . ksprintf ( fun dst -> command " wget - T 30 % s https ://% s /% s - O % S % s " ( if quiet then " - q " else " " ) download_server src dst ( if quiet then " >/ dev / null 2 >& 1 " else " " ) ) ) fmt
let download_index ~ dir ~ gpg = let index = Filename . concat dir " index " in let url_index = " meta / 1 . 0 / index - user " in Printf . printf " Download the index : " ; %! if not ( download " % s . % i " url_index download_compat_level " % s " index && download " % s . % i . asc " url_index download_compat_level "...
let semicomma = Str . regexp_string " ; "
let find_image ~ distr ~ release ~ arch index = let cin = open_in index in let rec aux ( ) = match Str . split semicomma ( input_line cin ) with | [ d ; r ; a ; _ ; db ; u ] when d = distr && r = release && a = arch -> close_in cin ; db , u | _ -> aux ( ) in try aux ( ) with End_of_file -> close_in cin ; Printf . eprin...
let download_rootfs_meta ~ dir ~ gpg ( build_id , url ) = let build_id_file = Filename . concat dir " build_id " in let rootfs_tar = Filename . concat dir " rootfs . tar . xz " in let meta_tar = Filename . concat dir " meta . tar . xz " in if not ( Sys . file_exists build_id_file ) || read_in_file " % s " build_id_file...
type userns_idmap = | KeepUser | IdMap of int * int
let set_usermap idmap pid = let curr_uid = Unix . getuid ( ) in let curr_gid = Unix . getgid ( ) in match idmap with | KeepUser -> write_in_file " / proc /% i / uid_map " pid " 0 % i 1 " curr_uid ; write_in_file " / proc /% i / gid_map " pid " 0 % i 1 " curr_gid ; | IdMap ( id , rangeid ) -> let error ( ) = ignore ( Un...
let goto_child ~ exec_in_parent = let fin , fout = Unix . pipe ( ) in match Unix . fork ( ) with | - 1 -> Printf . eprintf " Fork failed \ n " ; %! exit 1 | 0 -> Unix . close fout ; ignore ( Unix . read fin ( Bytes . create 1 ) 0 1 ) ; Unix . close fin | pid -> Unix . close fin ; ( exec_in_parent pid : unit ) ; ignore ...
let exec_in_child ( type a ) f = let fin , fout = Unix . pipe ( ) in match Unix . fork ( ) with | - 1 -> Printf . eprintf " Fork failed \ n " ; %! exit 1 | 0 -> Unix . close fout ; let cin = Unix . in_channel_of_descr fin in let arg = ( Marshal . from_channel cin : a ) in close_in cin ; f arg ; exit 0 | pid -> Unix . c...
let exec_now_in_child f arg = match Unix . fork ( ) with | - 1 -> Printf . eprintf " Fork failed \ n " ; %! exit 1 | 0 -> f arg ; exit 0 | pid -> let _ , status = Unix . waitpid [ ] pid in match status with | Unix . WEXITED 0 -> ( ) | Unix . WEXITED s -> exit s | Unix . WSIGNALED s -> Unix . kill ( Unix . getpid ( ) ) ...
let just_goto_child ( ) = match Unix . fork ( ) with | - 1 -> Printf . eprintf " Fork failed \ n " ; %! exit 1 | 0 -> ( ) | pid -> let _ , status = Unix . waitpid [ ] pid in match status with | Unix . WEXITED s -> exit s | Unix . WSIGNALED s -> Unix . kill ( Unix . getpid ( ) ) s ; assert false | Unix . WSTOPPED _ -> a...
let go_in_userns idmap = let call_set_usermap = exec_in_child ( set_usermap idmap ) in unshare [ CLONE_NEWNS ; CLONE_NEWIPC ; CLONE_NEWPID ; CLONE_NEWUTS ; CLONE_NEWUSER ; ] ; goto_child ~ exec_in_parent : call_set_usermap
let create_rootfs ~ distr ~ release ~ arch testdir = let rootfsdir = Filename . concat testdir " rootfs " in if not ( Sys . file_exists rootfsdir ) then begin let gpg = gpg_setup ~ dir : testdir in let index = download_index ~ dir : testdir ~ gpg in let url = find_image ~ distr ~ release ~ arch index in let rootfs , me...
let idmap , ( cmd , arg ) , testdir , setuid , setgid , arch , distr , release = let open Arg in let testdir = ref " userns_test " in let idmap_id = ref ( - 1 ) in let idmap_rangeid = ref ( - 1 ) in let command = ref [ ] in let setuid = ref 0 in let setgid = ref 0 in let arch = ref " amd64 " in let distr = ref " debian...
let ( ) = if Unix . getuid ( ) = 0 then begin Printf . eprintf " This program shouldn ' t be run as root !\ n " ; %! exit 1 end ; Unix . handle_unix_error begin fun ( ) -> test_userns_availability ( ) ; mkdir ~ perm : 0o750 testdir ; go_in_userns idmap ; let rootfsdir = create_rootfs ~ arch ~ distr ~ release testdir in...
let prettify s = try " JSON \ n " ^ Yojson . Basic . prettify s ^ " \ n " with _ -> s
let print_req meth uri_s body = printf " Request % s % s \ n " ( Cohttp . Code . string_of_method meth ) uri_s ; ( match body with None -> ( ) | Some s -> printf " Request body :\ n % s \ n " ( prettify s ) ; ) ; flush stdout
let print_resp status body = printf " Response status : % s \ n " ( Cohttp . Code . string_of_status status ) ; printf " Response body :\ n % s \ n " ( prettify body ) ; flush stdout
let wrap ( ? headers = [ ] ) uri_s meth body = let uri = Uri . of_string uri_s in let headers = Cohttp . Header . of_list headers in let headers = match Cohttp . Header . get headers " content - length " , body with None , Some s -> Cohttp . Header . add headers " content - length " ( string_of_int ( String . length s ...
module Lwt_http_client = struct type ' a computation = ' a Lwt . t let bind = Lwt . bind let return = Lwt . return let head ? headers url = wrap ? headers url ` HEAD None let get ? headers url = wrap ? headers url ` GET None let post ? headers ? body url = wrap ? headers url ` POST body let put ? headers ? body url = w...
let doctype = ` Doctype { Markup . doctype_name = Some " html " ; public_identifier = None ; system_identifier = None ; raw_text = None ; force_quirks = false }
let start_element name = ` Start_element ( ( Markup . Ns . html , name ) , [ ] )
let ok = wrong_k " failed "
type dom = | Text of string | Element of string * dom list
let tests = [ ( " utility . content " >:: fun _ -> " <? xml version ' = 1 . 0 ' ?><! DOCTYPE html ><!-- blah -->< p > foo </ p ><? bar baz " ?> |> string |> parse_xml |> signals |> content |> write_xml |> to_string |> assert_equal " < p > foo </ p " ) ; > ( " utility . strings_to_bytes " >:: fun _ -> [ " foo " ; " bar ...
module Fixtures = struct let location = Location . { loc_start = { pos_fname = " test . ml " ; pos_lnum = 1 ; pos_bol = 0 ; pos_cnum = 5 } ; loc_end = { pos_fname = " test . ml " ; pos_lnum = 1 ; pos_bol = 0 ; pos_cnum = 10 } ; loc_ghost = false } end