text stringlengths 0 601k |
|---|
let test_abstract_values_are_not_passable _ = begin assert_raises ~ msg " : Abstract type rejected as argument " ( Unsupported " Unsupported argument type " ) ( fun ( ) -> ( abstract ~ name " : abstract " ~ size : 1 ~ alignment : 1 ) @-> returning void ) ; assert_raises ~ msg " : Abstract type rejected as return type "... |
let test_struct_passability _ = let module M = struct type s1 and s2 and s3 and s4 and s5 and s6 and u let s1 : s1 structure typ = structure " s1 " let ( ) -: ty label = field s1 label ty let _ = int -: " _ " let _ = double -: " _ " let _ = ptr s1 -: " _ " let _ = Foreign . funptr ( int @-> returning int ) -: " _ " let... |
let test_incomplete_passability _ = let s = structure " incomplete " and u = union " incomplete " in begin assert_raises IncompleteType ( fun ( ) -> s @-> returning void ) ; assert_raises IncompleteType ( fun ( ) -> void @-> returning s ) ; assert_raises IncompleteType ( fun ( ) -> u @-> returning void ) ; assert_raise... |
let test_ocaml_values_are_not_passable_when_releasing_the_lock _ = begin assert_raises ( Unsupported " Unsupported argument type when releasing runtime lock " ) ( fun ( ) -> Foreign . foreign " puts " ( ocaml_string @-> returning int ) ~ release_runtime_lock : true ) ; let module Bindings ( F : Cstubs . FOREIGN ) = str... |
let suite = " Passability tests " >::: [ " primitives are passable " >:: test_primitives_are_passable ; " unions are not passable " >:: test_unions_are_not_passable ; " complex values passability " >:: test_complex_value_passability ; " long doubles are not passble " >:: test_ldouble_not_passable ; " arrays are not pas... |
let _ = run_test_tt_main suite |
let testlib = Dl . ( dlopen ~ filename " : clib / libtest_functions . so " ~ flags [ : RTLD_NOW ] ) |
module Common_tests ( S : Cstubs . FOREIGN with type ' a result = ' a and type ' a return = ' a ) = struct module M = Functions . Stubs ( S ) open M let test_passing_strings _ = let input = " abcdefghijklmnopqrstuvwxyz " in let len = String . length input in let buf = String . make len ' Z ' in let _ = memcpy_string_st... |
let test_ocaml_types_rejected_as_pointer_reference_types _ = assert_raises IncompleteType ( fun ( ) -> allocate ocaml_string ( ocaml_string_start " " ) ) |
let strdup = if Sys . os_type = " Win32 " then " _strdup " else " strdup " |
let test_ocaml_types_rejected_as_return_types _ = assert_raises IncompleteType ( fun ( ) -> Foreign . foreign strdup ( string @-> returning ocaml_string ) ) |
let test_pointers_to_ocaml_types_cannot_be_dereferenced _ = let p = allocate_n char 10 in let po = coerce ( ptr char ) ( ptr ocaml_string ) p in begin assert_raises IncompleteType ( fun ( ) -> !@ po ) ; assert_raises IncompleteType ( fun ( ) -> po <-@ ocaml_string_start " " ) ; end |
let test_no_higher_order_ocaml_string_support _ = begin assert_raises IncompleteType ( fun ( ) -> funptr ( void @-> returning ocaml_string ) ) end |
let suite = " Tests passing OCaml values " >::: [ " passing strings ( foreign ) " >:: Foreign_tests . test_passing_strings ; " passing strings ( stubs ) " >:: Stub_tests . test_passing_strings ; " pointer arithmetic on OCaml values ( foreign ) " >:: Foreign_tests . test_pointer_arithmetic ; " pointer arithmetic on OCam... |
let _ = run_test_tt_main suite |
let password str = Password_hash . Bytes . wipe_to_password ( Bytes . of_string str ) str |
let test_derive_secret_box_keys ctxt = let pw = password " Correct Horse Battery Staple " in let pw ' = password " Correct Battery Horse Staple " in let n = Password_hash . random_salt ( ) in let n ' = Password_hash . random_salt ( ) in let derive_interactive = Secret_box . derive_key Password_hash . interactive in let... |
let test_password_hashing ctxt = let pw = password " Correct Horse Battery Staple " in let pw ' = password " Correct Battery Horse Staple " in let h = Password_hash . Bytes . hash_password Password_hash . interactive pw in assert_bool " " = ( Password_hash . Bytes . verify_password_hash h pw ) pw ; assert_bool " " <> (... |
let suite = " Password_hash " >::: [ " test_password_hashing " >:: test_password_hashing ; " test_derive_secret_box_keys " >:: test_derive_secret_box_keys ; ] |
let eqp = eq ~ eq : Pat . equal ~ pp : Pat . pp |
let string_conv = test " Pat . { v , of_string , to_string } " @@ fun ( ) -> let trip p = eq_str p Pat . ( to_string ( v p ) ) in app_invalid ~ pp : Pat . pp Pat . v " ( " ; $ app_invalid ~ pp : Pat . pp Pat . v " ( $ a " ; app_invalid ~ pp : Pat . pp Pat . v " ( " ; $$$ app_invalid ~ pp : Pat . pp Pat . v " " ; $$$ ap... |
let dom = test " Pat . dom " @@ fun ( ) -> let eq s l = eq ~ eq : String . Set . equal ~ pp : String . Set . dump ( Pat . ( dom @@ v s ) ) ( String . Set . of_list l ) in eq " bla " [ ] ; eq " bla ha " $$ [ ] ; eq " hey ( $ bla ) " [ " bla " ] ; eq " hey ( $ bla ) ( ) " $ [ " bla " ; " " ] ; eq " hey ( $ bla ) ( $$ ha ... |
let subst = test " Pat . subst " @@ fun ( ) -> let eq ? undef defs p s = eq_str Pat . ( to_string @@ subst ? undef defs ( v p ) ) s in let defs = String . Map . of_list [ " bli " , " bla " ] in let undef = function " blu " -> Some " bla " $ | _ -> None in eq ~ undef defs " hey $$ ( $ bli ) ( $ bla ) ( $ blu ) " " hey $... |
let format = test " Pat . format " @@ fun ( ) -> let eq ? undef defs p s = eq_str ( Pat . ( format ? undef defs ( v p ) ) ) s in let defs = String . Map . of_list [ " hey " , " ho " ; " hi " , " ha " ] $ in let undef = fun _ -> " undef " in eq ~ undef defs " a $$ ( $ hu ) " " a $ undef " ; eq ~ undef defs " a ( $ hey )... |
let matches = test " Pat . matches " @@ fun ( ) -> let m p s = Pat . ( matches ( v p ) s ) in eq_bool ( m " ( $ mod ) . mli " " string . mli " ) true ; eq_bool ( m " ( $ mod ) . mli " " string . mli " ) false ; eq_bool ( m " ( $ mod ) . mli " " . mli " ) true ; eq_bool ( m " ( $ mod ) . mli " " . mli " ) false ; eq_boo... |
let query = test " Pat . query " @@ fun ( ) -> let u ? init p s = Pat . ( query ? init ( v p ) s ) in let eq = eq_option ~ eq ( : String . Map . equal String . equal ) ~ pp ( : String . Map . dump String . dump ) in let eq ? init p s = function | None -> eq ( u ? init p s ) None | Some l -> eq ( u ? init p s ) ( Some (... |
let suite = suite " Pat module " [ string_conv ; dom ; subst ; format ; matches ; query ; ] |
module Patdiff_core = Patdiff_core . Without_unix ( module struct let prev : Diff_input . t = { name = " old " ; text = " Foo bar buzz " } let next : Diff_input . t = { name = " old " ; text = " Foo buzz " } let % expect_test " Ansi output generates a single line diff " = printf " % s \ n " ( Patdiff_core . patdiff ~ s... |
let links = ( " . . . . // bin / patdiff - git - wrapper " , ` In_path_as , " patdiff - git - wrapper " ) :: links ; ; within_temp_dir ~ links ( fun ( ) -> let % bind ( ) = run " git " [ " init " ; " - q " ] in let % bind ( ) = Writer . save " foo " ~ contents " : foo bar baz \ n " in let % bind ( ) = run " git " [ " a... |
let test_resolve_local_file ( ) = let tests = [ ( " full URL simple " , " / foo / bar / baz " , " https :// example . com / images / buzz " , " / foo / bar / baz / images / buzz " ) ; ( " full URL cwd " , " / foo / bar / baz " , " https :// example . com . // buzz " , " / foo / bar / baz / buzz " ) ; ( " full URL paren... |
let ( ) = Printexc . record_backtrace true |
let ( ) = Alcotest . run " test_path " [ ( " Path " , [ ( " Check resolve_local_file " , ` Quick , test_resolve_local_file ) ] ) ; ] |
let a = Array . make 10 0 |
let f ( ) = a ( . 11 ) 11 |
let f2 x = match x with | 0 -> 1 | 1 -> 2 | 2 -> 3 |
let f3 = function | 0 -> 1 | 1 -> 2 | 3 -> 4 |
let main = h ( ) |
let f2 x = try match x with | 0 -> 1 | 1 -> 2 | 2 -> 3 with | exc -> ( Format . eprintf " Exception tracer at File " / Users / bobzhang1988 / Writing / ocaml - book / camlp4 / examples / test_pa_exception_wrapper . ml " , line 7 , characters 11 - 56 ( end at line 10 , character 10 ) 10 ( % s ) s . " @ ( Printexc . to_s... |
let f3 = function | 0 -> ( try 1 with | exc -> ( Format . eprintf " Exception tracer at File " / Users / bobzhang1988 / Writing / ocaml - book / camlp4 / examples / test_pa_exception_wrapper . ml " , line 14 , characters 9 - 10 ( % s ) s . " @ ( Printexc . to_string exc ) exc ; raise exc ) exc ) exc | 1 -> ( try 2 with... |
let main = h ( ) |
let f1 x = printf " f1 % d . " @ x ; ; |
let f2 x = printf " f2 % f . " @ x ; ; |
let f3 x = printf " f3 % s . " @ x ; ; |
let global_handler e = Format . eprintf " global_handler : % s . " @ ( Printexc . to_string e ) e Format . eprintf " global_handler : % s . " @ ( Printexc . to_string e ) e end in ( ) with ( fun e -> Format . eprintf " global_handler : % s . " @ ( Printexc . to_string e ) e ) e e |
let id = <: lam < \ x -> x x >> |
let zero = <: lam < \ s -> \ z -> s z >> |
let succ = <: lam < \ n -> \ s -> \ z -> s n >> |
let one = <: lam < $ succ $ >> |
let iota = <: lam < \ x -> z >> |
let rho = <: lam < \ m -> \ r -> ( s m ( m r iota r ) ) >> |
let rec_nat = <: lam < \ n -> \ s -> \ z -> n $ rho $ $ iota $ $ rho $ >> |
let plus = <: lam < \ n -> \ m -> $ rec_nat $ n ( \ n -> \ p -> $ succ $ p ) m >> |
let times = <: lam < \ n -> \ m -> $ rec_nat $ n ( \ n -> \ p -> $ plus $ m p ) $ zero $ >> |
let fact = <: lam < \ n -> $ rec_nat $ n ( \ n -> \ p -> $ times $ ( $ succ $ n ) p ) $ one $ >> |
let id = ` Lam ( ( ` Var " x ) " , ( ` App ( ( ` Var " x ) " , ( ` Var " x ) ) ) ) " |
let zero = ` Lam ( ( ` Var " s ) " , ( ` Lam ( ( ` Var " z ) " , ( ` App ( ( ` Var " s ) " , ( ` Var " z ) ) ) ) ) ) " |
let succ = ` Lam ( ( ` Var " n ) " , ( ` Lam ( ( ` Var " s ) " , ( ` Lam ( ( ` Var " z ) " , ( ` App ( ( ` Var " s ) " , ( ` Var " n ) ) ) ) ) ) ) ) " |
let iota = ` Lam ( ( ` Var " x ) " , ( ` Var " z ) ) " |
let rho = ` Lam ( ( ` Var " m ) " , ( ` Lam ( ( ` Var " r ) " , ( ` App ( ( ` App ( ( ` Var " s ) " , ( ` Var " m ) ) ) " , ( ` App ( ( ` App ( ( ` App ( ( ` Var " m ) " , ( ` Var " r ) ) ) " , ( ` Var " iota ) ) ) " , ( ` Var " r ) ) ) ) ) ) ) ) " |
let rec_nat = ` Lam ( ( ` Var " n ) " , ( ` Lam ( ( ` Var " s ) " , ( ` Lam ( ( ` Var " z ) " , ( ` App ( ( ` App ( ( ` App ( ( ` Var " n ) " , rho ) rho ) rho , iota ) iota ) iota , rho ) rho ) rho ) rho ) rho ) rho ) rho ) rho |
let plus = ` Lam ( ( ` Var " n ) " , ( ` Lam ( ( ` Var " m ) " , ( ` App ( ( ` App ( ( ` App ( rec_nat , ( ` Var " n ) ) ) " , ( ` Lam ( ( ` Var " n ) " , ( ` Lam ( ( ` Var " p ) " , ( ` App ( succ , ( ` Var " p ) ) ) ) ) ) ) ) ) " , ( ` Var " m ) ) ) ) ) ) " |
let times = ` Lam ( ( ` Var " n ) " , ( ` Lam ( ( ` Var " m ) " , ( ` App ( ( ` App ( ( ` App ( rec_nat , ( ` Var " n ) ) ) " , ( ` Lam ( ( ` Var " n ) " , ( ` Lam ( ( ` Var " p ) " , ( ` App ( ( ` App ( plus , ( ` Var " m ) ) ) " , ( ` Var " p ) ) ) ) ) ) ) ) ) " , zero ) zero ) zero ) zero ) zero ) zero |
let fact = ` Lam ( ( ` Var " n ) " , ( ` App ( ( ` App ( ( ` App ( rec_nat , ( ` Var " n ) ) ) " , ( ` Lam ( ( ` Var " n ) " , ( ` Lam ( ( ` Var " p ) " , ( ` App ( ( ` App ( times , ( ` App ( succ , ( ` Var " n ) ) ) ) ) " , ( ` Var " p ) ) ) ) ) ) ) ) ) " , one ) one ) one ) one |
let a = <: me < let rec fib x = >> |
let b = <: me < let f = $ a $ in f >> |
let c = <: me < $ int : x $ >> |
let d x = match x with | <: me < $ int : _ $ >> -> true | _ -> false |
let test_antiquot x = <: me < fun $ patt : x $ -> $ lid : x $ >> |
let test_antiquot2 x = <: me < let $ patt : x $ = 3 in $ lid : x $ >> |
let x = a |> generate_type_constraints |> rob |
let with_dump = with_access ~ from_dump ( : Filename . concat ( Sys . getcwd ( ) ) " lib_test / dump . data " ) |
let resident_pages ( ) = let with_channel c f = try let r = f c in close_in c ; r with exn -> close_in_noerr c ; raise exn in let statm = with_channel ( open_in " / proc / self / statm " ) input_line in Scanf . sscanf statm " % d % d % d % d % d % d % d " ( fun _ res _ _ _ _ _ -> res ) |
let smoke_test ( ) = with_dump ( fun a -> let ( _ : Pci_dev . t list ) = get_devices a in ( ) ) |
let test_with_access_cleanup ( ) = let _ = Gc . compact ( ) ; resident_pages ( ) in for i = 1 to 6000 do with_dump ~ cleanup : true ( fun _ -> ( ) ) done ; let mem = Gc . compact ( ) ; resident_pages ( ) in for i = 1 to 1000 do with_dump ~ cleanup : true ( fun _ -> ( ) ) done ; let mem ' = Gc . compact ( ) ; resident_p... |
let test_lookup_functions ( ) = let test_lookup = assert_equal ~ printer ( : fun x -> x ) in with_dump ( fun acc -> test_lookup " Bridge " @@ lookup_class_name acc 0x0680 ; test_lookup " Intel Corporation " @@ lookup_vendor_name acc 0x8086 ; test_lookup " 82371AB / EB / MB PIIX4 ACPI " @@ lookup_device_name acc 0x8086 ... |
let _ = let suite = " pci " >::: [ " smoke_test " >:: smoke_test ; " test_with_access_cleanup " >:: test_with_access_cleanup ; " test_lookup_functions " >:: test_lookup_functions ; ] in OUnit2 . run_test_tt_main @@ ounit2_of_ounit1 suite |
let string_of_group = function | Text s -> sp " Text % s " s | Delim s -> sp " Delim % s " s | Group ( x , s ) -> sp " Group ( % d % s ) " x s | NoGroup -> " NoGroup " |
let list_printer f xs = String . concat " ; " ( List . map f xs ) |
let test_blank_class _ = let re = Re . Perl . compile_pat " \\ d [ [ : blank ] ] :\\ d [ [ : blank ] ] [ :+ a - z ] " in let successes = [ " 1 2 a " ; " 2 \ t3 z " ; " 9 \ t0 \ t a " ] in let failures = [ " " ; " 123 " ; " " ; " 1 3z " ] in List . iter ( fun s -> assert_bool ( " String " ^ s ^ " should match " ) ( Re .... |
let rex = regexp " [ : _ ] " |
let split_empty _ = assert_equal ( full_split ~ rex " " ) [ ] |
let split_max_1 _ = assert_equal ( full_split ~ rex ~ max : 1 " xxx : yyy " ) [ Text " xxx : yyy " ] |
let rex = regexp " x ( x ) " ? |
let printer = list_printer string_of_group |
let group_split1 _ = let sp = full_split ~ rex " testxxyyy " in assert_equal ~ printer sp [ Text " test " ; Delim " xx " ; Group ( 1 , " x " ) ; Text " yyy " ] |
let group_split2 _ = let sp = full_split ~ rex " testxyyy " in assert_equal ~ printer sp [ Text " test " ; Delim " x " ; NoGroup ; Text " yyy " ] |
let test_fixtures = " test pcre features " >::: [ " test [ : blank ] : class " >:: test_blank_class ; " test splitting empty string " >:: split_empty ; " test split with max of 1 " >:: split_max_1 ; " test group split 1 " >:: group_split1 ; " test group split 2 - NoGroup " >:: group_split2 ] |
let _ = run_test_tt_main test_fixtures |
( module Stable_unit_test . Make ( struct include Stable . V1 let equal = equal let tests = [ of_mult 0 . 375 , " 37 . 5 " , % " \ 000 \ 000 \ 000 \ 000 \ 000 \ 000 \ 216 " ? ; of_mult 4 . 5 , " 4 . 5x " , " \ 000 \ 000 \ 000 \ 000 \ 000 \ 000 \ 018 " @ ; of_mult 0 . 0002 , " 2bp " , " - C \ 028 \ 235 \ 2266 " *? ; of_... |
let test raw_grammar = Sexp_grammar_validation . Raw_grammar . sexp_of_t raw_grammar |> Stdio . print_s ; ; test [ % sexp_grammar : < for_all : ' k ' v . ( ' k * ' v ) list > ] ; [ % expect { | ( ( generic_groups ( ( 6a84293b8771489e87de480107049eda ( ( implicit_vars ( list ) ) ( types ( ( t ( Explicit_bind ( a ) ( App... |
let eq_re ? opts r s = expect_equal_app ~ msg : s id r ( re ? opts ) s ; ; |
let parse_error_re ? opts s = try ignore ( re ? opts s ) ; OUnit2 . assert_failure s with | Re . Perl . Parse_error -> ( ) |
let _ = expect_pass " ordinary characters " ( fun ( ) -> eq_re ( char ' a ' ) " a " ; ) ; expect_pass " concatenation " ( fun ( ) -> eq_re ( seq [ char ' a ' ; char ' b ' ] ) " ab " ; ) ; expect_pass " escaping metacharacters " ( fun ( ) -> eq_re ( char ' ' ) ^ " " ; \\^ eq_re ( char ' . ' ) " . " ; \\ eq_re ( char ' '... |
let base_dir_class_testable = Alcotest . ( testable Persistence . pp_base_dir_class ( = ) ) |
let check_base_dir s bd1 bd2 = Alcotest . check base_dir_class_testable s bd1 bd2 |
let test_classify_does_not_exist = let open Lwt_tzresult_syntax in Tztest . tztest " Classify a non existing directory " ` Quick ( fun ( ) -> Lwt_utils_unix . with_tempdir " test_persistence " ( fun base_dir -> let + bd = Persistence . classify_base_dir ( Filename . concat base_dir " non_existing_directory " ) in check... |
let test_classify_is_file = let open Lwt_tzresult_syntax in Tztest . tztest " Classify a file " ` Quick ( fun ( ) -> let tmp_file = Filename . temp_file " " " " in let + bd = Persistence . classify_base_dir tmp_file in check_base_dir " A file " Base_dir_is_file bd ) |
let test_classify_is_mockup = let open Lwt_tzresult_syntax in Tztest . tztest " Classify a mockup directory " ` Quick ( fun ( ) -> Lwt_utils_unix . with_tempdir " test_persistence " ( fun dirname -> let mockup_directory = ( Files . get_mockup_directory ~ dirname :> string ) and mockup_file_name = Files . Context . get ... |
let test_classify_is_nonempty = let open Lwt_tzresult_syntax in Tztest . tztest " Classify a non empty directory " ` Quick ( fun ( ) -> Lwt_utils_unix . with_tempdir " test_persistence " ( fun temp_dir -> let _ = Filename . temp_file ~ temp_dir " " " " in let + bd = Persistence . classify_base_dir temp_dir in check_bas... |
let test_classify_is_empty = let open Lwt_tzresult_syntax in Tztest . tztest " Classify an empty directory " ` Quick ( fun ( ) -> Lwt_utils_unix . with_tempdir " test_persistence " ( fun base_dir -> let + bd = Persistence . classify_base_dir base_dir in check_base_dir " An empty directory " Base_dir_is_empty bd ) ) |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.