|
3 | 3 | #
|
4 | 4 | # Run this after registry_download.jl (so the pkgs directory is populated).
|
5 | 5 |
|
6 |
| -using JuliaSyntax, Logging, Serialization |
| 6 | +using JuliaSyntax, Logging, TerminalLoggers, ProgressLogging, Serialization |
7 | 7 |
|
8 | 8 | include("../test/test_utils.jl")
|
9 | 9 |
|
10 |
| -logio = open(joinpath(@__DIR__, "logs.txt"), "w") |
11 |
| -logger = Logging.ConsoleLogger(logio) |
12 |
| - |
13 | 10 | pkgspath = joinpath(@__DIR__, "pkgs")
|
| 11 | +source_paths = find_source_in_path(pkgspath) |
| 12 | +file_count = length(source_paths) |
14 | 13 |
|
15 | 14 | exception_count = 0
|
16 | 15 | mismatch_count = 0
|
17 |
| -file_count = 0 |
18 | 16 | t0 = time()
|
19 | 17 | exceptions = []
|
20 | 18 |
|
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") |
54 | 36 | end
|
55 | 37 | 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 |
63 | 55 | end
|
64 |
| - @error "Parse failed" fpath exception=ex parse_to_syntax |
65 | 56 | end
|
66 | 57 |
|
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" |
71 | 64 | end
|
| 65 | + @error "Parse failed" fpath exception=ex parse_to_syntax |
72 | 66 | end
|
73 | 67 | end
|
74 | 68 | end
|
75 |
| -close(logio) |
76 | 69 |
|
77 | 70 | t_avg = round((time() - t0)/file_count*1000, digits = 2)
|
78 | 71 |
|
|
0 commit comments