Skip to content

Commit

Permalink
feature: show number of errors when waiting in watch mode (#8408)
Browse files Browse the repository at this point in the history
This displays:

Had 4 errors, waiting for filesystem changes...

When the watch mode build has been finished with 4 errors. For a single
error it say "Had 1 error".

Signed-off-by: Ali Caglayan <[email protected]>
  • Loading branch information
Alizter authored Aug 21, 2023
1 parent 9ebdb0e commit 0a3b251
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 10 deletions.
11 changes: 10 additions & 1 deletion bin/import.ml
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,16 @@ module Scheduler = struct
let message =
match build_result with
| Success -> Pp.tag User_message.Style.Success (Pp.verbatim "Success")
| Failure -> Pp.tag User_message.Style.Error (Pp.verbatim "Had errors")
| Failure ->
let failure_message =
match
Build_system.Error.(
Id.Map.cardinal (Set.current (Fiber.Svar.read Build_system.errors)))
with
| 1 -> Pp.textf "Had 1 error"
| n -> Pp.textf "Had %d errors" n
in
Pp.tag User_message.Style.Error failure_message
in
Console.Status_line.set
(Constant (Pp.seq message (Pp.verbatim ", waiting for filesystem changes...")))
Expand Down
2 changes: 2 additions & 0 deletions doc/changes/8408.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Dune now displays the number of errors when waiting for changes in watch mode. (#8408,
@Alizter)
4 changes: 2 additions & 2 deletions test/blackbox-tests/test-cases/watching/basic.t
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,12 @@ Basic tests for the file-watching mode.
3 | (deps x)
4 | (action (system "cat x > y")))
Error: No rule found for x
Had errors, waiting for filesystem changes...
Had 1 error, waiting for filesystem changes...
File "dune", line 1, characters 0-59:
1 | (rule
2 | (target y)
3 | (deps x)
4 | (action (system "cat x > y")))
Error: No rule found for x
Had errors, waiting for filesystem changes...
Had 1 error, waiting for filesystem changes...
Success, waiting for filesystem changes...
12 changes: 6 additions & 6 deletions test/blackbox-tests/test-cases/watching/fs-memo.t
Original file line number Diff line number Diff line change
Expand Up @@ -240,9 +240,9 @@ If we repeat the test, we finally see the failure.
How about now?
Failure
Error: inotify_add_watch(subdir): Permission denied
Had errors, waiting for filesystem changes...
Had 1 error, waiting for filesystem changes...
Error: inotify_add_watch(subdir): Permission denied
Had errors, waiting for filesystem changes...
Had 1 error, waiting for filesystem changes...
------------------------------------------
result = '13' -> '13' -> '13'
------------------------------------------
Expand All @@ -254,9 +254,9 @@ Same problem in the other direction.
Failure
Failure
Error: inotify_add_watch(subdir): Permission denied
Had errors, waiting for filesystem changes...
Had 1 error, waiting for filesystem changes...
Error: inotify_add_watch(subdir): Permission denied
Had errors, waiting for filesystem changes...
Had 1 error, waiting for filesystem changes...
------------------------------------------
result = '13' -> '13' -> '13'
------------------------------------------
Expand Down Expand Up @@ -288,12 +288,12 @@ Same problem for files.
-> required by _build/default/file-1
-> required by _build/default/result
-> required by alias default
Had errors, waiting for filesystem changes...
Had 1 error, waiting for filesystem changes...
Error: file-1: Permission denied
-> required by _build/default/file-1
-> required by _build/default/result
-> required by alias default
Had errors, waiting for filesystem changes...
Had 1 error, waiting for filesystem changes...
------------------------------------------
result = '13' -> '13' -> '13'
------------------------------------------
Expand Down
38 changes: 38 additions & 0 deletions test/blackbox-tests/test-cases/watching/multiple-errors.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
We test the behavior of watch mode when we have multiple errors

$ . ./helpers.sh

$ echo "(lang dune 3.11)" > dune-project

$ start_dune

$ cat > x <<EOF
> not so
> EOF

$ cat >dune <<EOF
> (rule
> (action
> (progn
> (write-file y "different")
> (diff x y))))
> (rule
> (action
> (progn
> (write-file z "different")
> (diff x z))))
> (rule
> (deps y z)
> (action
> (write-file w "")))
> EOF

$ build w
Failure

$ stop_dune
File "x", line 1, characters 0-0:
Error: Files _build/default/x and _build/default/y differ.
File "x", line 1, characters 0-0:
Error: Files _build/default/x and _build/default/z differ.
Had 2 errors, waiting for filesystem changes...
2 changes: 1 addition & 1 deletion test/blackbox-tests/test-cases/watching/target-promotion.t
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ We're done.
- file present in source tree
- dune:1
Hint: rm -f promoted
Had errors, waiting for filesystem changes...
Had 1 error, waiting for filesystem changes...
Success, waiting for filesystem changes...
Success, waiting for filesystem changes...
Success, waiting for filesystem changes...
Expand Down

0 comments on commit 0a3b251

Please sign in to comment.