#' @srrstats {G5.2} Appropriate message/warning/error tests are in `/tests/testthat`
test_that("Setup with seed works (use 2 for testing)", {
expect_message(jlmerclusterperm_setup(restart = FALSE), "already running")
test_that("RNG initializes to seed=1 counter=0", {

"Setup with seed works (use 2 for testing)"

Setup with seed works (use 2 for testing)

get_rng_seed() (`actual`) not equal to 1 (`expected`).

`actual` is NULL
`expected` is a double vector (1)

Error: Evaluation in Julia failed.
Original Julia error message:
LoadError: UndefVarError: rng not defined
Stacktrace:
  [1] top-level scope
    @ string:1
  [2] eval
    @ .\boot.jl:368 [inlined]
  [3] include_string(mapexpr::typeof(identity), mod::Module, code::String, filename::String)
    @ Base .\loading.jl:1428
  [4] include_string (repeats 2 times)
    @ .\loading.jl:1438 [inlined]
  [5] mainevalcmd(str::String)
    @ Main.RConnector D:\RCompile\CRANpkg\lib\4.4\JuliaConnectoR\Julia\evaluating.jl:150
  [6] invokelatest(::Any, ::Any, ::Vararg{Any}; kwargs::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
    @ Base .\essentials.jl:729
  [7] invokelatest(::Any, ::Any, ::Vararg{Any})
    @ Base .\essentials.jl:726
  [8] evaluate!(call::Main.RConnector.Call, communicator::Main.RConnector.CommunicatoR{Sockets.TCPSocket})
    @ Main.RConnector D:\RCompile\CRANpkg\lib\4.4\JuliaConnectoR\Julia\evaluating.jl:67
  [9] evaluate_checked!(call::Main.RConnector.Call, communicator::Main.RConnector.CommunicatoR{Sockets.TCPSocket})
    @ Main.RConnector D:\RCompile\CRANpkg\lib\4.4\JuliaConnectoR\Julia\evaluating.jl:55
 [10] serve_repl(sock::Sockets.TCPSocket)
    @ Main.RConnector D:\RCompile\CRANpkg\lib\4.4\JuliaConnectoR\Julia\communicating.jl:185
 [11] (::Main.RConnector.var"#3#5")()
    @ Main.RConnector .\task.jl:484
in expression starting at string:1

jlmerclusterperm_setup(restart = FALSE, verbose = FALSE)
#' @srrstats {G5.0} Uses the built-in `ChickWeight` dataset for tests
weight ~ 1 + Diet, subset(ChickWeight, Time <= 20),
#' @srrstats {G5.5} Uses shared Julia RNG state to test correctness
#' @srrstats {G5.9} Tests for stochastic nature of the CPA under different RNG states
test_that("CPAs under the same RNG state are identical", {
a <- clusterpermute(spec, threshold = 2, progress = FALSE)
b <- clusterpermute(spec, threshold = 2, progress = FALSE)
wholesale <- clusterpermute(spec, threshold = 2, progress = FALSE)
empirical_clusters <- extract_empirical_clusters(empirical_statistics, threshold = 2)
null_cluster_dists <- extract_null_cluster_dists(null_statistics, threshold = 2)
empirical_clusters_tested <- calculate_clusters_pvalues(empirical_clusters, null_cluster_dists, add1 = TRUE)
test_that("Piecemeal and wholesale CPAs are identical", {
test_that("Errors on incompatible clusters", {
expect_error(calculate_clusters_pvalues(extract_empirical_clusters(empirical_statistics, threshold = 3), null_cluster_dists))
expect_error(calculate_clusters_pvalues(extract_empirical_clusters(compute_timewise_statistics(spec, statistic = "chisq"), threshold = .05), null_cluster_dists))
expect_error(calculate_clusters_pvalues(empirical_clusters, extract_null_cluster_dists(null_statistics, threshold = 3)))
weight ~ 1, subset(ChickWeight, Time <= 20),
expect_error(clusterpermute(spec_intercept, threshold = 1.5, nsim = 1), "No predictors to permute")
expect_error(permute_timewise_statistics(spec_intercept, threshold = 1.5, nsim = 1), "No predictors to permute")
lapply(list(empirical_statistics, empirical_clusters, null_statistics, null_cluster_dists, empirical_clusters_tested), tidy)
lapply(list(spec, empirical_statistics, empirical_clusters, null_statistics, null_cluster_dists, empirical_clusters_tested), print)