Skip to content

Commit c4f1f6a

Browse files
authored
Improve syntax diffing in General registry checker (#216)
1 parent 442f3e4 commit c4f1f6a

File tree

2 files changed

+54
-61
lines changed

2 files changed

+54
-61
lines changed

test/test_utils.jl

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -245,14 +245,7 @@ function equals_flisp_parse(exprs_equal, tree)
245245
exprs_equal(fl_ex, ex)
246246
end
247247

248-
"""
249-
reduce_test(text::AbstractString; exprs_equal=exprs_equal_no_linenum)
250-
reduce_test(tree::SyntaxNode; exprs_equal=exprs_equal_no_linenum)
251-
252-
Select minimal subtrees of `text` or `tree` which are inconsistent between
253-
flisp and JuliaSyntax parsers.
254-
"""
255-
function reduce_test(failing_subtrees, tree; exprs_equal=exprs_equal_no_linenum)
248+
function _reduce_test(failing_subtrees, tree; exprs_equal=exprs_equal_no_linenum)
256249
if equals_flisp_parse(exprs_equal, tree)
257250
return false
258251
end
@@ -266,7 +259,7 @@ function reduce_test(failing_subtrees, tree; exprs_equal=exprs_equal_no_linenum)
266259
if is_trivia(child) || !haschildren(child)
267260
continue
268261
end
269-
had_failing_subtrees |= reduce_test(failing_subtrees, child; exprs_equal=exprs_equal)
262+
had_failing_subtrees |= _reduce_test(failing_subtrees, child; exprs_equal=exprs_equal)
270263
end
271264
end
272265
if !had_failing_subtrees
@@ -275,9 +268,16 @@ function reduce_test(failing_subtrees, tree; exprs_equal=exprs_equal_no_linenum)
275268
return true
276269
end
277270

271+
"""
272+
reduce_test(text::AbstractString; exprs_equal=exprs_equal_no_linenum)
273+
reduce_test(tree::SyntaxNode; exprs_equal=exprs_equal_no_linenum)
274+
275+
Select minimal subtrees of `text` or `tree` which are inconsistent between
276+
flisp and JuliaSyntax parsers.
277+
"""
278278
function reduce_test(tree::SyntaxNode; kws...)
279279
subtrees = Vector{typeof(tree)}()
280-
reduce_test(subtrees, tree; kws...)
280+
_reduce_test(subtrees, tree; kws...)
281281
subtrees
282282
end
283283

tools/check_all_packages.jl

Lines changed: 44 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -3,76 +3,69 @@
33
#
44
# Run this after registry_download.jl (so the pkgs directory is populated).
55

6-
using JuliaSyntax, Logging, Serialization
6+
using JuliaSyntax, Logging, TerminalLoggers, ProgressLogging, Serialization
77

88
include("../test/test_utils.jl")
99

10-
logio = open(joinpath(@__DIR__, "logs.txt"), "w")
11-
logger = Logging.ConsoleLogger(logio)
12-
1310
pkgspath = joinpath(@__DIR__, "pkgs")
11+
source_paths = find_source_in_path(pkgspath)
12+
file_count = length(source_paths)
1413

1514
exception_count = 0
1615
mismatch_count = 0
17-
file_count = 0
1816
t0 = time()
1917
exceptions = []
2018

21-
Logging.with_logger(logger) do
22-
global exception_count, mismatch_count, file_count, t0
23-
for (r, _, files) in walkdir(pkgspath)
24-
for f in files
25-
endswith(f, ".jl") || continue
26-
fpath = joinpath(r, f)
27-
isfile(fpath) || continue
28-
29-
code = read(fpath, String)
30-
expr_cache = fpath*".Expr"
31-
#e2 = JuliaSyntax.fl_parseall(code)
32-
e2 = open(deserialize, fpath*".Expr")
33-
@assert Meta.isexpr(e2, :toplevel)
34-
try
35-
e1 = JuliaSyntax.parseall(Expr, code, filename=fpath, ignore_warnings=true)
36-
if !exprs_roughly_equal(e2, e1)
37-
mismatch_count += 1
38-
@error("Parsers succeed but disagree",
39-
fpath,
40-
diff=Text(sprint(show_expr_text_diff, show, e1, e2)),
41-
)
42-
end
43-
catch err
44-
err isa InterruptException && rethrow()
45-
ex = (err, catch_backtrace())
46-
push!(exceptions, ex)
47-
ref_parse = "success"
48-
if length(e2.args) >= 1 && Meta.isexpr(last(e2.args), (:error, :incomplete))
49-
ref_parse = "fail"
50-
if err isa JuliaSyntax.ParseError
51-
# Both parsers agree that there's an error, and
52-
# JuliaSyntax didn't have an internal error.
53-
continue
19+
Logging.with_logger(TerminalLogger()) do
20+
global exception_count, mismatch_count, t0
21+
@withprogress for (ifile, fpath) in enumerate(source_paths)
22+
@logprogress ifile/file_count time_ms=round((time() - t0)/ifile*1000, digits = 2)
23+
text = read(fpath, String)
24+
expr_cache = fpath*".Expr"
25+
#e2 = JuliaSyntax.fl_parseall(text)
26+
e2 = open(deserialize, fpath*".Expr")
27+
@assert Meta.isexpr(e2, :toplevel)
28+
try
29+
e1 = JuliaSyntax.parseall(Expr, text, filename=fpath, ignore_warnings=true)
30+
if !exprs_roughly_equal(e2, e1)
31+
mismatch_count += 1
32+
reduced_chunks = sprint(context=:color=>true) do io
33+
for c in reduce_test(text)
34+
JuliaSyntax.highlight(io, c.source, range(c), context_inner_lines=5)
35+
println(io, "\n")
5436
end
5537
end
56-
57-
exception_count += 1
58-
parse_to_syntax = "success"
59-
try
60-
JuliaSyntax.parseall(JuliaSyntax.SyntaxNode, code)
61-
catch err2
62-
parse_to_syntax = "fail"
38+
@error("Parsers succeed but disagree",
39+
fpath,
40+
reduced_chunks=Text(reduced_chunks),
41+
# diff=Text(sprint(show_expr_text_diff, show, e1, e2)),
42+
)
43+
end
44+
catch err
45+
err isa InterruptException && rethrow()
46+
ex = (err, catch_backtrace())
47+
push!(exceptions, ex)
48+
ref_parse = "success"
49+
if length(e2.args) >= 1 && Meta.isexpr(last(e2.args), (:error, :incomplete))
50+
ref_parse = "fail"
51+
if err isa JuliaSyntax.ParseError
52+
# Both parsers agree that there's an error, and
53+
# JuliaSyntax didn't have an internal error.
54+
continue
6355
end
64-
@error "Parse failed" fpath exception=ex parse_to_syntax
6556
end
6657

67-
file_count += 1
68-
if file_count % 100 == 0
69-
t_avg = round((time() - t0)/file_count*1000, digits = 2)
70-
print(stderr, "\r$file_count files parsed, $t_avg ms per file")
58+
exception_count += 1
59+
parse_to_syntax = "success"
60+
try
61+
JuliaSyntax.parseall(JuliaSyntax.SyntaxNode, code)
62+
catch err2
63+
parse_to_syntax = "fail"
7164
end
65+
@error "Parse failed" fpath exception=ex parse_to_syntax
7266
end
7367
end
7468
end
75-
close(logio)
7669

7770
t_avg = round((time() - t0)/file_count*1000, digits = 2)
7871

0 commit comments

Comments
 (0)