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 print tests output relative to import/gnucobol/ #28

Merged
merged 1 commit into from
Sep 28, 2023
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
5 changes: 3 additions & 2 deletions src/lsp/cobol_ast/raw_data_sections_visitor.ml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ open Cobol_common.Visitor.INFIX (* for `>>` (== `|>`) *)
open Terms_visitor

let todo x = Cobol_common.Visitor.todo __FILE__ x
let partial x = Cobol_common.Visitor.partial __FILE__ x
let partial modname line funcname =
Cobol_common.Visitor.partial __FILE__ modname line funcname

(* --- *)

Expand Down Expand Up @@ -85,7 +86,7 @@ struct
end

let todo x = todo __MODULE__ x
and partial x = partial __MODULE__ x
and partial line funcname = partial __MODULE__ line funcname

let fold_data_level (v: _ #folder) =
leaf v#fold_data_level
Expand Down
5 changes: 5 additions & 0 deletions src/lsp/cobol_common/visitor.ml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ module INFIX = struct
end
open INFIX

let in_testsuite = ref false

let report = (* to be kept until visitors are complete *)
let module REPORTED =
Hashtbl.Make (struct
Expand All @@ -68,6 +70,9 @@ let report = (* to be kept until visitors are complete *)
let reported_table = lazy (REPORTED.create 17) in
fun k file_name module_name line_num func_name ->
let tbl = Lazy.force reported_table in
let file_name =
if !in_testsuite then Filename.basename file_name else file_name in
let line_num = if !in_testsuite then 0 else line_num in
if not (REPORTED.mem tbl (file_name, module_name, line_num, func_name))
then begin
Pretty.error "@[<2>%s:%u:@ (%s.%s):@ %s@ visitor@ implementation@]@."
Expand Down
4 changes: 2 additions & 2 deletions test/lsp/lsp_formatting.ml
Original file line number Diff line number Diff line change
Expand Up @@ -401,10 +401,10 @@ let%expect_test "formatting-request-whole-program" =
end_with_postproc [%expect.output];
[%expect {|
{"params":{"diagnostics":[],"uri":"file://__rootdir__/superbol.toml"},"method":"textDocument/publishDiagnostics","jsonrpc":"2.0"}
src/lsp/cobol_ast/raw_misc_sections_visitor.ml:66:
raw_misc_sections_visitor.ml:0:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lefessan What was the problem of having precise source locations here?
To me the occasional need for an auto-promotion does not warrant the ugly hack used in this PR to remove the info.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These locations are very handy when implementing the partial visitors, even and in particular in the tests.

(Cobol_ast__Raw_misc_sections_visitor.fold_select_clause): missing visitor
implementation
src/lsp/cobol_ast/raw_data_sections_visitor.ml:280:
raw_data_sections_visitor.ml:0:
(Cobol_ast__Raw_data_sections_visitor.fold_file_section): missing visitor
implementation
{"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"}
Expand Down
5 changes: 4 additions & 1 deletion test/lsp/lsp_references.ml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ open EzCompat (* StringMap *)
open Lsp.Types
open Lsp_testing

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

let print_references ~projdir server (doc, positions) : unit =
let server, prog = add_cobol_doc server ~projdir "prog.cob" doc in
Expand Down Expand Up @@ -57,7 +60,7 @@ let%expect_test "simple-references-requests" =
end_with_postproc [%expect.output];
[%expect {|
{"params":{"diagnostics":[],"uri":"file://__rootdir__/superbol.toml"},"method":"textDocument/publishDiagnostics","jsonrpc":"2.0"}
src/lsp/cobol_ast/raw_data_sections_visitor.ml:231:
raw_data_sections_visitor.ml:0:
(Cobol_ast__Raw_data_sections_visitor.fold_data_clause): partial visitor
implementation
{"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"}
Expand Down
22 changes: 19 additions & 3 deletions test/output-tests/gnucobol.ml
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,28 @@ let target =
(** [pp_relloc ppf filename] prints [filename] relative to [srcdir] if the
latter is a directory (prefix) of [filename]. Otherwise, prints [filename]
as a whole. *)
(*
let pp_relloc =
let srcdir_prefix = srcdir ^ Ez_file.FileOS.dir_separator_string in
fun ppf s ->
match EzString.chop_prefix ~prefix:srcdir_prefix s with
| Some s -> Fmt.string ppf s
| None -> Fmt.string ppf s
let s =
match EzString.chop_prefix ~prefix:srcdir_prefix s with
| Some s -> s
| None -> s
in
Fmt.string ppf s
*)

let pp_relloc ppf s =
let path = EzString.split s '/' in
let rec iter path =
match path with
| [] -> s
| "import" :: "gnucobol" :: _ -> String.concat "/" path
Copy link
Collaborator

@nberth nberth Sep 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While you're at it, why not strip the import altogether?

Also ppf stands for pretty-printing-formatter (I think). fmt is the old-school name, that unfortunately can be mistaken for "format(-string)".

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok for ppf. For import, I don't want to match only on gnucobol, as it may appear above the source directory...

| _ :: path -> iter path
in
let s = iter path in
Fmt.string ppf s

let make_n_enter_rundir () =
Superbol_testutils.Tempdir.make_n_enter "superbol-gnucobol-tests"
Expand Down
16 changes: 15 additions & 1 deletion test/output-tests/preproc.ml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,22 @@ open Ez_file
open FileString.OP
open Cobol_preproc

let find_dir anchor =
let curdir = Sys.getcwd () in
let rec iter path =
if Sys.file_exists (path // anchor) then
path
else
let path' = Filename.dirname path in
if path = path' then
Printf.kprintf failwith "Anchor %S not found from %s" anchor curdir;
iter path'
in
iter curdir

let deep_iter = FileString.(make_select iter_dir) ~deep:true
let srcdir = try Unix.getenv "DUNE_SOURCEROOT" with Not_found -> "."
let srcdir = try Unix.getenv "DUNE_SOURCEROOT" with Not_found ->
find_dir "test"
let testsuites = "test/testsuite"
let ibm_testsuite = testsuites // "ibm/ibmmainframes.com"
let ibm_root = srcdir // ibm_testsuite
Expand Down
Loading