Skip to content

Commit

Permalink
better empty loading test
Browse files Browse the repository at this point in the history
  • Loading branch information
aviatesk committed Feb 4, 2025
1 parent 082691f commit 1b2f707
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 62 deletions.
11 changes: 6 additions & 5 deletions .github/workflows/loading-on-nightly.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: CI – Loading test on nightly
name: CI – Empty loading test on nightly

on:
push:
Expand All @@ -7,7 +7,7 @@ on:
pull_request:

jobs:
test:
empty-loading-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand All @@ -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
23 changes: 11 additions & 12 deletions src/JET.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
37 changes: 17 additions & 20 deletions src/JETEmpty.jl
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)

Check warning on line 27 in src/JETEmpty.jl

View check run for this annotation

Codecov / codecov/patch

src/JETEmpty.jl#L27

Added line #L27 was not covered by tests
@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)

Check warning on line 31 in src/JETEmpty.jl

View check run for this annotation

Codecov / codecov/patch

src/JETEmpty.jl#L31

Added line #L31 was not covered by tests
exported_macro_name = Symbol(lstrip(String(exported_macro), '@'))
@eval macro $exported_macro_name(exs...); :(error($(GlobalRef(@__MODULE__, :empty_stub_message)))); end
end
74 changes: 49 additions & 25 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -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
9 changes: 9 additions & 0 deletions test/test_JETEmpty.jl
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 1b2f707

Please sign in to comment.