From b54118073e5650bb0434157861d89ac6ee787a93 Mon Sep 17 00:00:00 2001 From: janlukas Date: Fri, 27 Oct 2023 17:26:56 +0100 Subject: [PATCH 1/2] Only run command_main when calling from CLI --- src/frontend/cast.jl | 4 +++- test/scripts.jl | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/frontend/cast.jl b/src/frontend/cast.jl index b51307a4..21e9349c 100644 --- a/src/frontend/cast.jl +++ b/src/frontend/cast.jl @@ -461,7 +461,9 @@ end function codegen_script_entry(m::Module, line, @nospecialize(ex)) quote $(codegen_create_entry(m, line, ex)) - command_main() + if abspath(PROGRAM_FILE) == @__FILE__ + command_main() + end end end diff --git a/test/scripts.jl b/test/scripts.jl index b4d13843..df5d30bd 100644 --- a/test/scripts.jl +++ b/test/scripts.jl @@ -5,7 +5,7 @@ using Test @testset "scripts" begin empty!(ARGS) push!(ARGS, "arg", "--opt1=2", "--opt2", "3", "-f") - @test Base.include(Main, "scripts/hello.jl") == 0 + @test Base.include(Main, "scripts/hello.jl") === nothing empty!(ARGS) push!(ARGS, "activate", "-h") @@ -17,7 +17,7 @@ using Test empty!(ARGS) push!(ARGS, "Author - Year.pdf") - @test Base.include(Main, "scripts/searchpdf.jl") == 0 + @test Base.include(Main, "scripts/searchpdf.jl") == nothing end end From 00669b07da48c774d181fd80440aee0ba0f84e59 Mon Sep 17 00:00:00 2001 From: janlukas Date: Mon, 30 Oct 2023 10:13:47 +0000 Subject: [PATCH 2/2] Fixed tests for including scripts --- test/scripts.jl | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/test/scripts.jl b/test/scripts.jl index df5d30bd..48b805f0 100644 --- a/test/scripts.jl +++ b/test/scripts.jl @@ -5,7 +5,8 @@ using Test @testset "scripts" begin empty!(ARGS) push!(ARGS, "arg", "--opt1=2", "--opt2", "3", "-f") - @test Base.include(Main, "scripts/hello.jl") === nothing + Base.include(Main, "scripts/hello.jl") + @test Main.command_main() == 0 empty!(ARGS) push!(ARGS, "activate", "-h") @@ -17,7 +18,8 @@ using Test empty!(ARGS) push!(ARGS, "Author - Year.pdf") - @test Base.include(Main, "scripts/searchpdf.jl") == nothing + Base.include(Main, "scripts/searchpdf.jl") + @test Main.command_main() == 0 end end