-
Notifications
You must be signed in to change notification settings - Fork 397
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
103 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,76 @@ | ||
enabled_if has a limitation: it attempts building even if enabled_if evaluates to false. | ||
|
||
$ cat > dune-project << EOF | ||
> (lang dune 3.9) | ||
> EOF | ||
|
||
The fields evaluates to true then var=true is passed. | ||
|
||
$ cat > dune << EOF | ||
> (test | ||
> (name t) | ||
> (build_if %{env:BUILD=false}) | ||
> (enabled_if %{env:RUN=false})) | ||
> (enabled_if %{env:ENABLED=false})) | ||
> EOF | ||
|
||
$ cat > t.ml << EOF | ||
> broken | ||
> EOF | ||
$ touch t.ml | ||
|
||
We test the various combinations: | ||
|
||
$ test_one () { | ||
> dune clean | ||
> output=$( dune build "$1" --display short 2>&1 ) | ||
> echo When building $1 with ENABLED=${ENABLED:-unset}: | ||
> if echo $output|grep -q ocamlopt ; then | ||
> echo ' build was done: YES' | ||
> else | ||
> echo ' build was done: NO' | ||
> fi | ||
> if echo $output|grep -q "alias runtest" ; then | ||
> echo ' test did run: YES' | ||
> else | ||
> echo ' test did run: NO' | ||
> fi | ||
> } | ||
|
||
The build is attempted only when the enabled_if clause evaluates to true. | ||
$ test_all () { | ||
> test_one @all | ||
> test_one @runtest | ||
> ENABLED=true test_one @all | ||
> ENABLED=true test_one @runtest | ||
> } | ||
|
||
$ dune build | ||
$ BUILD=true dune build | ||
File "t.ml", line 1, characters 0-6: | ||
1 | broken | ||
^^^^^^ | ||
Error: Unbound value broken | ||
[1] | ||
$ test_all | ||
When building @all with ENABLED=unset: | ||
build was done: YES | ||
test did run: NO | ||
When building @runtest with ENABLED=unset: | ||
build was done: NO | ||
test did run: NO | ||
When building @all with ENABLED=true: | ||
build was done: YES | ||
test did run: NO | ||
When building @runtest with ENABLED=true: | ||
build was done: YES | ||
test did run: YES | ||
|
||
In the presence of both enabled_if and build_if, the test only runs if both | ||
conditions hold. | ||
Now with build_if: | ||
|
||
$ cat > t.ml << EOF | ||
> let () = exit 1 | ||
$ cat > dune << EOF | ||
> (test | ||
> (name t) | ||
> (build_if %{env:ENABLED=false})) | ||
> EOF | ||
|
||
$ dune runtest | ||
$ BUILD=true dune runtest | ||
$ RUN=true dune runtest | ||
$ BUILD=true RUN=true dune runtest | ||
File "dune", line 2, characters 7-8: | ||
2 | (name t) | ||
^ | ||
Command exited with code 1. | ||
[1] | ||
Notice that in the first case, nothing is done at all: | ||
|
||
$ test_all | ||
When building @all with ENABLED=unset: | ||
build was done: NO | ||
test did run: NO | ||
When building @runtest with ENABLED=unset: | ||
build was done: NO | ||
test did run: NO | ||
When building @all with ENABLED=true: | ||
build was done: YES | ||
test did run: NO | ||
When building @runtest with ENABLED=true: | ||
build was done: YES | ||
test did run: YES |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
build_if is compatible with package. | ||
|
||
This is important to test because in that case, (test) can not be split into two stanzas: | ||
|
||
$ cat > dune-project << EOF | ||
> (lang dune 3.9) | ||
> | ||
> (package (name a) (allow_empty)) | ||
> EOF | ||
|
||
$ cat > dune << EOF | ||
> (test | ||
> (name t) | ||
> (package a) | ||
> (build_if %{env:ENABLED=false})) | ||
> EOF | ||
|
||
$ touch t.ml | ||
|
||
$ dune runtest | ||
|
||
If we try to split it we get an error: | ||
|
||
$ cat > dune << EOF | ||
> (executable | ||
> (name t) | ||
> (package a) | ||
> (enabled_if %{env:ENABLED=false})) | ||
> | ||
> (rule | ||
> (alias runtest) | ||
> (action (run ./t.exe)) | ||
> (package a) | ||
> (enabled_if %{env:ENABLED=false})) | ||
> EOF | ||
|
||
$ dune runtest | ||
File "dune", line 3, characters 1-12: | ||
3 | (package a) | ||
^^^^^^^^^^^ | ||
Error: This field is useless without a (public_name ...) field. | ||
[1] |