This commit is contained in:
swrup 2025-11-11 02:07:51 +01:00
parent aa2ff7b2f0
commit 2f3113f55d
11742 changed files with 1223940 additions and 0 deletions

View file

@ -0,0 +1,40 @@
Tests for promoting directory targets
-------------------------------------
$ cat > dune-project << EOF
> (lang dune 3.0)
> (using directory-targets 0.1)
> EOF
$ cat > dune << EOF
> (rule
> (deps
> (source_tree deep))
> (targets
> (dir deep_copied))
> (mode promote)
> (action
> (run cp -r deep deep_copied)))
> EOF
Let's create the directory structure we are going to promote (as a copy on
another dir):
$ mkdir -p deep/a/
$ touch deep/a/deep_file
$ touch deep/base_file
Let's try this:
$ dune build deep_copied
This one works. Now, let's add a layer between base_file and deep_file:
$ rm -rf deep
$ mkdir -p deep/a/b/
$ touch deep/a/b/deep_file
$ touch deep/base_file
$ dune build deep_copied
It now works!

View file

@ -0,0 +1,108 @@
Depending on a promoted file works.
$ cat > dune-project <<EOF
> (lang dune 2.0)
> EOF
$ cat > dune <<EOF
> (rule
> (mode promote)
> (deps original)
> (target promoted)
> (action (copy %{deps} %{target})))
> (rule
> (deps promoted)
> (target result)
> (action (bash "cat promoted promoted > result")))
> EOF
$ echo hi > original
$ dune build result
$ cat promoted
hi
$ cat _build/default/result
hi
hi
Now change the [original] and rebuild.
$ echo bye > original
$ dune build result
$ cat promoted
bye
$ cat _build/default/result
bye
bye
Now switch the mode to standard. Dune reports an error about multiple rules for
[_build/default/promoted], as expected.
$ cat > dune <<EOF
> (rule
> (mode standard)
> (deps original)
> (target promoted)
> (action (copy %{deps} %{target})))
> (rule
> (deps promoted)
> (target result)
> (action (bash "cat promoted promoted > result")))
> EOF
$ dune build result
Error: Multiple rules generated for _build/default/promoted:
- dune:1
- file present in source tree
Hint: rm -f promoted
[1]
We use the hint and it starts to work.
$ rm -f promoted
$ dune build result
$ cat promoted
cat: promoted: No such file or directory
[1]
$ cat _build/default/promoted
bye
$ cat _build/default/result
bye
bye
Now use [fallback] to override the rule that generates [promoted].
$ cat > dune <<EOF
> (rule
> (mode fallback)
> (deps original)
> (target promoted)
> (action (copy %{deps} %{target})))
> (rule
> (deps promoted)
> (target result)
> (action (bash "cat promoted promoted > result")))
> EOF
At first, we don't have the source, so the rule is used.
$ dune build result
$ cat promoted
cat: promoted: No such file or directory
[1]
$ cat _build/default/promoted
bye
$ cat _build/default/result
bye
bye
Now we create the source file and it overrides the rule.
$ echo hi > promoted
$ dune build result
$ cat promoted
hi
$ cat _build/default/promoted
hi
$ cat _build/default/result
hi
hi

View file

@ -0,0 +1,5 @@
(rule (with-stdout-to x.gen (echo "")))
(rule
(alias blah-non-existent)
(action (diff x-non-existent x.gen)))

View file

@ -0,0 +1,15 @@
Tests for promoting with non existent reference
-----------------------------------------------
# Diffing should do as if it is an empty file
$ cat x-non-existent
cat: x-non-existent: No such file or directory
[1]
$ dune build @blah-non-existent
$ dune promote
$ cat x-non-existent
cat: x-non-existent: No such file or directory
[1]

View file

@ -0,0 +1,15 @@
Test of a rule that tries to promote to a source directory that doesn't exist.
Taken from #3502
$ cat >dune-project <<EOF
> (lang dune 3.4)
> EOF
$ cat >dune <<EOF
> (subdir x
> (rule
> (mode (promote (until-clean)))
> (action (with-stdout-to y (echo "z")))))
> EOF
$ dune build x/y
$ cat x/y
z

View file

@ -0,0 +1,5 @@
(rule (with-stdout-to x.gen (echo "toto")))
(rule
(alias blah-non-existent)
(action (diff x-non-existent x.gen)))

View file

@ -0,0 +1,18 @@
Tests for promoting with non existent reference
-----------------------------------------------
# Diffing should do as if it is an empty file
$ cat x-non-existent
cat: x-non-existent: No such file or directory
[1]
$ dune build @blah-non-existent
File "x-non-existent", line 1, characters 0-0:
Error: Files _build/default/x-non-existent and _build/default/x.gen differ.
[1]
$ dune promote
Promoting _build/default/x.gen to x-non-existent.
$ cat x-non-existent
toto

View file

@ -0,0 +1,38 @@
(rule (with-stdout-to x.gen (echo "toto")))
(alias
(name blah)
(action (diff x x.gen)))
(rule (with-stdout-to x.gen.copy (cat x.gen)))
(rule (with-stdout-to y.gen (echo "titi")))
(alias
(name blah2)
(action (diff y y.gen)))
(rule
(targets promoted)
(action (with-stdout-to promoted (echo "Hello, world!")))
(mode (promote-into subdir)))
(rule
(targets only1 only2)
(action
(progn
(with-stdout-to only1 (echo "0"))
(with-stdout-to only2 (echo "0"))))
(mode (promote (only *1))))
;; More complex test
(rule
(target into+ignoring)
(mode (promote (into subdir)))
(action (with-stdout-to %{target} (echo "hello"))))
(rule
(target into+ignoring)
(enabled_if %{ignoring_promoted_rules})
(action (copy subdir/into+ignoring into+ignoring)))

View file

@ -0,0 +1,173 @@
General tests
--------------------------
$ printf titi > x
$ dune build @blah
File "x", line 1, characters 0-0:
Error: Files _build/default/x and _build/default/x.gen differ.
[1]
$ cat x
titi
$ dune promote
Promoting _build/default/x.gen to x.
$ cat x
toto
$ dune build @blah
$ cat x
toto
The correction file stays on the filesystem even after promotion and
can be depended on by other actions.
We disable this test for OSX because it's flaky
$ if [ "$(uname)" = "Darwin" ]
> then
> echo toto
> else
> cat _build/default/x.gen
> fi
toto
$ printf titi > x
$ dune build @blah x.gen.copy
File "x", line 1, characters 0-0:
Error: Files _build/default/x and _build/default/x.gen differ.
[1]
$ cat _build/default/x.gen.copy
toto
Otherwise this test fails on OSX
$ dune clean
$ printf titi > x
$ dune build @blah --auto-promote
File "x", line 1, characters 0-0:
Error: Files _build/default/x and _build/default/x.gen differ.
Promoting _build/default/x.gen to x.
[1]
$ cat x
toto
$ dune build @blah
$ cat x
toto
Test single file promotion
--------------------------
$ printf a > x
$ printf a > y
$ dune build @blah @blah2
File "x", line 1, characters 0-0:
Error: Files _build/default/x and _build/default/x.gen differ.
File "y", line 1, characters 0-0:
Error: Files _build/default/y and _build/default/y.gen differ.
[1]
$ dune promote x
Promoting _build/default/x.gen to x.
$ cat x
toto
$ cat y
a
$ dune promote y
Promoting _build/default/y.gen to y.
$ cat x
toto
$ cat y
titi
$ dune promote x y
Warning: Nothing to promote for x.
Warning: Nothing to promote for y.
Reproduction case for #1772
---------------------------
$ printf a > x
$ printf a > y
$ dune build @blah @blah2
File "x", line 1, characters 0-0:
Error: Files _build/default/x and _build/default/x.gen differ.
File "y", line 1, characters 0-0:
Error: Files _build/default/y and _build/default/y.gen differ.
[1]
$ rm -f _build/default/x.gen
$ dune promote
Skipping promotion of _build/default/x.gen to x as the file is missing.
Promoting _build/default/y.gen to y.
Tests for promote-into
----------------------
$ mkdir -p subdir
$ dune build promoted
$ cat subdir/promoted
Hello, world!
Test for (promote (only ...))
-----------------------------
Only "only1" should be promoted in the source tree:
$ dune build only2
$ ls -1 only*
only1
Dune restores only1 if it's deleted from the source tree
$ rm only1
$ dune build only2
$ ls -1 only*
only1
Dune restores only1 if it's modified in the source tree
$ cat only1
0
$ echo 1 > only1
$ dune build only2
$ cat only1
0
Test for (promote (into ...)) + (enabled_if %{ignoring_promoted_rules}
----------------------------------------------------------------------
$ dune build into+ignoring
$ ls -1 subdir/into*
subdir/into+ignoring
$ dune clean
$ dune build into+ignoring --ignore-promoted-rules
$ ls -1 _build/default/into*
_build/default/into+ignoring
Reproduction case for #3069
---------------------------
$ mkdir 3069 && cd 3069
$ echo "(lang dune 2.0)" > dune-project
$ cat >dune <<EOF
> (rule
> (action (with-stdout-to x (echo bar)))
> (mode (promote (into dir))))
> EOF
$ dune build ./x
File "dune", line 3, characters 22-25:
3 | (mode (promote (into dir))))
^^^
Error: Directory "dir" does not exist. Please create it manually.
-> required by _build/default/x
[1]
Now test the case where dir exists but is a file
$ touch dir
$ dune build ./x
File "dune", line 3, characters 22-25:
3 | (mode (promote (into dir))))
^^^
Error: "dir" is not a directory.
-> required by _build/default/x
[1]

View file

@ -0,0 +1,43 @@
Demonstrate issue https://github.com/ocaml/dune/issues/7383 with changing a file for
promotion from a file to a directory whilst in the staging area. This causes Dune to get
confused and stuck.
Create a cram test:
$ cat > dune-project << EOF
> (lang dune 3.8)
> EOF
$ cat > my_cram.t << EOF
> $ echo hello
> EOF
Run the cram test, should fail and file should be staged for promotion
$ dune build @runtest
File "my_cram.t", line 1, characters 0-0:
Error: Files _build/default/my_cram.t and _build/default/my_cram.t.corrected
differ.
[1]
Change cram test to a directory cram test
$ rm my_cram.t
$ mkdir my_cram.t
$ cat > my_cram.t/run.t << EOF
> $ echo hello
> EOF
Run the cram test, should fail and file should be promoted
$ dune build @runtest 2>&1 | sed -E 's#/.*.sandbox/[^/]+#/.sandbox/$SANDBOX#g'
File "my_cram.t/run.t", line 1, characters 0-0:
Error: Files _build/default/my_cram.t/run.t and
_build/default/my_cram.t/run.t.corrected differ.
Error: rename(_build/default/my_cram.t/run.t.corrected): Not a directory
-> required by alias my_cram
-> required by alias runtest
We cannot promote:
$ dune promote

View file

@ -0,0 +1,84 @@
Test that [promote-foo] syntax is deleted in Dune 3.0 with good error messages.
First, check that the syntax still works with Dune 2.9.
$ echo "(lang dune 2.9)" > dune-project
$ cat >dune <<EOF
> (rule
> (targets promoted)
> (action (with-stdout-to promoted (echo "Hello, world!")))
> (mode (promote-into subdir)))
> (rule
> (targets promoted-until-clean)
> (action (with-stdout-to promoted-until-clean (echo "Hello again!")))
> (mode promote-until-clean))
> EOF
$ mkdir subdir
$ dune build promoted promoted-until-clean
$ cat subdir/promoted
Hello, world!
$ cat promoted-until-clean
Hello again!
$ dune clean
$ cat subdir/promoted
Hello, world!
$ cat promoted-until-clean
cat: promoted-until-clean: No such file or directory
[1]
Now switch to Dune 3.0.
$ echo "(lang dune 3.0)" > dune-project
$ dune build promoted
File "dune", line 4, characters 7-28:
4 | (mode (promote-into subdir)))
^^^^^^^^^^^^^^^^^^^^^
Error: 'promote-into' was deleted in version 3.0 of the dune language. Use
the (promote (into <dir>)) syntax instead.
[1]
$ cat >dune <<EOF
> (rule
> (targets promoted)
> (action (with-stdout-to promoted (echo "Hello again!")))
> (mode (promote-until-clean-into subdir)))
> EOF
$ dune build promoted
File "dune", line 4, characters 7-40:
4 | (mode (promote-until-clean-into subdir)))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error: 'promote-until-clean-into' was deleted in version 3.0 of the dune
language. Use the (promote (until-clean) (into <dir>)) syntax instead.
[1]
$ cat >dune <<EOF
> (rule
> (targets promoted)
> (action (with-stdout-to promoted (echo "Hello again!")))
> (mode promote-until-clean))
> EOF
$ dune build promoted
File "dune", line 4, characters 7-26:
4 | (mode promote-until-clean))
^^^^^^^^^^^^^^^^^^^
Error: 'promote-until-clean' was deleted in version 3.0 of the dune language.
Use the (promote (until-clean)) syntax instead.
[1]
Test that the hint works.
$ cat >dune <<EOF
> (rule
> (targets promoted)
> (action (with-stdout-to promoted (echo "Hello again!")))
> (mode (promote (until-clean))))
> EOF
$ dune build promoted
$ cat promoted
Hello again!
$ dune clean
$ cat promoted
cat: promoted: No such file or directory
[1]

View file

@ -0,0 +1,60 @@
Test that targets aren't re-promoted if they are up to date.
$ echo "(lang dune 3.0)" > dune-project
$ cat >dune <<EOF
> (rule
> (targets promoted)
> (mode promote)
> (action (with-stdout-to promoted (echo "Hello, world!"))))
> EOF
$ dune build promoted --verbose 2>&1 | grep "Promoting"
Promoting "_build/default/promoted" to "promoted"
$ cat promoted
Hello, world!
Dune doesn't promote the file again if it's unchanged.
$ dune build promoted --verbose 2>&1 | grep "Promoting"
[1]
$ cat promoted
Hello, world!
Dune does promotes the file again if it's changed.
$ echo hi > promoted
$ dune build promoted --verbose 2>&1 | grep "Promoting"
Promoting "_build/default/promoted" to "promoted"
$ cat promoted
Hello, world!
Now test behaviour for executables, which use artifact substitution.
$ git init --quiet
$ cat >dune <<EOF
> (executable
> (name hello)
> (libraries dune-build-info)
> (promote))
> EOF
$ cat >hello.ml <<EOF
> print_endline "Hello, World!";
> (match Build_info.V1.version () with
> | Some _ -> print_endline "Has version info"
> | None -> print_endline "Has no version info")
> EOF
$ dune build hello.exe --verbose 2>&1 | grep "Promoting"
Promoting "_build/default/hello.exe" to "hello.exe"
$ ./hello.exe
Hello, World!
Has version info
Bug: Dune currently re-promotes versioned executables on every restart.
# CR-someday amokhov: Fix this.
$ dune build hello.exe --verbose 2>&1 | grep "Promoting"
Promoting "_build/default/hello.exe" to "hello.exe"

View file

@ -0,0 +1,30 @@
`dune promotion run` is equivalent to `dune promote`.
$ cat > dune-project << EOF
> (lang dune 2.0)
> EOF
$ cat > dune << EOF
> (rule
> (alias runtest)
> (action
> (diff a.expected a.actual)))
>
> (rule
> (write-file a.actual Actual))
> EOF
$ cat > a.expected << EOF
> Expected
> EOF
$ dune runtest
File "a.expected", line 1, characters 0-0:
Error: Files _build/default/a.expected and _build/default/a.actual differ.
[1]
$ cat a.expected
Expected
$ dune promotion apply
Promoting _build/default/a.actual to a.expected.
$ cat a.expected
Actual

View file

@ -0,0 +1,64 @@
$ cat > dune-project << EOF
> (lang dune 2.0)
> EOF
$ cat > dune << EOF
> (rule
> (alias runtest)
> (action
> (diff a.expected a.actual)))
>
> (rule
> (with-stdout-to a.actual
> (echo "A actual\n")))
>
> (rule
> (alias runtest)
> (action
> (progn
> (with-stdout-to b.actual
> (echo "B actual\n"))
> (diff? b.expected b.actual))))
> EOF
$ echo 'A expected' > a.expected
$ echo 'B expected' > b.expected
$ touch nothing-to-promote.txt
$ dune runtest
File "a.expected", line 1, characters 0-0:
Error: Files _build/default/a.expected and _build/default/a.actual differ.
File "b.expected", line 1, characters 0-0:
Error: Files _build/default/b.expected and _build/default/b.actual differ.
[1]
$ dune promotion diff --diff-command 'diff -u' 2>&1 | sed -e 's/\t.*$//'
File "a.expected", line 1, characters 0-0:
--- a.expected
+++ _build/default/a.actual
@@ -1 +1 @@
-A expected
+A actual
File "b.expected", line 1, characters 0-0:
--- b.expected
+++ _build/.promotion-staging/b.expected
@@ -1 +1 @@
-B expected
+B actual
$ dune promotion diff b.expected --diff-command 'diff -u' 2>&1 | sed -e 's/\t.*$//'
File "b.expected", line 1, characters 0-0:
--- b.expected
+++ _build/.promotion-staging/b.expected
@@ -1 +1 @@
-B expected
+B actual
$ dune promotion diff a.expected nothing-to-promote.txt --diff-command 'diff -u' 2>&1 | sed -e 's/\t.*$//'
Warning: Nothing to promote for nothing-to-promote.txt.
File "a.expected", line 1, characters 0-0:
--- a.expected
+++ _build/default/a.actual
@@ -1 +1 @@
-A expected
+A actual

View file

@ -0,0 +1,44 @@
$ cat > dune-project << EOF
> (lang dune 2.0)
> EOF
$ cat > dune << EOF
> (rule
> (alias runtest)
> (action
> (diff a.expected a.actual)))
>
> (rule
> (with-stdout-to a.actual
> (echo "A actual\n")))
>
> (rule
> (alias runtest)
> (action
> (progn
> (with-stdout-to b.actual
> (echo "B actual\n"))
> (diff? b.expected b.actual))))
> EOF
$ echo 'A expected' > a.expected
$ echo 'B expected' > b.expected
$ touch nothing-to-promote.txt
$ dune runtest
File "a.expected", line 1, characters 0-0:
Error: Files _build/default/a.expected and _build/default/a.actual differ.
File "b.expected", line 1, characters 0-0:
Error: Files _build/default/b.expected and _build/default/b.actual differ.
[1]
$ dune promotion list --diff-command 'diff -u' 2>&1
a.expected
b.expected
$ dune promotion list b.expected --diff-command 'diff -u' 2>&1
b.expected
$ dune promotion list a.expected nothing-to-promote.txt --diff-command 'diff -u' 2>&1
Warning: Nothing to promote for nothing-to-promote.txt.
a.expected