Browse Source

Add a progress prefix in verbose mode

This patch adds a progress prefix to each file of the form
`[file/nfiles]` to verbose output.
pull/121/head
Fredrik Ekre 12 months ago
parent
commit
e3f5d040fb
No known key found for this signature in database
GPG Key ID: DE82E6D5E364C0A2
  1. 37
      src/main.jl
  2. 29
      test/maintests.jl

37
src/main.jl

@ -85,12 +85,15 @@ function panic( @@ -85,12 +85,15 @@ function panic(
return errno
end
function okln()
blue(str) = printstyled(stderr, str; color = :blue)
function okln(str)
blue(str)
printstyled(stderr, ""; color = :green, bold = true)
println(stderr)
return
end
function errln()
function errln(str)
blue(str)
printstyled(stderr, ""; color = :red, bold = true)
println(stderr)
return
@ -316,7 +319,8 @@ function main(argv) @@ -316,7 +319,8 @@ function main(argv)
end
# Loop over the input files
for inputfile in inputfiles
nfiles_str = string(length(inputfiles))
for (file_counter, inputfile) in enumerate(inputfiles)
# Read the input
if input_is_stdin
@assert length(inputfiles) == 1
@ -365,14 +369,18 @@ function main(argv) @@ -365,14 +369,18 @@ function main(argv)
if print_progress
@assert inputfile != "-"
input_pretty = relpath(inputfile)
prefix = string(
"[", lpad(string(file_counter), textwidth(nfiles_str), " "), "/",
nfiles_str, "] "
)
if Sys.iswindows()
input_pretty = replace(input_pretty, "\\" => "/")
end
if check
str = "Checking `$(input_pretty)` "
str = string(prefix, "Checking `", input_pretty, "` ")
ndots = 80 - textwidth(str) - 1 - 1
dots = ndots > 0 ? "."^ndots : ""
printstyled(stderr, str * dots * " "; color = :blue)
str = string(str, dots, " ")
else
if output.output_is_samefile
output_pretty = " "
@ -383,10 +391,10 @@ function main(argv) @@ -383,10 +391,10 @@ function main(argv)
end
output_pretty = " -> `$(output_pretty)` "
end
str = "Formatting `$(input_pretty)`$(output_pretty)"
str = string(prefix, "Formatting `", input_pretty, "`", output_pretty)
ndots = 80 - textwidth(str) - 1 - 1
dots = ndots > 0 ? "."^ndots : ""
printstyled(stderr, str * dots * " "; color = :blue)
str = string(str, dots, " ")
end
end
@ -396,7 +404,7 @@ function main(argv) @@ -396,7 +404,7 @@ function main(argv)
format_tree!(ctx′)
ctx′
catch err
print_progress && errln()
print_progress && errln(str)
if err isa JuliaSyntax.ParseError
panic("failed to parse input: ", err)
continue
@ -424,24 +432,25 @@ function main(argv) @@ -424,24 +432,25 @@ function main(argv)
changed = !nodes_equal(ctx.fmt_tree, ctx.src_tree)
if check
if changed
print_progress && errln()
print_progress && errln(str)
global errno = 1
else
print_progress && okln()
print_progress && okln(str)
end
elseif changed || !inplace
@assert output.which !== :devnull
try
writeo(output, seekstart(ctx.fmt_io))
catch err
print_progress && errln()
print_progress && errln(str)
panic("could not write to output file `$(output.file)`: ", err)
continue
end
print_progress && okln()
print_progress && okln(str)
else
print_progress && okln()
print_progress && okln(str)
end
if diff
if changed && diff
mktempdir() do dir
a = mkdir(joinpath(dir, "a"))
b = mkdir(joinpath(dir, "b"))

29
test/maintests.jl

@ -104,7 +104,7 @@ function maintests(f::R) where {R} @@ -104,7 +104,7 @@ function maintests(f::R) where {R}
rc, fd1, fd2 = runic(argv)
@test rc == 0
@test isempty(fd1)
@test occursin("Formatting `in.jl` -> `out.jl` ...", fd2)
@test occursin("[1/1] Formatting `in.jl` -> `out.jl` ...", fd2)
@test occursin("", fd2)
@test !occursin("", fd2)
@test read(f_out, String) == good
@ -128,7 +128,7 @@ function maintests(f::R) where {R} @@ -128,7 +128,7 @@ function maintests(f::R) where {R}
rc, fd1, fd2 = runic(argv)
@test rc == 0
@test isempty(fd1)
@test occursin("Formatting `in.jl` ...", fd2)
@test occursin("[1/1] Formatting `in.jl` ...", fd2)
@test occursin("", fd2)
@test !occursin("", fd2)
@test read(f_in, String) == good
@ -150,7 +150,7 @@ function maintests(f::R) where {R} @@ -150,7 +150,7 @@ function maintests(f::R) where {R}
write(f_in, good)
rc, fd1, fd2 = runic(argv)
@test rc == 0
@test occursin("Formatting `in.jl` ...", fd2)
@test occursin("[1/1] Formatting `in.jl` ...", fd2)
@test occursin("", fd2)
@test !occursin("", fd2)
@test read(f_in, String) == good
@ -184,6 +184,7 @@ function maintests(f::R) where {R} @@ -184,6 +184,7 @@ function maintests(f::R) where {R}
@test isempty(fd1)
@test occursin("Formatting `good.jl` ...", fd2)
@test occursin("Formatting `src/bad.jl` ...", fd2)
@test occursin("[1/2]", fd2) && occursin("[2/2]", fd2)
@test occursin("", fd2)
@test !occursin("", fd2)
@test !occursin("git.jl", fd2)
@ -208,7 +209,7 @@ function maintests(f::R) where {R} @@ -208,7 +209,7 @@ function maintests(f::R) where {R}
rc, fd1, fd2 = runic(argv)
@test rc == 1
@test isempty(fd1)
@test occursin("Checking `in.jl` ...", fd2)
@test occursin("[1/1] Checking `in.jl` ...", fd2)
@test !occursin("", fd2)
@test occursin("", fd2)
@test read(f_in, String) == bad
@ -230,7 +231,7 @@ function maintests(f::R) where {R} @@ -230,7 +231,7 @@ function maintests(f::R) where {R}
rc, fd1, fd2 = runic(argv)
@test rc == 0
@test isempty(fd1)
@test occursin("Checking `in.jl` ...", fd2)
@test occursin("[1/1] Checking `in.jl` ...", fd2)
@test occursin("", fd2)
@test !occursin("", fd2)
@test read(f_in, String) == good
@ -265,6 +266,7 @@ function maintests(f::R) where {R} @@ -265,6 +266,7 @@ function maintests(f::R) where {R}
@test isempty(fd1)
@test occursin("Checking `good.jl` ...", fd2)
@test occursin("Checking `src/bad.jl` ...", fd2)
@test occursin("[1/2]", fd2) && occursin("[2/2]", fd2)
@test occursin("", fd2)
@test occursin("", fd2)
@test !occursin("git.jl", fd2)
@ -296,7 +298,7 @@ function maintests(f::R) where {R} @@ -296,7 +298,7 @@ function maintests(f::R) where {R}
rc, fd1, fd2 = runic(argv)
@test rc == 1
@test isempty(fd1)
@test occursin("Checking `in.jl` ...", fd2)
@test occursin("[1/1] Checking `in.jl` ...", fd2)
@test !occursin("", fd2)
@test occursin("", fd2)
@test occursin("diff --git", fd2)
@ -307,6 +309,21 @@ function maintests(f::R) where {R} @@ -307,6 +309,21 @@ function maintests(f::R) where {R}
end
end
# runic --verbose
cdtmp() do
f_in = "in.jl"
write(f_in, good)
let argv = ["--verbose"; "--check"; fill(f_in, 10)]
rc, fd1, fd2 = runic(argv)
@test rc == 0
@test isempty(fd1)
for i in 1:9
@test occursin("[ $(i)/10] Checking `in.jl` ...", fd2)
end
@test occursin("[10/10] Checking `in.jl` ...", fd2)
end
end
# Error paths
# runic -o
let (rc, fd1, fd2) = runic(["-o"])

Loading…
Cancel
Save