Skip to content

Commit

Permalink
Switch to cram tests for instrumentation testing
Browse files Browse the repository at this point in the history
Resolves #340.
Resolves #342.
  • Loading branch information
aantron committed Oct 30, 2020
1 parent 9bdc5da commit beb80b3
Show file tree
Hide file tree
Showing 148 changed files with 2,388 additions and 2,682 deletions.
37 changes: 34 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
sudo: required
language: generic
dist: focal

scripts:
- &bucklescript
Expand Down Expand Up @@ -83,10 +84,30 @@ scripts:
opam switch create . $COMPILER $REPOSITORIES --no-install
fi
- eval `opam config env`
- ocaml -version
- ocamlc -version
- opam --version

- opam install -y --with-test --deps-only .
- |
case `ocamlc -version` in
"4.02.3") OCAMLFORMAT_BINARY=YES;;
"4.03.0") OCAMLFORMAT_BINARY=YES;;
"4.04.2") OCAMLFORMAT_BINARY=YES;;
"4.05.0") OCAMLFORMAT_BINARY=YES;;
esac
- |
if [ "$OCAMLFORMAT_BINARY" == YES ]
then
opam install -y --deps-only .
opam install -y --unset-root ocamlfind ounit2
wget https://github.com/aantron/ocamlformat-binary/releases/download/0.15.0/ocamlformat
sudo mv ocamlformat /usr/local/bin/ocamlformat
sudo chmod a+x /usr/local/bin/ocamlformat
else
opam install -y --deps-only . --with-test
fi
- which ocamlformat
- ocamlformat --version

- opam list

script:
Expand All @@ -96,7 +117,17 @@ scripts:
cp -r _cache/_build .
fi
- make build
- (unset TRAVIS && unset TRAVIS_JOB_ID && make test)
- |
case `ocamlc -version` in
"4.02.3") TEST_ALIAS=@compatible;;
"4.03.0") TEST_ALIAS=@compatible;;
"4.04.2") TEST_ALIAS=@compatible;;
"4.05.0") TEST_ALIAS=@compatible;;
"4.06.1") TEST_ALIAS=@compatible;;
"4.07.1") TEST_ALIAS=@compatible;;
*) TEST_ALIAS=@runtest;;
esac
- (unset TRAVIS && unset TRAVIS_JOB_ID && make test TEST=$TEST_ALIAS)
- |
if [ ! -d _cache/_build ]
then
Expand Down
11 changes: 9 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,15 @@
build :
dune build -p bisect_ppx

TEST := @runtest

.PHONY : test
test : build
dune runtest -p bisect_ppx --force --no-buffer -j 1
dune build -p bisect_ppx $(TEST)

.PHONY : promote
promote :
dune promote

SELF_COVERAGE := _self

Expand Down Expand Up @@ -67,6 +73,7 @@ self-coverage-workspace :
cp -r $(SOURCES) $(SELF_COVERAGE)/bisect_ppx/
mkdir -p $(SELF_COVERAGE)/bisect_ppx/test
cp -r test/unit $(SELF_COVERAGE)/bisect_ppx/test/
cp -r test/instrument $(SELF_COVERAGE)/bisect_ppx/test/
cd $(SELF_COVERAGE)/meta_bisect_ppx && \
patch --no-backup-if-mismatch -p2 < ../../test/self/meta_bisect_ppx.diff
cd $(SELF_COVERAGE)/bisect_ppx && \
Expand Down Expand Up @@ -108,7 +115,7 @@ self-coverage-test :
cd $(SELF_COVERAGE) && rm -f bisect*.meta
cd $(SELF_COVERAGE) && dune build @install --instrument-with meta_bisect_ppx
cd $(SELF_COVERAGE) && \
dune runtest --force --no-buffer -j 1 --instrument-with meta_bisect_ppx
dune build --force --instrument-with meta_bisect_ppx $(TEST)
rm -rf _coverage
cd $(SELF_COVERAGE) && \
_build/install/default/bin/meta-bisect-ppx-report \
Expand Down
8 changes: 8 additions & 0 deletions bisect_ppx.opam
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,17 @@ depends: [
"ppx_tools_versioned" {>= "5.4.0"}

"ocamlfind" {with-test}
"ocamlformat" {with-test & = "git.1bf68a7"}
"ounit2" {with-test}
]

pin-depends: [
# This is the last commit before ocamlformat's ppxlib conversion. A newer
# commit, or no pin at all, can be used once Bisect_ppx is also converted to
# ppxlib.
["ocamlformat.git.1bf68a7" "git+https://github.com/ocaml-ppx/ocamlformat.git#1bf68a70f1480df80a8ab0bd20a799b8e1df0081"]
]

build: [
["dune" "build" "-p" name "-j" jobs]
["dune" "runtest" "-p" name] {with-test}
Expand Down
1 change: 1 addition & 0 deletions dune-project
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
(lang dune 2.7)
(cram enable)
3 changes: 2 additions & 1 deletion src/common/bisect_common.ml
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ let write_runtime_data channel =
output_string channel data

let () =
Random.self_init ()
Random.self_init () [@coverage off]

let random_filename base_name =
Printf.sprintf "%s%09d.coverage" base_name (abs (Random.int 1000000000))
Expand Down Expand Up @@ -229,6 +229,7 @@ let bisect_silent = ref None

type options = (Arg.key * Arg.spec * Arg.doc) list

[@@@coverage off]
let deprecated binary basename options =
let make make_spec fn =
(basename,
Expand Down
2 changes: 1 addition & 1 deletion src/ppx/exclusions.ml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ type t =

let excluded = ref []

let function_separator = Str.regexp "[ \t]*,[ \t]*"
let function_separator = Str.regexp "[ \t]*,[ \t]*" [@coverage off]

let add s =
let patterns = Str.split function_separator s in
Expand Down
23 changes: 14 additions & 9 deletions src/ppx/instrument.ml
Original file line number Diff line number Diff line change
Expand Up @@ -528,9 +528,9 @@ struct
(C B, D E), [loc B, loc E]
(C B, D F), [loc B, loc F]
During recursion, the invariant on the location is that it is the
location of the nearest enclosing or-pattern, or the entire pattern, if
there is no enclosing or-pattern. *)
During recursion, the invariant on the location is that it is the
location of the nearest enclosing or-pattern, or the entire pattern, if
there is no enclosing or-pattern. *)
and rotate_or_patterns_to_top loc p : rotated_case list =

let rec recurse ~enclosing_loc p : rotated_case list =
Expand Down Expand Up @@ -636,7 +636,7 @@ struct
pattern lists (on the left side) into tuples.
This is typical of "and-patterns", i.e. those that match various
product types (though that carry multiple pieces of data
product types (those that carry multiple pieces of data
simultaneously). *)
| Ppat_tuple ps ->
ps
Expand Down Expand Up @@ -710,6 +710,8 @@ struct

| Ppat_or (p_1, p_2) ->
has_exception_pattern p_1 || has_exception_pattern p_2
(* Should be unreachable, because or-patterns will have been rotated out
of all patterns by the time this is called. *)

| Ppat_constraint (p', _) ->
has_exception_pattern p'
Expand Down Expand Up @@ -1356,17 +1358,20 @@ class instrumenter =
| Pexp_letexception (c, e) ->
Exp.letexception ~loc ~attrs c (traverse ~is_in_tail_position e)

| Pexp_open (m, e) ->
Exp.open_ ~loc ~attrs
(self#open_declaration m)
(traverse ~is_in_tail_position e)

(* Expressions that don't need instrumentation, and where AST
traversal leaves the expression language. *)
| Pexp_object c ->
Exp.object_ ~loc ~attrs (self#class_structure c)

| Pexp_pack m ->
Exp.pack ~loc ~attrs (self#module_expr m)

| Pexp_open (m, e) ->
Exp.open_ ~loc ~attrs
(self#open_declaration m)
(traverse ~is_in_tail_position e)

(* Expressions that are not recursively traversed at all. *)
| Pexp_extension _ | Pexp_unreachable ->
e
end
Expand Down
2 changes: 1 addition & 1 deletion src/ppx/register.ml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ let switches = [
" Default value for BISECT_SILENT environment variable");
]

let deprecated = Common.deprecated "bisect_ppx"
let deprecated = Common.deprecated "bisect_ppx" [@coverage off]

let switches =
switches
Expand Down
3 changes: 0 additions & 3 deletions test/inspect/dune

This file was deleted.

Loading

0 comments on commit beb80b3

Please sign in to comment.