text
stringlengths
0
601k
let tests = [ test_simple ; test_multiple_opam ; test_filter_packages ; test_filter_packages_no_solution ; test_opam_monorepo ; test_opam_monorepo_no_version ; test_ocamlformat_self ; ]
module Alcotest = struct include Alcotest let bigstring = Alcotest . testable ( fun fmt _bs -> Fmt . pf fmt " < bigstring " ) > ( = ) end
let check ? size f p is = let open Buffered in let state = List . fold_left ( fun state chunk -> feed state ( ` String chunk ) ) ( parse ? initial_buffer_size : size p ) is in f ( state_to_result ( feed state ` Eof ) )
let check_ok ? size ~ msg test p is r = let r = Ok r in check ? size ( fun result -> Alcotest . ( check ( result test string ) ) msg r result ) p is
let check_fail ? size ~ msg p is = let r = Error " " in check ? size ( fun result -> Alcotest . ( check ( result reject pass ) ) msg r result ) p is
let check_c ? size ~ msg p is r = check_ok ? size ~ msg Alcotest . char p is r
let check_lc ? size ~ msg p is r = check_ok ? size ~ msg Alcotest . ( list char ) p is r
let check_co ? size ~ msg p is r = check_ok ? size ~ msg Alcotest . ( option char ) p is r
let check_s ? size ~ msg p is r = check_ok ? size ~ msg Alcotest . string p is r
let check_bs ? size ~ msg p is r = check_ok ? size ~ msg Alcotest . bigstring p is r
let check_ls ? size ~ msg p is r = check_ok ? size ~ msg Alcotest . ( list string ) p is r
let check_int ? size ~ msg p is r = check_ok ? size ~ msg Alcotest . int p is r
let bigstring_of_string s = Bigstringaf . of_string s ~ off : 0 ~ len ( : String . length s )
let basic_constructors = [ " peek_char " , ` Quick , begin fun ( ) -> check_co ~ msg " : singleton input " peek_char [ " t " ] ( Some ' t ' ) ; check_co ~ msg " : longer input " peek_char [ " true " ] ( Some ' t ' ) ; check_co ~ msg " : empty input " peek_char [ " " ] None ; end ; " peek_char_fail " , ` Quick , begin f...
module type EndianBigstring = sig val set_int16 : Bigstringaf . t -> int -> int -> unit val set_int32 : Bigstringaf . t -> int -> int32 -> unit val set_int64 : Bigstringaf . t -> int -> int64 -> unit val set_float : Bigstringaf . t -> int -> float -> unit val set_double : Bigstringaf . t -> int -> float -> unit end
module Endian ( Es : EndianBigstring ) = struct type ' a endian = { name : string ; size : int ; zero : ' a ; min : ' a ; max : ' a ; dump : Bigstringaf . t -> int -> ' a -> unit ; testable : ' a Alcotest . testable } let int16 = { name = " int16 " ; size = 2 ; zero = 0 ; min = ~- 32768 ; max = 32767 ; dump = Es . set_...
let little_endian = let module E = Endian ( struct let set_int16 = Bigstringaf . unsafe_set_int16_le let set_int32 = Bigstringaf . unsafe_set_int32_le let set_int64 = Bigstringaf . unsafe_set_int64_le let set_float bs off f = Bigstringaf . unsafe_set_int32_le bs off ( Int32 . bits_of_float f ) let set_double bs off d =...
let big_endian = let module E = Endian ( struct let set_int16 = Bigstringaf . unsafe_set_int16_be let set_int32 = Bigstringaf . unsafe_set_int32_be let set_int64 = Bigstringaf . unsafe_set_int64_be let set_float bs off f = Bigstringaf . unsafe_set_int32_be bs off ( Int32 . bits_of_float f ) let set_double bs off d = Bi...
let monadic = [ " fail " , ` Quick , begin fun ( ) -> check_fail ~ msg " : non - empty input " ( fail " < msg " ) > [ " asdf " ] ; check_fail ~ msg " : empty input " ( fail " < msg " ) > [ " " ] end ; " return " , ` Quick , begin fun ( ) -> check_s ~ msg " : non - empty input " ( return " test " ) [ " asdf " ] " test "...
let applicative = [ " applicative " , ` Quick , begin fun ( ) -> check_s ~ msg " ` : foo *> bar ` returns bar " ( string " foo " *> string " bar " ) [ " foobar " ] " bar " ; check_s ~ msg " ` : foo <* bar ` returns bar " ( string " foo " <* string " bar " ) [ " foobar " ] " foo " ; end ]
let alternative = [ " alternative " , ` Quick , begin fun ( ) -> check_c ~ msg " : char a | char b " ( char ' a ' <|> char ' b ' ) [ " a " ] ' a ' ; check_c ~ msg " : char b | char a " ( char ' b ' <|> char ' a ' ) [ " a " ] ' a ' ; check_s ~ msg " : string ' a ' | string ' b ' " ( string " a " <|> string " b " ) [ " a...
let combinators = [ " many " , ` Quick , begin fun ( ) -> check_lc ~ msg " : empty input " ( many ( char ' a ' ) ) [ " " ] [ ] ; check_lc ~ msg " : single char " ( many ( char ' a ' ) ) [ " a " ] [ ' a ' ] ; check_lc ~ msg " : two chars " ( many ( char ' a ' ) ) [ " aa " ] [ ' a ' ; ' a ' ] ; end ; " many_till " , ` Qu...
let incremental = [ " within chunk boundary " , ` Quick , begin fun ( ) -> check_s ~ msg " : string on each side of 2 inputs " ( string " this " *> string " that " ) [ " this " ; " that " ] " that " ; check_s ~ msg " : string on each side of 3 inputs " ( string " thi " *> string " st " *> string " hat " ) [ " thi " ; "...
let count_while_regression = [ " proper position set after count_while " , ` Quick , begin fun ( ) -> check_s ~ msg " : take_while then eof " ( take_while ( fun _ -> true ) <* end_of_input ) [ " asdf " ; " " ] " asdf " ; check_s ~ msg " : take_while1 then eof " ( take_while1 ( fun _ -> true ) <* end_of_input ) [ " asdf...
let choice_commit = [ " " , ` Quick , begin fun ( ) -> let p = choice [ string " " @@ *> commit *> char ' ' * ; string " " @ *> commit *> char ' ' ! ] in Alcotest . ( check ( result reject string ) ) " commit to branch " ( Error " : char ' ' " ) * ( parse_string ~ consume : All p " " ) ; @@^ end ]
let input = let test p input ~ off ~ len expect = match Angstrom . Unbuffered . parse p with | Done _ | Fail _ -> assert false | Partial { continue ; committed } -> Alcotest . ( check int ) " committed is zero " 0 committed ; let bs = Bigstringaf . of_string input ~ off : 0 ~ len ( : String . length input ) in let stat...
let consume = [ " consume with choice matching prefix " , ` Quick , begin fun ( ) -> let open Angstrom in let parse ~ consume = parse_string ~ consume ( many ( char ' a ' ) ) " aaabbb " in Alcotest . ( check ( result ( list char ) string ) ) " consume prefix passes " ( parse ~ consume : Prefix ) ( Ok [ ' a ' ; ' a ' ; ...
let ( ) = Alcotest . run " test suite " [ " basic constructors " , basic_constructors ; " little endian " , little_endian ; " big endian " , big_endian ; " monadic interface " , monadic ; " applicative interface " , applicative ; " alternative " , alternative ; " combinators " , combinators ; " incremental input " , in...
type pointC = ProtoC_t . pointC = { f : float }
type pointB = ProtoD_t . pointB = { f : float }
type pointA = ProtoA_t . pointA = { f : float }
let write_pointC : _ -> pointC -> _ = ( fun ob ( x : pointC ) -> Bi_outbuf . add_char ob ' { ' ; let is_first = ref true in if ! is_first then is_first := false else Bi_outbuf . add_char ob ' , ' ; Bi_outbuf . add_string ob " " \ f " " ; \: ( Yojson . Safe . write_std_float ) ob x . f ; Bi_outbuf . add_char ob ' } ' ; ...
let string_of_pointC ( ? len = 1024 ) x = let ob = Bi_outbuf . create len in write_pointC ob x ; Bi_outbuf . contents ob
let read_pointC = ( fun p lb -> Yojson . Safe . read_space p lb ; Yojson . Safe . read_lcurl p lb ; let field_f = ref ( None ) in try Yojson . Safe . read_space p lb ; Yojson . Safe . read_object_end lb ; Yojson . Safe . read_space p lb ; let f = fun s pos len -> if pos < 0 || len < 0 || pos + len > String . length s t...
let pointC_of_string s = read_pointC ( Yojson . Safe . init_lexer ( ) ) ( Lexing . from_string s )
let write_pointB : _ -> pointB -> _ = ( fun ob ( x : pointB ) -> Bi_outbuf . add_char ob ' { ' ; let is_first = ref true in if ! is_first then is_first := false else Bi_outbuf . add_char ob ' , ' ; Bi_outbuf . add_string ob " " \ f " " ; \: ( Yojson . Safe . write_std_float ) ob x . f ; Bi_outbuf . add_char ob ' } ' ; ...
let string_of_pointB ( ? len = 1024 ) x = let ob = Bi_outbuf . create len in write_pointB ob x ; Bi_outbuf . contents ob
let read_pointB = ( fun p lb -> Yojson . Safe . read_space p lb ; Yojson . Safe . read_lcurl p lb ; let field_f = ref ( None ) in try Yojson . Safe . read_space p lb ; Yojson . Safe . read_object_end lb ; Yojson . Safe . read_space p lb ; let f = fun s pos len -> if pos < 0 || len < 0 || pos + len > String . length s t...
let pointB_of_string s = read_pointB ( Yojson . Safe . init_lexer ( ) ) ( Lexing . from_string s )
let write_pointA : _ -> pointA -> _ = ( fun ob ( x : pointA ) -> Bi_outbuf . add_char ob ' { ' ; let is_first = ref true in if ! is_first then is_first := false else Bi_outbuf . add_char ob ' , ' ; Bi_outbuf . add_string ob " " \ f " " ; \: ( Yojson . Safe . write_std_float ) ob x . f ; Bi_outbuf . add_char ob ' } ' ; ...
let string_of_pointA ( ? len = 1024 ) x = let ob = Bi_outbuf . create len in write_pointA ob x ; Bi_outbuf . contents ob
let read_pointA = ( fun p lb -> Yojson . Safe . read_space p lb ; Yojson . Safe . read_lcurl p lb ; let field_f = ref ( None ) in try Yojson . Safe . read_space p lb ; Yojson . Safe . read_object_end lb ; Yojson . Safe . read_space p lb ; let f = fun s pos len -> if pos < 0 || len < 0 || pos + len > String . length s t...
let pointA_of_string s = read_pointA ( Yojson . Safe . init_lexer ( ) ) ( Lexing . from_string s )
let color_text ' ? drop_unsupported_escapes ~ use_temp_file text = Current_buffer . set_temporarily_to_temp_buffer Sync ( fun ( ) -> Point . insert_text text ; color_region_in_current_buffer ~ start ( : Point . min ( ) ) ~ end_ ( : Point . max ( ) ) ~ use_temp_file ? drop_unsupported_escapes ( ) ; Current_buffer . cont...
let color_text ? drop_unsupported_escapes text = let with_temp_file = color_text ' ? drop_unsupported_escapes ~ use_temp_file : true text in let without_temp_file = color_text ' ? drop_unsupported_escapes ~ use_temp_file : false text in ( match [ % compare . equal : Sexp . t ] ( Text . sexp_of_t with_temp_file ) ( Text...
let color_string ? drop_unsupported_escapes s = color_text ? drop_unsupported_escapes ( s |> Text . of_utf8_bytes ) ; ;
let escape ' codes = concat [ " \ 027 [ " ; concat ( codes |> List . map ~ f ( : Option . value_map ~ f : Int . to_string ~ default " " ) : |> List . intersperse ~ sep " ; " ) : ; " m " ] ; ;
let escape codes = escape ' ( List . map codes ~ f ( : fun code -> Some code ) )
let print_state_machine string = Ref . set_temporarily Ansi_color . print_state_machine true ~ f ( : fun ( ) -> ignore ( color_text ' ~ use_temp_file : false ( string |> Text . of_utf8_bytes ) : Text . t ) ) ; ; print_state_machine " " ; [ % expect { | ( state_machine ( ( current_state ( attributes_state ( Complete ( (...
let test ( ? show_input = true ) input = let output = Or_error . try_with ( fun ( ) -> color_string input ) in print_s [ % message . omit_nil " " ~ _ ( : if show_input then [ % message input ] else [ % message ] : Sexp . t ) ~ _ ( : output : Text . t Or_error . t ) ] ; ;
let test_codes codes = test ( concat [ escape codes ; " foo " ] ) test " " ; [ % expect { | ( " " ( Ok " " ) ) } ] ; | return ( ) ; ; test " foo " ; [ % expect { | ( foo ( Ok foo ) ) } ] ; | return ( ) ; ; test_codes [ ] ; [ % expect { | ( " \ 027 [ mfoo " ( Ok foo ) ) } ] ; | test ( concat [ escape [ 31 ] ; " foo " ; ...
let test_point_preservation ~ left ~ right ~ colorize = Current_buffer . set_temporarily_to_temp_buffer Sync ( fun ( ) -> Point . insert left ; let middle = Point . get ( ) in Point . insert right ; Point . goto_char middle ; let show_point ( ) = Text . concat [ Current_buffer . contents ~ text_properties : true ~ end_...
let failf ? attach fmt = ksprintf ( fun s -> fail ? attach ( ` Scenario_error s ) ) fmt
type display_policy = [ ` All | ` Lines of int | ` No | ` On_error of display_policy ]
let call ? comment ( ? expect = ` Status ` OK ) ( ? show_body = ` All ) ( ? show_response = ` On_error ` All ) ( ? how = ` Get ) state ~ api_prefix ~ path = let http_method , body = let json_body json = Some ( Cohttp_lwt . Body . of_string ( Ezjsonm . to_string ~ minify : false json ) ) in match how with | ` Get -> ( `...
( module struct module A = Applicative . Make ( struct type ' a t = ' a Or_error . t let return = Or_error . return let apply = Or_error . apply let map = ` Define_using_apply end ) let error = Or_error . error_string module Tests : module type of A = struct let return = A . return let % expect_test _ = print_s [ % sex...
let debug = OS . Arg . ( flag [ " g " ; " debug " ] ~ env " : DEBUG " ~ doc " : Debug mode . " )
let count = OS . Arg . ( flag_all [ " c " ] ~ doc " : Count me . " )
let print_parse ( ) = Logs . app ( fun m -> m " debug : % b " debug ) ; Logs . app ( fun m -> m " count : % d " count ) ; ( )
let main ( ) = Logs . set_reporter ( Logs_fmt . reporter ( ) ) ; OS . Arg . parse_opts ( ) ; print_parse ( ) ; ( )
let ( ) = main ( )
let debug = OS . Arg . ( flag [ " g " ; " debug " ] ~ env " : DEBUG " ~ doc " : Debug mode . " )
let ( ) = Fmt . ( set_style_renderer stdout ` Ansi_tty )
let print_parse depth ints = Logs . app ( fun m -> m " debug : % b " debug ) ; Logs . app ( fun m -> m " depth : % d " depth ) ; Logs . app ( fun m -> m " pos : [ @% a ] " @ Fmt . ( list ~ sep : sp int ) ints ) ; ( )
let main ( ) = Logs . set_reporter ( Logs_fmt . reporter ( ) ) ; let depth = OS . Arg . ( opt [ " d " ; " depth " ] int ~ absent : 2 ~ doc " : Specifies depth of ( $ docv ) iterations . " ) in let doc = " Testing the OS . Arg module . " in print_parse depth ( OS . Arg . ( parse ~ doc ~ pos : int ( ) ) )
let ( ) = main ( )
let a = Array . make 8 None ; ;
let _ = Array . fill a 2 3 ( Some 42 ) ; ; a ; ; [ %% expect { | [ | None ; None ; None ; None ; None ; None ; None ; None ] | } ] |
let _ = Array . fill a 3 1 ( Some 0 ) ; ; a ; ; [ %% expect { | } ] |
let _ = Array . fill a 3 6 None ; ; a ; ; [ %% expect { | } ] |
let _ = Array . fill a ( - 1 ) 2 None ; ; a ; ; [ %% expect { | } ] |
let _ = Gc . compact ( ) ; ;
let _ = Array . fill a 5 1 ( Some ( if Random . int 2 < 0 then 1 else 2 ) ) ; ; a ; ; [ %% expect { | } ] |
let _ = Array . fill a 5 1 None ; ; a ; ; [ %% expect { | } ] |
let a = Array . make 8 0 . ; ;
let _ = Array . fill a 2 3 42 . ; ; a ; ; [ %% expect { | } ] |
module Make ( A : sig type ' a t val make : int -> ' a -> ' a t val fallback : ' a t -> ' a val get : ' a t -> int -> ' a val set : ' a t -> int -> ' a -> ' a t val iter : ( ' a -> return ) -> ' a t -> return val map : ( ' a -> ' b ) -> ' a t -> ' b t val fold : ( ' b -> ' a -> ' b ) -> ' a t -> ' b -> ' b val fold_map...
module Rsa = struct let ( expected_public , expected_private ) = let n = Z . of_string " 0x00B0DF8DE301B3E8D567285E754661230BEDD203F62C7FF101AA3BBAA1D268C85883D9DCAD1CB39FC51857B10D4EF6BEF6B4FE720E67C1978E4B7801FECB1FBB29 " in let e = Z . of_string " 0x010001 " in let d = Z . of_string " 0x766C074CB12C2ABD0F07694EEDE34...
let dsa_suite = let open Key_parsers . Asn1 . Dsa in let p = Z . of_string " 0x00E21ECE0A801FFBFBA42C78331538C38E004BF7EBD2F882B5AAB6B17AD0F9BE7352DFEB7522BCA514884CBBC78197B3889DF954D6C5E06EF824B7DD54F256A6AF04B77D1A683E725AF3283C4A55A88FCEAACE54328FDF99A690A353E1D07041DD4D0EC391C8B1249E52541D7BC95229A783AA5C3BBFA0F5C...
let ec_suite = let open Key_parsers . Asn1 . Ec in let p256v1_oid = Asn . OID . ( base 1 2 <|| [ 840 ; 10045 ; 3 ; 1 ; 7 ] ) in let exp_named_params = Params . Named p256v1_oid in let test_params expected real ctxt = let printer = Params . show in let cmp p p ' = Params . compare p p ' = 0 in assert_equal ~ ctxt ~ cmp ...
let dh_suite = let open Key_parsers . Asn1 . Dh in let expected_params = let p = Z . of_string " 0x00FD5E02F538091F7380991F204E931C62633358124FA1C3DE6A9F852B2C621F040F44B56F6C6605CFBBC4CF4ECD449BB2889CEA53E0FF88F1FE8D9471030EE893 " in let g = Z . of_string " 2 " in Params . { p ; g ; l = None } in let expected_public =...
let suite = [ Rsa . suite ; " Dsa " >::: dsa_suite ; " Ec " >::: ec_suite ; " Dh " >::: dh_suite ]
let test_assert_true_ok ( ) = assert_true ~ label " : should pass " true
let test_assert_true_fail ( ) = try assert_true ~ label " : test_bool " false ; failwith " assert_true should have failed " with TestFailure " test value was false ( test_bool ) " -> ( )
let test_assert_equal_ok ( ) = assert_equal 5 5
let test_assert_equal_fail ( ) = try assert_equal 5 6 ; failwith " assert_equal should have failed " with TestFailure " not equal " -> ( )
let test_assert_equal_label ( ) = try assert_equal ~ label " : assert_equal " 5 6 ; failwith " assert_equal should have failed " with TestFailure " not equal ( assert_equal ) " -> ( )
let test_assert_equal_printer ( ) = try assert_equal ~ printer : string_of_int 5 6 ; failwith " assert_equal should have failed " with TestFailure " not equal : 5 6 " -> ( )
let test_assert_equal_label_printer ( ) = try assert_equal ~ label " : assert_equal " ~ printer : string_of_int 5 6 ; failwith " assert_equal should have failed " with TestFailure " not equal ( assert_equal ) : 5 6 " -> ( )
let equal_float a b = abs_float ( a . - b ) < 0 . 01
let test_assert_custom_equal_ok ( ) = assert_equal ~ equal : equal_float 5 . 0 5 . 001
let test_assert_custom_equal_fail ( ) = try assert_equal ~ equal : equal_float 5 . 0 6 . 0 ; failwith " assert_equal should have failed " with TestFailure " not equal " -> ( )
let test_assert_raises_ok ( ) = assert_raises ( MyException 0 ) ( fun ( ) -> raise ( MyException 0 ) )
let test_assert_raises_no_exn ( ) = try assert_raises ( MyException 0 ) ( fun ( ) -> ( ) ) with TestFailure " expected exception not raised " -> ( )
let test_assert_raises_wrong_exn ( ) = try assert_raises ( MyException 0 ) ( fun ( ) -> raise ( MyException 1 ) ) with | TestFailure " unexpected exception raised : Test_assert . MyException ( 1 ) " -> ( )
let test_assert_raises_no_exn_label ( ) = try assert_raises ~ label " : assert_raises " ( MyException 0 ) ( fun ( ) -> ( ) ) with | TestFailure " expected exception not raised ( assert_raises ) " -> ( )
let test_assert_raises_wrong_exn_label ( ) = try assert_raises ~ label " : assert_raises " ( MyException 0 ) ( fun ( ) -> raise ( MyException 1 ) ) with | TestFailure " unexpected exception raised ( assert_raises ) : Test_assert . MyException ( 1 ) " -> ( )
let test_assert_raises_string_ok ( ) = assert_raises_string " Test_assert . MyException ( 0 ) " ( fun ( ) -> raise ( MyException 0 ) )
let test_assert_raises_string_no_exn ( ) = try assert_raises_string " Test_assert . MyException ( 0 ) " ( fun ( ) -> ( ) ) with TestFailure " expected exception not raised " -> ( )
let test_assert_raises_string_wrong_exn ( ) = try assert_raises_string " Test_assert . MyException ( 0 ) " ( fun ( ) -> raise ( MyException 1 ) ) with | TestFailure " unexpected exception raised : Test_assert . MyException ( 1 ) " -> ( )