Skip to content

Commit 20f0eb4

Browse files
authored
Merge pull request #28 from lefessan/z-2023-09-28-rebase-Considering
Always print tests output relative to import/gnucobol/
2 parents 7674480 + 2b9c53e commit 20f0eb4

File tree

6 files changed

+48
-9
lines changed

6 files changed

+48
-9
lines changed

src/lsp/cobol_ast/raw_data_sections_visitor.ml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ open Cobol_common.Visitor.INFIX (* for `>>` (== `|>`) *)
1818
open Terms_visitor
1919

2020
let todo x = Cobol_common.Visitor.todo __FILE__ x
21-
let partial x = Cobol_common.Visitor.partial __FILE__ x
21+
let partial modname line funcname =
22+
Cobol_common.Visitor.partial __FILE__ modname line funcname
2223

2324
(* --- *)
2425

@@ -85,7 +86,7 @@ struct
8586
end
8687

8788
let todo x = todo __MODULE__ x
88-
and partial x = partial __MODULE__ x
89+
and partial line funcname = partial __MODULE__ line funcname
8990

9091
let fold_data_level (v: _ #folder) =
9192
leaf v#fold_data_level

src/lsp/cobol_common/visitor.ml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ module INFIX = struct
5757
end
5858
open INFIX
5959

60+
let in_testsuite = ref false
61+
6062
let report = (* to be kept until visitors are complete *)
6163
let module REPORTED =
6264
Hashtbl.Make (struct
@@ -68,6 +70,9 @@ let report = (* to be kept until visitors are complete *)
6870
let reported_table = lazy (REPORTED.create 17) in
6971
fun k file_name module_name line_num func_name ->
7072
let tbl = Lazy.force reported_table in
73+
let file_name =
74+
if !in_testsuite then Filename.basename file_name else file_name in
75+
let line_num = if !in_testsuite then 0 else line_num in
7176
if not (REPORTED.mem tbl (file_name, module_name, line_num, func_name))
7277
then begin
7378
Pretty.error "@[<2>%s:%u:@ (%s.%s):@ %s@ visitor@ implementation@]@."

test/lsp/lsp_formatting.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -401,10 +401,10 @@ let%expect_test "formatting-request-whole-program" =
401401
end_with_postproc [%expect.output];
402402
[%expect {|
403403
{"params":{"diagnostics":[],"uri":"file://__rootdir__/superbol.toml"},"method":"textDocument/publishDiagnostics","jsonrpc":"2.0"}
404-
src/lsp/cobol_ast/raw_misc_sections_visitor.ml:66:
404+
raw_misc_sections_visitor.ml:0:
405405
(Cobol_ast__Raw_misc_sections_visitor.fold_select_clause): missing visitor
406406
implementation
407-
src/lsp/cobol_ast/raw_data_sections_visitor.ml:280:
407+
raw_data_sections_visitor.ml:0:
408408
(Cobol_ast__Raw_data_sections_visitor.fold_file_section): missing visitor
409409
implementation
410410
{"params":{"diagnostics":[{"message":"Source format `auto` is not supported yet, using `fixed`","range":{"end":{"character":0,"line":0},"start":{"character":0,"line":0}},"severity":2}],"uri":"file://__rootdir__/prog.cob"},"method":"textDocument/publishDiagnostics","jsonrpc":"2.0"}

test/lsp/lsp_references.ml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ open EzCompat (* StringMap *)
1515
open Lsp.Types
1616
open Lsp_testing
1717

18+
(* Used to remove full-path and lines in the test files *)
19+
let () =
20+
Cobol_common.Visitor.in_testsuite := true
1821

1922
let print_references ~projdir server (doc, positions) : unit =
2023
let server, prog = add_cobol_doc server ~projdir "prog.cob" doc in
@@ -57,7 +60,7 @@ let%expect_test "simple-references-requests" =
5760
end_with_postproc [%expect.output];
5861
[%expect {|
5962
{"params":{"diagnostics":[],"uri":"file://__rootdir__/superbol.toml"},"method":"textDocument/publishDiagnostics","jsonrpc":"2.0"}
60-
src/lsp/cobol_ast/raw_data_sections_visitor.ml:231:
63+
raw_data_sections_visitor.ml:0:
6164
(Cobol_ast__Raw_data_sections_visitor.fold_data_clause): partial visitor
6265
implementation
6366
{"params":{"diagnostics":[{"message":"Source format `auto` is not supported yet, using `fixed`","range":{"end":{"character":0,"line":0},"start":{"character":0,"line":0}},"severity":2}],"uri":"file://__rootdir__/prog.cob"},"method":"textDocument/publishDiagnostics","jsonrpc":"2.0"}

test/output-tests/gnucobol.ml

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,28 @@ let target =
4040
(** [pp_relloc ppf filename] prints [filename] relative to [srcdir] if the
4141
latter is a directory (prefix) of [filename]. Otherwise, prints [filename]
4242
as a whole. *)
43+
(*
4344
let pp_relloc =
4445
let srcdir_prefix = srcdir ^ Ez_file.FileOS.dir_separator_string in
4546
fun ppf s ->
46-
match EzString.chop_prefix ~prefix:srcdir_prefix s with
47-
| Some s -> Fmt.string ppf s
48-
| None -> Fmt.string ppf s
47+
let s =
48+
match EzString.chop_prefix ~prefix:srcdir_prefix s with
49+
| Some s -> s
50+
| None -> s
51+
in
52+
Fmt.string ppf s
53+
*)
54+
55+
let pp_relloc ppf s =
56+
let path = EzString.split s '/' in
57+
let rec iter path =
58+
match path with
59+
| [] -> s
60+
| "import" :: "gnucobol" :: _ -> String.concat "/" path
61+
| _ :: path -> iter path
62+
in
63+
let s = iter path in
64+
Fmt.string ppf s
4965

5066
let make_n_enter_rundir () =
5167
Superbol_testutils.Tempdir.make_n_enter "superbol-gnucobol-tests"

test/output-tests/preproc.ml

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,22 @@ open Ez_file
1616
open FileString.OP
1717
open Cobol_preproc
1818

19+
let find_dir anchor =
20+
let curdir = Sys.getcwd () in
21+
let rec iter path =
22+
if Sys.file_exists (path // anchor) then
23+
path
24+
else
25+
let path' = Filename.dirname path in
26+
if path = path' then
27+
Printf.kprintf failwith "Anchor %S not found from %s" anchor curdir;
28+
iter path'
29+
in
30+
iter curdir
31+
1932
let deep_iter = FileString.(make_select iter_dir) ~deep:true
20-
let srcdir = try Unix.getenv "DUNE_SOURCEROOT" with Not_found -> "."
33+
let srcdir = try Unix.getenv "DUNE_SOURCEROOT" with Not_found ->
34+
find_dir "test"
2135
let testsuites = "test/testsuite"
2236
let ibm_testsuite = testsuites // "ibm/ibmmainframes.com"
2337
let ibm_root = srcdir // ibm_testsuite

0 commit comments

Comments
 (0)