dune icon indicating copy to clipboard operation
dune copied to clipboard

Fail to promote over a non-existing file

Open Julow opened this issue 2 years ago • 4 comments

Expected Behavior

The testsuite demonstrate that this is possible in test/blackbox-tests/test-cases/promote/non-existent.t/run.t My reproduction looks very similar to this test but fail with an error.

Actual Behavior

dune build @bench:

File "dune", line 3, characters 0-55:
3 | (rule
4 |  (alias bench)
5 |  (action
6 |   (diff promoted x.gen)))
Error: Unable to resolve symlink _build/default/promoted

Reproduction

The reproduction is at https://gist.github.com/Julow/961080a45a58b964fd1bca7892445034

Specifications

  • Dune 3.8.2

Julow avatar Jun 28 '23 14:06 Julow

If I replace the dune files at test/blackbox-tests/test-cases/promote/non-existent.t/ with mines, it's able to promote. The problem persists with --sandbox none.

Julow avatar Jun 28 '23 14:06 Julow

Also running into this. It would be very convenient for dune to be able to promote over nonexistent files.

jfeser avatar Aug 29 '23 20:08 jfeser

The test uses (lang dune 2.8) which might be why it works there, but some newer dune lang might change the behavior.

sim642 avatar May 15 '24 17:05 sim642

I just checked that the test passes with both lang versions 3.7 (the version used in the repro) and 3.15.

Julow avatar May 16 '24 14:05 Julow

Hi,

I encounter the same problem with the last version of dune (3.20.2). Trying to use diff against a non existing file leads to the error Error: Unable to resolve symlink _build/default/XXX. Is there a workaround?

Thanks in advance,

Christophe

tofgarion avatar Oct 22 '25 20:10 tofgarion

I just create an empty file in the expected location eg touch XXX. Arguably, dune should just do this if it can't find the file.

yawaramin avatar Oct 23 '25 07:10 yawaramin

I've managed to reproduce this issue. The main reason we hadn't done this sooner is because INSIDE_DUNE, an internal env variable we set when testing dune needs to be unset for the behaviour to become apparent. In that case we default to git diff which most users see, however git diff does not like symbolic links so there is some work on resolving these in the code. This however doesn't make any sense when the file (target of the symlink) simply doesn't exist.

In my test however, it appears the promotion was still being registered even though dune was complaining about the symlink not being resolvable.

A fix can be found in #12615.

Alizter avatar Oct 23 '25 09:10 Alizter

Hi @Alizter and @yawaramin ,

Thanks for your answers. I am currently using dune and diff to check a tool output for thousands of test cases representing regression tests, and in the vast majority of the test cases the output should be empty, hence the use of a "non existing result file". I could of course create an empty file for each test case.

tofgarion avatar Oct 23 '25 09:10 tofgarion

@tofgarion are you able to check if my fix in #12615 fixes your issue?

Alizter avatar Oct 23 '25 10:10 Alizter

The current behavior is also in conflict with explicitly documented behavior in https://dune.readthedocs.io/en/stable/concepts/promotion.html#diffing, it seems:

If <file1> doesn’t exist, it will compare with the empty file.

nomeata avatar Nov 12 '25 10:11 nomeata

@nomeata Its partially correct since if you use a different --diff= program it will work. I will update the docs in the fix too #12615.

Alizter avatar Nov 12 '25 10:11 Alizter

Indeed! With

dune runtest --diff-command "diff -Nur"

it seems to work. Thanks!

nomeata avatar Nov 12 '25 11:11 nomeata

Actually after reviewing the doc, it doesn't need updating. But I am pushing the fix forward so that dune's behaviour actually matches the doc in all cases.

Alizter avatar Nov 12 '25 12:11 Alizter