From 9bf421d45f1c09b080271f697c2375637988c89e Mon Sep 17 00:00:00 2001 From: Shuhei Kadowaki <40514306+aviatesk@users.noreply.github.com> Date: Tue, 4 Feb 2025 20:45:24 +0900 Subject: [PATCH] better empty loading test (#689) --- .github/workflows/loading-on-nightly.yml | 11 ++-- src/JET.jl | 23 ++++---- src/JETEmpty.jl | 37 ++++++------ test/runtests.jl | 74 ++++++++++++++++-------- test/test_JETEmpty.jl | 9 +++ 5 files changed, 92 insertions(+), 62 deletions(-) create mode 100644 test/test_JETEmpty.jl diff --git a/.github/workflows/loading-on-nightly.yml b/.github/workflows/loading-on-nightly.yml index f5a496d6e..70f556e4f 100644 --- a/.github/workflows/loading-on-nightly.yml +++ b/.github/workflows/loading-on-nightly.yml @@ -1,4 +1,4 @@ -name: CI – Loading test on nightly +name: CI – Empty loading test on nightly on: push: @@ -7,7 +7,7 @@ on: pull_request: jobs: - test: + empty-loading-test: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 @@ -16,6 +16,7 @@ jobs: version: 'nightly' arch: x64 - uses: julia-actions/julia-buildpkg@latest - - name: Loading test - run: | - julia --startup-file=no --project=@. -e 'using JET' + - uses: julia-actions/julia-buildpkg@latest + - uses: julia-actions/julia-runtest@latest + - uses: julia-actions/julia-processcoverage@v1 + - uses: codecov/codecov-action@v5 diff --git a/src/JET.jl b/src/JET.jl index 3352232f4..75329dd56 100644 --- a/src/JET.jl +++ b/src/JET.jl @@ -9,15 +9,20 @@ const JET_LOADABLE = JET_DEV_MODE || (get(VERSION.prerelease, 1, "") != "DEV") # exports # ======= -export +const exports = Set{Symbol}(( # jetanalyzer - @report_call, report_call, @test_call, test_call, - report_file, test_file, report_package, test_package, report_text, reportkey, test_text, - watch_file, + Symbol("@report_call"), :report_call, Symbol("@test_call"), :test_call, + :report_file, :test_file, :report_package, :test_package, :report_text, :reportkey, :test_text, + :watch_file, # optanalyzer - @report_opt, report_opt, @test_opt, test_opt, + Symbol("@report_opt"), :report_opt, Symbol("@test_opt"), :test_opt, # configurations - LastFrameModule, AnyFrameModule + :LastFrameModule, :AnyFrameModule +)) + +for exported_name in exports + Core.eval(@__MODULE__, Expr(:export, exported_name)) +end # Pre-release Julia versions are not supported, and we don't expect JET to even # precompile in pre-release versions. So, instead of having JET fail to precompile, we @@ -28,12 +33,6 @@ export @static if JET_LOADABLE include("JETBase.jl") else - @warn """ - JET.jl does not guarantee compatibility with nightly versions of Julia and, - it will not be loaded on nightly versions by default. - If you want to load JET on a nightly version, set the `JET_DEV_MODE` Preferences.jl - configuration to `true` and reload it. - """ include("JETEmpty.jl") end diff --git a/src/JETEmpty.jl b/src/JETEmpty.jl index 4ee1a4481..55ddc9938 100644 --- a/src/JETEmpty.jl +++ b/src/JETEmpty.jl @@ -1,7 +1,17 @@ # Empty stubs for the exported functions/macros of JET.jl, to provide a more informative # error message when JET.jl is used with a pre-release version of Julia. -const err_msg = strip(""" +const empty_loading_message = """ + JET.jl does not guarantee compatibility with nightly versions of Julia and, + it will not be loaded on nightly versions by default. + If you want to load JET on a nightly version, set the `JET_DEV_MODE` Preferences.jl + configuration to `true` and reload it. + """ |> strip +function __init__() + @warn empty_loading_message +end + +const empty_stub_message = strip(""" JET.jl does not guarantee compatibility with pre-release versions of Julia and is not be loaded on this versions by default. Julia VERSION = $VERSION @@ -14,24 +24,11 @@ const err_msg = strip(""" even with `JET_DEV_MODE` enabled. """) -for exported_func in ( - :report_call, :test_call, - :report_file, :test_file, :report_package, :test_package, :report_text, :reportkey, :test_text, - :watch_file, - # optanalyzer - :report_opt, :test_opt, - # configurations - :LastFrameModule, :AnyFrameModule -) - @eval $exported_func(args...; kws...) = error($err_msg) +for exported_func in filter(name::Symbol->!startswith(String(name), "@"), exports) + @eval $exported_func(args...; kws...) = error($(GlobalRef(@__MODULE__, :empty_stub_message))) end -for exported_macro in ( - :report_call, :test_call, - :report_opt, :test_opt -) - @eval begin - macro $exported_macro(args...) - error($err_msg) - end - end + +for exported_macro in filter(name::Symbol->startswith(String(name), "@"), exports) + exported_macro_name = Symbol(lstrip(String(exported_macro), '@')) + @eval macro $exported_macro_name(exs...); :(error($(GlobalRef(@__MODULE__, :empty_stub_message)))); end end diff --git a/test/runtests.jl b/test/runtests.jl index c077c4a6d..9205aa5cc 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,44 +1,68 @@ -using Test, JET +using Test + +const outmsg, errmsg = let + local outmsg::String, errmsg::String + mktemp() do outpath, stdout + mktemp() do errpath, stderr + redirect_stdio(; stdout, stderr) do + @eval using JET + end + flush(stderr) + errmsg = read(errpath, String) + end + flush(stdout) + outmsg = read(outpath, String) + end + outmsg, errmsg +end + +isempty(outmsg) || println(outmsg) +isempty(errmsg) || println(errmsg) @info "JET setup information:" JET.JET_DEV_MODE @testset "JET.jl" begin - @testset "abstractinterpret" begin - @testset "inferenceerrorreport.jl" include("abstractinterpret/test_inferenceerrorreport.jl") + @static if JET.JET_LOADABLE + @testset "abstractinterpret" begin + @testset "inferenceerrorreport.jl" include("abstractinterpret/test_inferenceerrorreport.jl") - @testset "typeinfer.jl" include("abstractinterpret/test_typeinfer.jl") - end + @testset "typeinfer.jl" include("abstractinterpret/test_typeinfer.jl") + end - @testset "toplevel" begin - @testset "virtualprocess.jl" include("toplevel/test_virtualprocess.jl") - end + @testset "toplevel" begin + @testset "virtualprocess.jl" include("toplevel/test_virtualprocess.jl") + end - @testset "ui" begin - # tests with Windows-paths is just an hell - @static Sys.iswindows() || @testset "print.jl" include("ui/test_print.jl") + @testset "ui" begin + # tests with Windows-paths is just an hell + @static Sys.iswindows() || @testset "print.jl" include("ui/test_print.jl") - @testset "vscode.jl" include("ui/test_vscode.jl") - end + @testset "vscode.jl" include("ui/test_vscode.jl") + end - @testset "misc" include("test_misc.jl") + @testset "misc" include("test_misc.jl") - @testset "Test.jl integration" include("test_Test.jl") + @testset "Test.jl integration" include("test_Test.jl") - @testset "JETInterface" include("test_JETInterface.jl") + @testset "JETInterface" include("test_JETInterface.jl") - @testset "analyzers" begin - @testset "JETAnalyzer" include("analyzers/test_jetanalyzer.jl") + @testset "analyzers" begin + @testset "JETAnalyzer" include("analyzers/test_jetanalyzer.jl") - @testset "OptAnalyzer" include("analyzers/test_optanalyzer.jl") - end + @testset "OptAnalyzer" include("analyzers/test_optanalyzer.jl") + end - @testset "performance" include("performance.jl") + @testset "performance" include("performance.jl") - @testset "sanity check" include("sanity_check.jl") + @testset "sanity check" include("sanity_check.jl") - @testset "self check" include("self_check.jl") + @testset "self check" include("self_check.jl") - @testset "extensions" begin - include("ext/test_cthulhu.jl") + @testset "extensions" begin + include("ext/test_cthulhu.jl") + end + else + @info "JET was not loaded fully, switching to run the tests for JETEmpty.jl." + @testset "test_JETEmpty.jl" include("test_JETEmpty.jl") end end diff --git a/test/test_JETEmpty.jl b/test/test_JETEmpty.jl new file mode 100644 index 000000000..8395229d4 --- /dev/null +++ b/test/test_JETEmpty.jl @@ -0,0 +1,9 @@ +using Test, JET + +for line in filter(!isempty, split(JET.empty_loading_message, '\n')) + @test occursin(line, errmsg) +end + +@test_throws JET.empty_stub_message report_call(sin, (Int,)) + +@test_throws JET.empty_stub_message @report_call sin(42)