Skip to content

Commit 2eaffde

Browse files
fix: multithreading in jlfmt app
Adds a minimal test against future regression in this too
1 parent 1f1f794 commit 2eaffde

3 files changed

Lines changed: 49 additions & 2 deletions

File tree

src/app.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,7 @@ function main(argv::Vector{String})
560560
print_progress = verbose && !(input_is_stdin || output_is_stdout)
561561

562562
nfiles_str = string(length(inputfiles))
563-
options_list = (
563+
options_list = [
564564
ProcessFileArgs(
565565
inputfile,
566566
file_counter,
@@ -577,7 +577,7 @@ function main(argv::Vector{String})
577577
format_markdown,
578578
config_priority,
579579
) for (file_counter, inputfile) in enumerate(inputfiles)
580-
)
580+
]
581581

582582
# Use multithreading for multiple files (only if multiple threads available)
583583
# Single file or stdin or single thread: process sequentially

test/jlfmt_app.jl

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
@testset "Test jlfmt app" begin
2+
@testset "Test app with threads" begin
3+
mktempdir(; prefix = "jlfmt_threads_") do sandbox_dir
4+
write(
5+
joinpath(sandbox_dir, "spacing_and_call.jl"),
6+
"""
7+
f( x,y )=x+y
8+
z=f( 1,2 )
9+
""",
10+
)
11+
12+
write(
13+
joinpath(sandbox_dir, "control_flow_and_collection.jl"),
14+
"""
15+
function g(xs)
16+
ys=[ x*2 for x in xs if x>0 ]
17+
return ys
18+
end
19+
""",
20+
)
21+
22+
write(
23+
joinpath(sandbox_dir, "struct_and_keywords.jl"),
24+
"""
25+
struct Foo
26+
x::Int
27+
y::String
28+
end
29+
30+
h(;a=1,b=2)=a+b
31+
""",
32+
)
33+
34+
project = dirname(Base.active_project())
35+
36+
check_before_cmd = `$(Base.julia_cmd()) --threads=3 --project=$project -m JuliaFormatter --check $sandbox_dir`
37+
@test !success(check_before_cmd)
38+
39+
format_cmd = `$(Base.julia_cmd()) --threads=3 --project=$project -m JuliaFormatter --inplace $sandbox_dir`
40+
@test success(format_cmd)
41+
42+
check_after_cmd = `$(Base.julia_cmd()) --threads=3 --project=$project -m JuliaFormatter --check $sandbox_dir`
43+
@test success(check_after_cmd)
44+
end
45+
end
46+
end

test/runtests.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,4 +77,5 @@ end
7777
include("interface.jl")
7878
include("config.jl")
7979
include("format_repo.jl")
80+
include("jlfmt_app.jl")
8081
end

0 commit comments

Comments
 (0)