Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Always display the line number in file excerpts #1203

Merged
merged 1 commit into from
Sep 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions src/errors.ml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ let file_lines path ~start ~stop =
aux [] 1
)

let pp_line padding_width pp (lnum, l) =
Format.fprintf pp "%*s | %s\n" padding_width lnum l

let print ppf loc =
let { Loc.start; stop } = loc in
let start_c = start.pos_cnum - start.pos_bol in
Expand All @@ -73,11 +76,15 @@ let print ppf loc =
if not whole_file then
let path = Path.of_string start.pos_fname in
if Path.exists path then
let line = file_line path start.pos_lnum in
let line_num = start.pos_lnum in
let line_num_str = string_of_int line_num in
let padding_width = String.length line_num_str in
let line = file_line path line_num in
if stop_c <= String.length line then
let len = stop_c - start_c in
Format.fprintf pp "%s\n%*s\n" line
stop_c
Format.fprintf pp "%a%*s\n"
(pp_line padding_width) (line_num_str, line)
(stop_c + padding_width + 3)
(String.make len '^')
else
let get_padding lines =
Expand All @@ -93,7 +100,7 @@ let print ppf loc =
in
let print_lines lines padding_width =
List.iter ~f:(fun (lnum, l) ->
Format.fprintf pp "%*s | %s\n" padding_width lnum l) lines;
pp_line padding_width pp (lnum, l)) lines;
in
if num_lines <= max_lines_to_print_in_full then
let lines = file_lines path ~start:start.pos_lnum ~stop:stop.pos_lnum in
Expand Down
8 changes: 4 additions & 4 deletions test/blackbox-tests/test-cases/bad-alias-error/run.t
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
$ dune runtest --root absolute-path
Entering directory 'absolute-path'
File "jbuild", line 3, characters 16-24:
(deps ((alias /foo/bar)))))
^^^^^^^^
3 | (deps ((alias /foo/bar)))))
^^^^^^^^
Error: Invalid alias!
Tried to reference path outside build dir: "/foo/bar"
[1]
$ dune runtest --root outside-workspace
Entering directory 'outside-workspace'
File "jbuild", line 4, characters 16-39:
(deps ((alias ${ROOT}/../../../foobar)))))
^^^^^^^^^^^^^^^^^^^^^^^
4 | (deps ((alias ${ROOT}/../../../foobar)))))
^^^^^^^^^^^^^^^^^^^^^^^
Error: path outside the workspace: ./../../../foobar from default
[1]
4 changes: 2 additions & 2 deletions test/blackbox-tests/test-cases/dune-jbuild-var-case/run.t
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ All builtin variables are lower cased in Dune:
$ dune runtest --root dune-upper
Entering directory 'dune-upper'
File "dune", line 3, characters 41-46:
(action (with-stdout-to %{null} (echo %{MAKE}))))
^^^^^
3 | (action (with-stdout-to %{null} (echo %{MAKE}))))
^^^^^
Error: %{MAKE} was renamed to '%{make}' in the 1.0 version of the dune language
[1]

Expand Down
12 changes: 6 additions & 6 deletions test/blackbox-tests/test-cases/dune-ppx-driver-system/run.t
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@ No ppx driver found

$ dune build foo1.cma
File "dune", line 6, characters 13-18:
(preprocess (pps)))
^^^^^
6 | (preprocess (pps)))
^^^^^
Error: You must specify at least one ppx rewriter.
[1]

Too many drivers

$ dune build foo2.cma
File "dune", line 13, characters 13-28:
(preprocess (pps ppx1 ppx2)))
^^^^^^^^^^^^^^^
13 | (preprocess (pps ppx1 ppx2)))
^^^^^^^^^^^^^^^
Error: Too many incompatible ppx drivers were found: foo.driver2 and
foo.driver1.
[1]
Expand All @@ -21,8 +21,8 @@ Not compatible with Dune

$ dune build foo3.cma
File "dune", line 20, characters 13-28:
(preprocess (pps ppx_other)))
^^^^^^^^^^^^^^^
20 | (preprocess (pps ppx_other)))
^^^^^^^^^^^^^^^
Error: No ppx driver were found. It seems that ppx_other is not compatible
with Dune. Examples of ppx rewriters that are compatible with Dune are ones
using ocaml-migrate-parsetree, ppxlib or ppx_driver.
Expand Down
8 changes: 4 additions & 4 deletions test/blackbox-tests/test-cases/dup-fields/run.t
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ Duplicating a field in a dune file is an error:

$ dune build --root dune
File "dune", line 4, characters 1-20:
(action (echo bar)))
^^^^^^^^^^^^^^^^^^^
4 | (action (echo bar)))
^^^^^^^^^^^^^^^^^^^
Error: Field "action" is present too many times
[1]

Expand All @@ -17,8 +17,8 @@ For backward compatibility, it is only a warning in jbuild files:

$ dune build --root jbuild
File "jbuild", line 4, characters 2-21:
(action (echo bar))))
^^^^^^^^^^^^^^^^^^^
4 | (action (echo bar))))
^^^^^^^^^^^^^^^^^^^
Warning: Field "action" is present several times, previous occurrences are ignored.
Entering directory 'jbuild'
bar
4 changes: 2 additions & 2 deletions test/blackbox-tests/test-cases/exclude-missing-module/run.t
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
$ dune build --display short
File "dune", line 3, characters 22-26:
(modules :standard \ fake))
^^^^
3 | (modules :standard \ fake))
^^^^
Warning: Module Fake is excluded but it doesn't exist.
4 changes: 2 additions & 2 deletions test/blackbox-tests/test-cases/exec-missing/run.t
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ When using dune exec, the external-lib-deps command refers to the executable:

$ dune exec ./x.exe
File "dune", line 3, characters 12-26:
(libraries does-not-exist))
^^^^^^^^^^^^^^
3 | (libraries does-not-exist))
^^^^^^^^^^^^^^
Error: Library "does-not-exist" not found.
Hint: try: dune external-lib-deps --missing ./x.exe
[1]
8 changes: 4 additions & 4 deletions test/blackbox-tests/test-cases/fallback-dune/run.t
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@ fallback isn't allowed in dune

$ dune build --root dune1
File "dune", line 2, characters 1-11:
(fallback)
^^^^^^^^^^
2 | (fallback)
^^^^^^^^^^
Error: 'fallback' was renamed to '(mode fallback)' in the 1.0 version of the dune language
[1]

2nd fallback form isn't allowed either

$ dune build --root dune2
File "dune", line 2, characters 1-17:
(fallback false)
^^^^^^^^^^^^^^^^
2 | (fallback false)
^^^^^^^^^^^^^^^^
Error: 'fallback' was renamed to '(mode fallback)' in the 1.0 version of the dune language
[1]

Expand Down
8 changes: 4 additions & 4 deletions test/blackbox-tests/test-cases/findlib-error/run.t
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ We are dropping support for findlib in dune
$ dune build --root in-dune target.txt
Entering directory 'in-dune'
File "dune", line 2, characters 25-37:
(write-file target.txt %{findlib:pkg})
^^^^^^^^^^^^
2 | (write-file target.txt %{findlib:pkg})
^^^^^^^^^^^^
Error: %{findlib:..} was renamed to '%{lib:..}' in the 1.0 version of the dune language
[1]

Expand All @@ -13,7 +13,7 @@ But it must still be available in jbuild files
$ dune build --root in-jbuild target.txt
Entering directory 'in-jbuild'
File "jbuild", line 4, characters 23-42:
(write-file target.txt ${findlib:pkg:file})
^^^^^^^^^^^^^^^^^^^
4 | (write-file target.txt ${findlib:pkg:file})
^^^^^^^^^^^^^^^^^^^
Error: Public library "pkg" not found
[1]
12 changes: 6 additions & 6 deletions test/blackbox-tests/test-cases/findlib/run.t
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ Reproduction case for #484. The error should point to src/jbuild

$ dune build @install
File "src/dune", line 4, characters 14-15:
(libraries a b c))
^
4 | (libraries a b c))
^
Error: Library "a" not found.
Hint: try: dune external-lib-deps --missing @install
[1]
Expand All @@ -18,8 +18,8 @@ When passing --dev, the profile should be displayed only once (#1106):

$ jbuilder build --dev @install
File "src/dune", line 4, characters 14-15:
(libraries a b c))
^
4 | (libraries a b c))
^
Error: Library "a" not found.
Hint: try: dune external-lib-deps --missing --profile dev @install
[1]
Expand All @@ -28,8 +28,8 @@ With dune and an explicit profile, it is the same:

$ dune build --profile dev @install
File "src/dune", line 4, characters 14-15:
(libraries a b c))
^
4 | (libraries a b c))
^
Error: Library "a" not found.
Hint: try: dune external-lib-deps --missing --profile dev @install
[1]
8 changes: 4 additions & 4 deletions test/blackbox-tests/test-cases/github1099/run.t
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ If the source directory does not exist, an error message is printed:
$ dune build --root no-dir demo.exe
Entering directory 'no-dir'
File "dune", line 1, characters 13-23:
(copy_files# "no_dir/*")
^^^^^^^^^^
1 | (copy_files# "no_dir/*")
^^^^^^^^^^
Error: cannot find directory: no_dir
[1]

Expand All @@ -13,7 +13,7 @@ This works also is a file exists with the same name:
$ dune build --root file-with-same-name demo.exe
Entering directory 'file-with-same-name'
File "dune", line 1, characters 13-23:
(copy_files# "no_dir/*")
^^^^^^^^^^
1 | (copy_files# "no_dir/*")
^^^^^^^^^^
Error: cannot find directory: no_dir
[1]
4 changes: 2 additions & 2 deletions test/blackbox-tests/test-cases/github644/run.t
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
$ dune runtest
File "jbuild", line 4, characters 20-42:
(preprocess (pps (ppx_that_doesn't_exist)))))
^^^^^^^^^^^^^^^^^^^^^^
4 | (preprocess (pps (ppx_that_doesn't_exist)))))
^^^^^^^^^^^^^^^^^^^^^^
Error: Library "ppx_that_doesn't_exist" not found.
Hint: try: dune external-lib-deps --missing @runtest
[1]
Expand Down
4 changes: 2 additions & 2 deletions test/blackbox-tests/test-cases/github734/run.t
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
$ jbuilder build @foo
File "src/dune", line 4, characters 10-17:
(c_names stubs/x))
^^^^^^^
4 | (c_names stubs/x))
^^^^^^^
Error: File src/stubs/x.c is not part of the current directory group. This is not allowed.
[1]
4 changes: 2 additions & 2 deletions test/blackbox-tests/test-cases/github761/run.t
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
$ jbuilder build @bar
File "dune", line 2, characters 7-14:
(name foo/bar)
^^^^^^^
2 | (name foo/bar)
^^^^^^^
Error: "foo/bar" is not a valid alias name
[1]
4 changes: 2 additions & 2 deletions test/blackbox-tests/test-cases/github784/run.t
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
$ dune build
File "dune", line 1, characters 0-28:
(rule (run %{bin:echo} foo))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1 | (rule (run %{bin:echo} foo))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error: Rule has no targets specified
[1]
8 changes: 4 additions & 4 deletions test/blackbox-tests/test-cases/github992/run.t
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ argument of "package".

$ cd package-without-pub-name && dune build -p foo
File "dune", line 3, characters 1-14:
(package foo))
^^^^^^^^^^^^^
3 | (package foo))
^^^^^^^^^^^^^
Error: This field is useless without a (public_name ...) field.
[1]

$ cd package-without-pub-name-jbuild && dune build -p foo
File "jbuild", line 3, characters 2-15:
(package foo)))
^^^^^^^^^^^^^
3 | (package foo)))
^^^^^^^^^^^^^
Warning: This field is useless without a (public_name ...) field.
4 changes: 2 additions & 2 deletions test/blackbox-tests/test-cases/include-loop/run.t
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
$ dune build --display short
File "dune", line 1, characters 0-15:
(include a.inc)
^^^^^^^^^^^^^^^
1 | (include a.inc)
^^^^^^^^^^^^^^^
Error: Recursive inclusion of jbuild files detected:
File a.inc is included from c.inc:1
--> included from b.inc:1
Expand Down
8 changes: 4 additions & 4 deletions test/blackbox-tests/test-cases/inline_tests/run.t
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@

$ dune runtest missing-backend
File "missing-backend/dune", line 3, characters 1-15:
(inline_tests))
^^^^^^^^^^^^^^
3 | (inline_tests))
^^^^^^^^^^^^^^
Error: No inline tests backend found.
[1]

$ dune runtest too-many-backends
File "too-many-backends/dune", line 17, characters 1-15:
(inline_tests)
^^^^^^^^^^^^^^
17 | (inline_tests)
^^^^^^^^^^^^^^
Error: Too many independent inline tests backends found:
- "backend_tmb1" in _build/default/too-many-backends
- "backend_tmb2" in _build/default/too-many-backends
Expand Down
12 changes: 6 additions & 6 deletions test/blackbox-tests/test-cases/intf-only/run.t
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ Errors:
$ dune build --display short --root b foo.cma
Entering directory 'b'
File "dune", line 3, characters 33-34:
(modules_without_implementation x))
^
3 | (modules_without_implementation x))
^
Warning: The following modules must be listed here as they don't have an implementation:
- y
This will become an error in the future.
Expand All @@ -47,14 +47,14 @@ Errors:
$ dune build --display short --root c foo.cma
Entering directory 'c'
File "dune", line 3, characters 33-34:
(modules_without_implementation x))
^
3 | (modules_without_implementation x))
^
Error: Module X doesn't exist.
[1]
$ dune build --display short --root d foo.cma
Entering directory 'd'
File "dune", line 3, characters 33-34:
(modules_without_implementation x))
^
3 | (modules_without_implementation x))
^
Error: Module X has an implementation, it cannot be listed here
[1]
4 changes: 2 additions & 2 deletions test/blackbox-tests/test-cases/macro-expand-error/run.t
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ inappropariate place:

$ dune build
File "dune", line 1, characters 14-21:
(copy_files %{read:x}/*)
^^^^^^^
1 | (copy_files %{read:x}/*)
^^^^^^^
Error: %{read:..} isn't allowed in this position
[1]
4 changes: 2 additions & 2 deletions test/blackbox-tests/test-cases/misc/run.t
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
$ dune runtest --display short
File "dune", line 44, characters 19-42:
(deps (glob_files dir-that-doesnt-exist/*)))
^^^^^^^^^^^^^^^^^^^^^^^
44 | (deps (glob_files dir-that-doesnt-exist/*)))
^^^^^^^^^^^^^^^^^^^^^^^
Warning: Directory dir-that-doesnt-exist doesn't exist.
diff alias runtest
diff alias runtest
Expand Down
4 changes: 2 additions & 2 deletions test/blackbox-tests/test-cases/missing-loc-run/run.t
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ Path that needs to be searched:
$ dune runtest --root search-path
Entering directory 'search-path'
File "dune", line 3, characters 14-32:
(action (run foo-does-not-exist)))
^^^^^^^^^^^^^^^^^^
3 | (action (run foo-does-not-exist)))
^^^^^^^^^^^^^^^^^^
Error: Error: Program foo-does-not-exist not found in the tree or in PATH (context: default)
[1]

Expand Down
Loading