Merge pull request #1069 from rgrinberg/port-enabled-if-tests

Port enabled if tests
This commit is contained in:
Rudi Grinberg 2018-07-31 17:35:35 +02:00 committed by GitHub
commit 9ea98b1846
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 75 additions and 86 deletions

View File

@ -1,2 +1,2 @@
(lang dune 1.0)
(lang dune 1.1)
(name dune)

View File

@ -11,9 +11,9 @@ module Op = struct
let eval t (x : Ordering.t) =
match t, x with
| (Eq | Gte | Lte) , Eq
| (Lt | Lte) , Lt
| (Gt | Gte) , Gt -> true
| (Eq | Gte | Lte) , Eq
| (Neq | Lt | Lte) , Lt
| (Neq | Gt | Gte) , Gt -> true
| _, _ -> false
end

View File

@ -82,16 +82,16 @@ let alias sctx ~dir ~scope (alias_conf : Alias_conf.t) =
} in
Blang.eval_bool blang ~dir ~f
in
let stamp =
let module S = Sexp.To_sexp in
Sexp.List
[ Sexp.unsafe_atom_of_string "user-alias"
; Jbuild.Bindings.sexp_of_t Jbuild.Dep_conf.sexp_of_t alias_conf.deps
; S.option Action.Unexpanded.sexp_of_t
(Option.map alias_conf.action ~f:snd)
]
in
if enabled then
let stamp =
let module S = Sexp.To_sexp in
Sexp.List
[ Sexp.unsafe_atom_of_string "user-alias"
; Jbuild.Bindings.sexp_of_t Jbuild.Dep_conf.sexp_of_t alias_conf.deps
; S.option Action.Unexpanded.sexp_of_t
(Option.map alias_conf.action ~f:snd)
]
in
add_alias sctx
~dir
~name:alias_conf.name
@ -112,3 +112,9 @@ let alias sctx ~dir ~scope (alias_conf : Alias_conf.t) =
~targets:Alias
~targets_dir:dir
~scope)
else
add_alias sctx
~dir
~name:alias_conf.name
~stamp
(Build.return (Action.Progn []))

View File

@ -16,6 +16,11 @@ let to_int = function
| Eq -> 0
| Gt -> 1
let to_string = function
| Lt -> "<"
| Eq -> "="
| Gt -> ">"
let neq = function
| Eq -> false
| Lt | Gt -> true

View File

@ -8,4 +8,7 @@ type t =
val of_int : int -> t
val to_int : t -> int
(** returns the string representation. one of: "<", "=", ">" *)
val to_string : t -> string
val neq : t -> bool

View File

@ -100,17 +100,15 @@ and postprocess tbl b = parse
let () =
let skip_versions = ref [] in
let skip_platforms = ref [] in
let expect_test = ref None in
let args =
(Platform.argv skip_platforms)
:: [ "-skip-versions"
, Arg.String (fun s -> skip_versions := parse_skip_versions s)
, "Comma separated versions of ocaml where to skip test"
; "-test"
, Arg.String (fun s -> expect_test := Some s)
, "expect test file"
] in
[ "-skip-versions"
, Arg.String (fun s -> skip_versions := parse_skip_versions s)
, "Comma separated versions of ocaml where to skip test"
; "-test"
, Arg.String (fun s -> expect_test := Some s)
, "expect test file"
] in
Configurator.main ~args ~name:"cram" (fun configurator ->
let expect_test =
match !expect_test with
@ -123,12 +121,6 @@ and postprocess tbl b = parse
if List.exists !skip_versions ~f:(fun (op, v') ->
test op ocaml_version v') then
exit 0;
let platform =
Configurator.ocaml_config_var_exn configurator "system" in
if List.exists !skip_platforms ~f:(fun p ->
Platform.to_string p = platform
) then
exit 0;
end;
Test_common.run_expect_test expect_test ~f:(fun file_contents lexbuf ->
let items = file lexbuf in

View File

@ -1,20 +1,15 @@
(ignored_subdirs (test-cases))
(library
(name platform)
(modules platform)
(libraries stdune))
(executable
(name cram)
(modules cram)
(libraries test_common platform dune configurator))
(libraries test_common dune configurator))
(ocamllex cram)
(executable
(name gen_tests)
(libraries stdune platform usexp)
(libraries stdune usexp)
(modules gen_tests))
(include dune.inc)

View File

@ -52,9 +52,8 @@
(action
(chdir
test-cases/configurator
(progn
(run %{exe:cram.exe} -skip-platforms win -test run.t)
(diff? run.t run.t.corrected)))))
(progn (run %{exe:cram.exe} -test run.t) (diff? run.t run.t.corrected))))
(enabled_if (<> %{ocaml-config:system} win)))
(alias
(name copy_files)
@ -315,9 +314,8 @@
(action
(chdir
test-cases/github764
(progn
(run %{exe:cram.exe} -skip-platforms win -test run.t)
(diff? run.t run.t.corrected)))))
(progn (run %{exe:cram.exe} -test run.t) (diff? run.t run.t.corrected))))
(enabled_if (<> %{ocaml-config:system} win)))
(alias
(name github784)
@ -535,15 +533,10 @@
(chdir
test-cases/output-obj
(progn
(run
%{exe:cram.exe}
-skip-versions
<4.06.0
-skip-platforms
macosx,win
-test
run.t)
(diff? run.t run.t.corrected)))))
(run %{exe:cram.exe} -skip-versions <4.06.0 -test run.t)
(diff? run.t run.t.corrected))))
(enabled_if
(and (<> %{ocaml-config:system} macosx) (<> %{ocaml-config:system} win))))
(alias
(name package-dep)

View File

@ -18,14 +18,40 @@ module Sexp = struct
|> Usexp.Ast.remove_locs
end
let alias ?action name ~deps =
module Platform = struct
type t = Win | Mac
open Usexp
let to_string = function
| Win -> "win"
| Mac -> "macosx"
let t t = atom (to_string t)
let system_var = Sexp.parse "%{ocaml-config:system}"
let enabled_if = function
| [] -> None
| [x] -> Some (List [atom "<>"; system_var; t x])
| ps ->
Some (List (
atom "and"
:: List.map ps ~f:(fun p -> List [atom "<>"; system_var; t p])
))
end
let alias ?enabled_if ?action name ~deps =
Sexp.constr "alias"
(Sexp.fields (
[ "name", [Usexp.atom name]
; "deps", deps
] @ (match action with
| None -> []
| Some a -> ["action", [a]])))
| Some a -> ["action", [a]])
@ (match enabled_if with
| None -> []
| Some e -> ["enabled_if", [e]])))
module Test = struct
type t =
@ -56,7 +82,7 @@ module Test = struct
| None -> []
| Some s -> ["-skip-versions"; s]
in
let skip_platforms = Platform.to_cmd t.skip_platforms in
let enabled_if = Platform.enabled_if t.skip_platforms in
let action =
List
[ atom "chdir"
@ -67,9 +93,7 @@ module Test = struct
([ atom "run"
; Sexp.parse "%{exe:cram.exe}" ]
@ (List.map ~f:Usexp.atom_or_quoted_string
(skip_version
@ skip_platforms
@ ["-test"; "run.t"])))
(skip_version @ ["-test"; "run.t"])))
; Sexp.strings ["diff?"; "run.t"; "run.t.corrected"]
]
@ -84,6 +108,7 @@ module Test = struct
; v
; action ] in
alias t.name
?enabled_if
~deps:(
[ Sexp.strings ["package"; "dune"]
; Sexp.strings [ "source_tree"

View File

@ -1,30 +0,0 @@
open Stdune
type t = Win | Mac
let to_string = function
| Win -> "win"
| Mac -> "macosx"
let of_string = function
| "macosx" -> Mac
| "win" -> Win
| s -> invalid_arg ("Platform.of_string: " ^ s)
let arg_name = "-skip-platforms"
let to_cmd = function
| [] -> []
| l ->
[ arg_name
; String.concat ~sep:"," (List.map ~f:to_string l)]
let of_args args =
String.split ~on:',' args
|> List.map ~f:of_string
let argv v =
( arg_name
, Arg.String (fun s -> v := of_args s)
, "Comma separated versions of ocaml where to skip test"
)