-
Notifications
You must be signed in to change notification settings - Fork 400
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #6938 The semantics of `(enabled_if)` in `(test)` can be confusing: `(test)` can be seen as the combination of `(executable)` and a `(rule (alias runtest))`; but `(enabled_if)` actually only controls the "running" part, not the "building" one. This adds a new `(build_if)` field in `(test)`. When it evaluates to false, the test stanza is bypassed (no build is attempted). Signed-off-by: Etienne Millon <me@emillon.org>
- Loading branch information
Showing
10 changed files
with
197 additions
and
30 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
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
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
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
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
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
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
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,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 | ||
|
||
$ cat > dune << EOF | ||
> (test | ||
> (name t) | ||
> (enabled_if %{env:ENABLED=false})) | ||
> 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 | ||
> } | ||
|
||
$ test_all () { | ||
> test_one @all | ||
> test_one @runtest | ||
> ENABLED=true test_one @all | ||
> ENABLED=true test_one @runtest | ||
> } | ||
|
||
$ 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 | ||
|
||
Now with build_if: | ||
|
||
$ cat > dune << EOF | ||
> (test | ||
> (name t) | ||
> (build_if %{env:ENABLED=false})) | ||
> EOF | ||
|
||
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] |
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,25 @@ | ||
$ cat > dune-project << EOF | ||
> (lang dune 3.8) | ||
> EOF | ||
|
||
$ cat > dune << EOF | ||
> (test | ||
> (name t) | ||
> (build_if true)) | ||
> EOF | ||
|
||
$ touch t.ml | ||
|
||
$ dune build | ||
File "dune", line 3, characters 1-16: | ||
3 | (build_if true)) | ||
^^^^^^^^^^^^^^^ | ||
Error: 'build_if' is only available since version 3.9 of the dune language. | ||
Please update your dune-project file to have (lang dune 3.9). | ||
[1] | ||
|
||
$ cat > dune-project << EOF | ||
> (lang dune 3.9) | ||
> EOF | ||
|
||
$ dune build |