diff --git a/package.json b/package.json index 8980fe26..bc51d0bb 100644 --- a/package.json +++ b/package.json @@ -25,16 +25,10 @@ "jest": "^26.5.2", "docsify-cli": "~4.4.0" }, - "dependencies": { - "bisect_ppx": "^2.7.1" - }, "jest": { "verbose": false, "testMatch": [ "/_build/default/__tests__/output/__tests__/**/*_test.[jt]s?(x)" - ], - "setupFilesAfterEnv": [ - "/_build/default/__tests__/output/node_modules/relude/bisect_ppx/runtime/js/jest.js" ] } } diff --git a/src/bisect_ppx/common/bisect_common.ml b/src/bisect_ppx/common/bisect_common.ml deleted file mode 100755 index c1176ac4..00000000 --- a/src/bisect_ppx/common/bisect_common.ml +++ /dev/null @@ -1,105 +0,0 @@ -(* This file is part of Bisect_ppx, released under the MIT license. See - LICENSE.md for details, or visit - https://github.com/aantron/bisect_ppx/blob/master/LICENSE.md. *) - - - -(* Basic types and file [bisect*.coverage] file identifier. Shared with the - reporter. *) - -type instrumented_file = { - filename : string; - points : int array; - counts : int array; -} - -type coverage = (string, instrumented_file) Hashtbl.t - -let coverage_file_identifier = "BISECT-COVERAGE-4" - - - -(* Output functions for the [bisect*.coverage] file format. *) - -let write_int formatter i = - Format.fprintf formatter " %i" i - -let write_string formatter s = - Format.fprintf formatter " %i %s" (String.length s) s - -let write_array write_element formatter a = - Format.fprintf formatter " %i" (Array.length a); - Array.iter (write_element formatter) a - -let write_list write_element formatter l = - Format.fprintf formatter " %i" (List.length l); - List.iter (write_element formatter) l - -let write_instrumented_file formatter {filename; points; counts} = - write_string formatter filename; - write_array write_int formatter points; - write_array write_int formatter counts - -let write_coverage formatter coverage = - Format.fprintf formatter "%s" coverage_file_identifier; - write_list write_instrumented_file formatter coverage; - Format.pp_print_flush formatter () - - - -(* Accumulated visit counts. This is used only by the native and ReScript - runtimes. It is idly linked as part of this module into the PPX and reporter, - as well, but not used by them. *) - -let coverage : coverage Lazy.t = - lazy (Hashtbl.create 17) - -let register_file ~filename ~points = - let counts = Array.make (Array.length points) 0 in - let coverage = Lazy.force coverage in - if not (Hashtbl.mem coverage filename) then - Hashtbl.add coverage filename {filename; points; counts}; - `Visit (fun index -> - let current_count = counts.(index) in - if current_count < max_int then - counts.(index) <- current_count + 1) - -let flatten_coverage coverage = - Hashtbl.fold (fun _ file acc -> file::acc) coverage [] - -let flatten_data () = - flatten_coverage (Lazy.force coverage) - -let reset_counters () = - Lazy.force coverage - |> Hashtbl.iter begin fun _ {counts; _} -> - match Array.length counts with - | 0 -> () - | n -> Array.fill counts 0 (n - 1) 0 - end - - - -(** Helpers for serializing the coverage data in {!coverage}. *) - -let runtime_data_to_string () = - match flatten_data () with - | [] -> - None - | data -> - let buffer = Buffer.create 4096 in - write_coverage (Format.formatter_of_buffer buffer) data; - Some (Buffer.contents buffer) - -let write_runtime_coverage coverage channel = - write_coverage (Format.formatter_of_out_channel channel) (flatten_coverage coverage) - -let write_runtime_data channel = - write_coverage (Format.formatter_of_out_channel channel) (flatten_data ()) - -let prng = - Random.State.make_self_init () [@coverage off] - -let random_filename ~prefix = - Printf.sprintf "%s%09d.coverage" - prefix (abs (Random.State.int prng 1000000000)) diff --git a/src/bisect_ppx/common/bisect_common.mli b/src/bisect_ppx/common/bisect_common.mli deleted file mode 100755 index 88ad5a4a..00000000 --- a/src/bisect_ppx/common/bisect_common.mli +++ /dev/null @@ -1,88 +0,0 @@ -(* This file is part of Bisect_ppx, released under the MIT license. See - LICENSE.md for details, or visit - https://github.com/aantron/bisect_ppx/blob/master/LICENSE.md. *) - - - -(** This module provides type definitions and functions that are shared between - more than one part of Bisect, namely: - - - the instrumenter (PPX) - - the native runtime ([Bisect.Runtime] in [src/runtime/native/]) - - the ReScript runtime ([Bisect.Runtime] in [src/runtime/js/]) - - the reporter ([bisect-ppx-report]) *) - - - -(** {1 Types} - - Types representing accumulated visit counts. This data is written to - [bisect*.coverage] files when an instrumented binary exits. - - The two types in this section, {!instrumented_file} and {!coverage}, and the - value {!coverage_file_identifier}, are the only items shared with the - reporter. Otherwise, the reporter is self-contained. *) - -type instrumented_file = { - filename : string; (** Source file name. *) - points : int array; (** Byte offsets of the points placed in the file. *) - counts : int array; (** Visitation counts, one for each point. *) -} -(** Data gathered for a single source file. *) - -type coverage = (string, instrumented_file) Hashtbl.t -(** A binary instrumented with Bisect, when run, produces coverage statistics - for each of its source files. The runtime and reporter both index the - statistics by source file name. *) - -val coverage_file_identifier : string -(** A string written at the beginning of each [bisect*.coverage] files. Provides - a sanity check for the reporter that it is reading a [bisect*.coverage] - file, and the file format version. *) - - - -(** {1 Initialization} *) - -val register_file : - filename:string -> points:int array -> [`Visit of (int -> unit)] -(** Each source file is instrumented to call {!Bisect.Runtime.register_file} at - run time, during program initialization. {!Bisect.Runtime.register_file} - eventually forwards to this function, {!Biesct_common.register_file}. This - function allocates the visit count array, with one array cell for each - point, and registers the array for later writing to [bisect*.coverage] - files. - - - [~filename] is the name of the source file. - - [~points] is the list of byte offsets of the instrumentation points placed - in the source file. - - The return value is the function that is called by each instrumentation - point to increment its own visit count. The instrumentation point passes its - own index to the function. *) - - - -(** {1 [.coverage] output} *) - -val write_runtime_coverage : coverage -> out_channel -> unit -(** Writes the [coverage] to the given output channel. *) - -val write_runtime_data : out_channel -> unit -(** Writes the current accumulated coverage data (of type {!coverage}) to the - given output channel. *) - -val runtime_data_to_string : unit -> string option -(** Same as {!write_runtime_data}, but writes the output to a string instead. - - [None] is returned if there are no source files registered. This can occur - when the runtime gets linked into a binary, but no files had been - instrumented, because instrumentation was turned off. This combination - normally shouldn't happen, but it can occur depending on the quality of the - integration between the build system and Bisect. *) - -val reset_counters : unit -> unit -(** Clears accumulated visit counts. All array cells are set to zero. *) - -val random_filename : prefix:string -> string -(** Returns a random filename with the given prefix. *) diff --git a/src/bisect_ppx/runtime/js/jest.ml b/src/bisect_ppx/runtime/js/jest.ml deleted file mode 100755 index 191a7c8a..00000000 --- a/src/bisect_ppx/runtime/js/jest.ml +++ /dev/null @@ -1,17 +0,0 @@ -(* If we make a curried binding of afterAll, BuckleScript will compile it like - this: - - afterAll((function (param) { // <-- notice "param" - // ... snip ... - })); - - this will cause timeout in Jest because Jest will wait until you manually - invoke param.done() within afterAll. *) -external afterAll : ((unit -> unit) [@mel]) -> unit = "afterAll" - -let () = - afterAll - ((fun () -> - Runtime.write_coverage_data (); - Runtime.reset_coverage_data ()) - [@mel]) diff --git a/src/bisect_ppx/runtime/js/runtime.ml b/src/bisect_ppx/runtime/js/runtime.ml deleted file mode 100755 index 254dd8bf..00000000 --- a/src/bisect_ppx/runtime/js/runtime.ml +++ /dev/null @@ -1,49 +0,0 @@ -(* This file is part of Bisect_ppx, released under the MIT license. See - LICENSE.md for details, or visit - https://github.com/aantron/bisect_ppx/blob/master/LICENSE.md. *) - - - -let get_coverage_data = - Bisect_common.runtime_data_to_string - -let write_coverage_data () = - match get_coverage_data () with - | None -> - () - | Some data -> - let rec create_file attempts = - let filename = Bisect_common.random_filename ~prefix:"bisect" in - match Node.Fs.openSync filename `Write_fail_if_exists with - | exception exn -> - if attempts = 0 then - raise exn - else - create_file (attempts - 1) - | _ -> - Node.Fs.writeFileSync filename data `binary - in - create_file 100 - -let reset_coverage_data = - Bisect_common.reset_counters - -let node_at_exit = [%mel.raw {| - function (callback) { - if (typeof process !== 'undefined' && typeof process.on !== 'undefined') - process.on("exit", callback); - } -|}] - -let exit_hook_added = ref false - -let [@warning "-20-21"] write_coverage_data_on_exit () = - if not !exit_hook_added then begin - node_at_exit (fun () -> write_coverage_data (); reset_coverage_data ()); - exit_hook_added := true - end - -let register_file - ~bisect_file:_ ~bisect_silent:_ ~bisect_sigterm:_ ~filename ~points = - write_coverage_data_on_exit (); - Bisect_common.register_file ~filename ~points diff --git a/src/bisect_ppx/runtime/js/runtime.mli b/src/bisect_ppx/runtime/js/runtime.mli deleted file mode 100755 index 41ecf4c0..00000000 --- a/src/bisect_ppx/runtime/js/runtime.mli +++ /dev/null @@ -1,37 +0,0 @@ -(* This file is part of Bisect_ppx, released under the MIT license. See - LICENSE.md for details, or visit - https://github.com/aantron/bisect_ppx/blob/master/LICENSE.md. *) - - - -val register_file : - bisect_file:string option -> - bisect_silent:string option -> - bisect_sigterm:bool -> - filename:string -> - points:int array -> - [`Visit of (int -> unit)] -(** [register_file file ~bisect_file ~bisect_silent ~point_count - ~point_definitions] indicates that the file [file] is part of the - application that has been instrumented. [point_definitions] is a serialized - [Common.point_definition list] giving the locations of all points in the - file. The returned callback is used to increment visitation counts. - - [~bisect_file], [~bisect_silent], and [~bisect_sigterm] are ignored. *) - -val get_coverage_data : unit -> string option -(** Returns the binary coverage data accumulated by the program so far. This - should eventually be written to a file, to be processed by - [bisect-ppx-report]. *) - -val write_coverage_data : unit -> unit -(** On Node.js, writes the same coverage data that is returned by - {!get_coverage_data} to a [.coverage] file with a randomized name in the - current directory. *) - -val write_coverage_data_on_exit : unit -> unit -(** Registers {!write_coverage_data} to be called automatically on process - exit. *) - -val reset_coverage_data : unit -> unit -(** [reset_coverage_data ()] clears accumulated coverage statistics. *) diff --git a/yarn.lock b/yarn.lock index 2382133f..0e64c9da 100644 --- a/yarn.lock +++ b/yarn.lock @@ -867,11 +867,6 @@ binary-extensions@^2.0.0: resolved "https://registry.npmjs.org/binary-extensions/-/binary-extensions-2.2.0.tgz" integrity sha512-jDctJ/IVQbZoJykoeHbhXpOlNBqGNcwXJKJog42E5HDPUwQTSdjCHdihjj0DlnheQ7blbT6dHOafNAiS8ooQKA== -bisect_ppx@^2.7.1: - version "2.7.1" - resolved "https://registry.npmjs.org/bisect_ppx/-/bisect_ppx-2.7.1.tgz" - integrity sha512-e8gRgfhmCptiyGGov+54Acah+rc+svm0yc/26mn+M6CCNDADufVLMgRaG1uw3LAHm/PFPy+zGFAKMwd6lD2O2g== - boxen@^4.2.0: version "4.2.0" resolved "https://registry.npmjs.org/boxen/-/boxen-4.2.0.tgz"