6
6
using JuliaSyntax, Logging, TerminalLoggers, ProgressLogging, Serialization
7
7
8
8
include (" ../test/test_utils.jl" )
9
+ include (" ../test/fuzz_test.jl" )
9
10
10
11
pkgspath = joinpath (@__DIR__ , " pkgs" )
11
12
source_paths = find_source_in_path (pkgspath)
@@ -16,6 +17,24 @@ mismatch_count = 0
16
17
t0 = time ()
17
18
exceptions = []
18
19
20
+ function parsers_disagree (text:: AbstractString )
21
+ fl_ex = fl_parseall (text, filename= " none" )
22
+ if Meta. isexpr (fl_ex, (:error ,:incomplete )) ||
23
+ (Meta. isexpr (fl_ex, :toplevel ) && length (fl_ex. args) >= 1 &&
24
+ Meta. isexpr (fl_ex. args[end ], (:error ,:incomplete )))
25
+ return false
26
+ end
27
+ try
28
+ ex = parseall (Expr, text, filename= " none" , ignore_errors= true )
29
+ return ! exprs_roughly_equal (fl_ex, ex)
30
+ catch
31
+ @error " Reduction failed" text
32
+ return false
33
+ end
34
+ end
35
+
36
+ all_reduced_failures = String[]
37
+
19
38
Logging. with_logger (TerminalLogger ()) do
20
39
global exception_count, mismatch_count, t0
21
40
@withprogress for (ifile, fpath) in enumerate (source_paths)
@@ -29,16 +48,19 @@ Logging.with_logger(TerminalLogger()) do
29
48
e1 = JuliaSyntax. parseall (Expr, text, filename= fpath, ignore_warnings= true )
30
49
if ! exprs_roughly_equal (e2, e1)
31
50
mismatch_count += 1
32
- reduced_chunks = sprint (context= :color => true ) do io
51
+ failing_source = sprint (context= :color => true ) do io
33
52
for c in reduce_test (text)
34
53
JuliaSyntax. highlight (io, c. source, range (c), context_lines_inner= 5 )
35
54
println (io, " \n " )
36
55
end
37
56
end
57
+ reduced_failures = rand_reduce .(sourcetext .(reduce_test (text)),
58
+ parsers_disagree)
59
+ append! (all_reduced_failures, reduced_failures)
38
60
@error (" Parsers succeed but disagree" ,
39
61
fpath,
40
- reduced_chunks = Text (reduced_chunks ),
41
- # diff=Text(sprint(show_expr_text_diff, show, e1, e2)) ,
62
+ failing_source = Text (failing_source ),
63
+ reduced_failures ,
42
64
)
43
65
end
44
66
catch err
@@ -75,3 +97,14 @@ println()
75
97
$(exception_count) failures compared to reference parser
76
98
$(mismatch_count) Expr mismatches
77
99
$(t_avg) ms per file"""
100
+
101
+ open (joinpath (@__DIR__ , " reduced_failures.jl" ), write= true ) do io
102
+ for str in all_reduced_failures
103
+ println (io, repr (str))
104
+ end
105
+ for str in all_reduced_failures
106
+ println (io, " #------------------------------" )
107
+ println (io, str)
108
+ println (io)
109
+ end
110
+ end
0 commit comments