2021-02-01 17:43:39 +08:00
|
|
|
# frozen_string_literal: true
|
2022-01-13 17:05:07 +08:00
|
|
|
|
2023-12-14 17:47:17 +08:00
|
|
|
require "test_helper"
|
2021-02-01 17:43:39 +08:00
|
|
|
|
|
|
|
module Bootsnap
|
|
|
|
class SetupTest < Minitest::Test
|
|
|
|
def setup
|
|
|
|
@_old_env = ENV.to_h
|
2022-01-13 17:05:07 +08:00
|
|
|
@tmp_dir = Dir.mktmpdir("bootsnap-test")
|
|
|
|
ENV["BOOTSNAP_CACHE_DIR"] = @tmp_dir
|
2021-02-01 17:43:39 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def teardown
|
|
|
|
ENV.replace(@_old_env)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_default_setup
|
|
|
|
Bootsnap.expects(:setup).with(
|
|
|
|
cache_dir: @tmp_dir,
|
|
|
|
development_mode: true,
|
|
|
|
load_path_cache: true,
|
2022-11-09 08:42:30 +08:00
|
|
|
compile_cache_iseq: true,
|
2021-02-01 17:43:39 +08:00
|
|
|
compile_cache_yaml: true,
|
2021-09-16 17:28:11 +08:00
|
|
|
compile_cache_json: true,
|
2022-11-09 05:49:04 +08:00
|
|
|
ignore_directories: nil,
|
2022-11-24 23:20:57 +08:00
|
|
|
readonly: false,
|
2024-02-02 17:08:07 +08:00
|
|
|
revalidation: false,
|
2021-02-01 17:43:39 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
Bootsnap.default_setup
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_default_setup_with_ENV_not_dev
|
2022-01-13 17:05:07 +08:00
|
|
|
ENV["ENV"] = "something"
|
2021-02-01 17:43:39 +08:00
|
|
|
|
|
|
|
Bootsnap.expects(:setup).with(
|
|
|
|
cache_dir: @tmp_dir,
|
|
|
|
development_mode: false,
|
|
|
|
load_path_cache: true,
|
2022-11-09 08:42:30 +08:00
|
|
|
compile_cache_iseq: true,
|
2021-02-01 17:43:39 +08:00
|
|
|
compile_cache_yaml: true,
|
2021-09-16 17:28:11 +08:00
|
|
|
compile_cache_json: true,
|
2022-11-09 05:49:04 +08:00
|
|
|
ignore_directories: nil,
|
2022-11-24 23:20:57 +08:00
|
|
|
readonly: false,
|
2024-02-02 17:08:07 +08:00
|
|
|
revalidation: false,
|
2021-02-01 17:43:39 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
Bootsnap.default_setup
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_default_setup_with_DISABLE_BOOTSNAP_LOAD_PATH_CACHE
|
2022-01-13 17:05:07 +08:00
|
|
|
ENV["DISABLE_BOOTSNAP_LOAD_PATH_CACHE"] = "something"
|
2021-02-01 17:43:39 +08:00
|
|
|
|
|
|
|
Bootsnap.expects(:setup).with(
|
|
|
|
cache_dir: @tmp_dir,
|
|
|
|
development_mode: true,
|
|
|
|
load_path_cache: false,
|
2022-11-09 08:42:30 +08:00
|
|
|
compile_cache_iseq: true,
|
2021-02-01 17:43:39 +08:00
|
|
|
compile_cache_yaml: true,
|
2021-09-16 17:28:11 +08:00
|
|
|
compile_cache_json: true,
|
2022-11-09 05:49:04 +08:00
|
|
|
ignore_directories: nil,
|
2022-11-24 23:20:57 +08:00
|
|
|
readonly: false,
|
2024-02-02 17:08:07 +08:00
|
|
|
revalidation: false,
|
2021-02-01 17:43:39 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
Bootsnap.default_setup
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_default_setup_with_DISABLE_BOOTSNAP_COMPILE_CACHE
|
2022-01-13 17:05:07 +08:00
|
|
|
ENV["DISABLE_BOOTSNAP_COMPILE_CACHE"] = "something"
|
2021-02-01 17:43:39 +08:00
|
|
|
|
|
|
|
Bootsnap.expects(:setup).with(
|
|
|
|
cache_dir: @tmp_dir,
|
|
|
|
development_mode: true,
|
|
|
|
load_path_cache: true,
|
|
|
|
compile_cache_iseq: false,
|
|
|
|
compile_cache_yaml: false,
|
2021-09-16 17:28:11 +08:00
|
|
|
compile_cache_json: false,
|
2022-11-09 05:49:04 +08:00
|
|
|
ignore_directories: nil,
|
2022-11-24 23:20:57 +08:00
|
|
|
readonly: false,
|
2024-02-02 17:08:07 +08:00
|
|
|
revalidation: false,
|
2021-02-01 17:43:39 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
Bootsnap.default_setup
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_default_setup_with_DISABLE_BOOTSNAP
|
2022-01-13 17:05:07 +08:00
|
|
|
ENV["DISABLE_BOOTSNAP"] = "something"
|
2021-02-01 17:43:39 +08:00
|
|
|
|
|
|
|
Bootsnap.expects(:setup).never
|
|
|
|
Bootsnap.default_setup
|
|
|
|
end
|
2021-02-01 18:41:46 +08:00
|
|
|
|
|
|
|
def test_default_setup_with_BOOTSNAP_LOG
|
2022-01-13 17:05:07 +08:00
|
|
|
ENV["BOOTSNAP_LOG"] = "something"
|
2021-02-01 18:41:46 +08:00
|
|
|
|
|
|
|
Bootsnap.expects(:setup).with(
|
|
|
|
cache_dir: @tmp_dir,
|
|
|
|
development_mode: true,
|
|
|
|
load_path_cache: true,
|
2022-11-09 08:42:30 +08:00
|
|
|
compile_cache_iseq: true,
|
2021-02-01 18:41:46 +08:00
|
|
|
compile_cache_yaml: true,
|
2021-09-16 17:28:11 +08:00
|
|
|
compile_cache_json: true,
|
2022-11-09 05:49:04 +08:00
|
|
|
ignore_directories: nil,
|
2022-11-24 23:20:57 +08:00
|
|
|
readonly: false,
|
2024-02-02 17:08:07 +08:00
|
|
|
revalidation: false,
|
2021-02-01 18:41:46 +08:00
|
|
|
)
|
|
|
|
Bootsnap.expects(:logger=).with($stderr.method(:puts))
|
|
|
|
|
|
|
|
Bootsnap.default_setup
|
|
|
|
end
|
2022-08-11 16:49:21 +08:00
|
|
|
|
2022-11-09 05:49:04 +08:00
|
|
|
def test_default_setup_with_BOOTSNAP_IGNORE_DIRECTORIES
|
|
|
|
ENV["BOOTSNAP_IGNORE_DIRECTORIES"] = "foo,bar"
|
|
|
|
|
|
|
|
Bootsnap.expects(:setup).with(
|
|
|
|
cache_dir: @tmp_dir,
|
|
|
|
development_mode: true,
|
|
|
|
load_path_cache: true,
|
2022-11-09 08:42:30 +08:00
|
|
|
compile_cache_iseq: true,
|
2022-11-09 05:49:04 +08:00
|
|
|
compile_cache_yaml: true,
|
|
|
|
compile_cache_json: true,
|
|
|
|
ignore_directories: %w[foo bar],
|
2022-11-24 23:20:57 +08:00
|
|
|
readonly: false,
|
2024-02-02 17:08:07 +08:00
|
|
|
revalidation: false,
|
|
|
|
)
|
|
|
|
|
|
|
|
Bootsnap.default_setup
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_default_setup_with_BOOTSNAP_READONLY
|
|
|
|
ENV["BOOTSNAP_READONLY"] = "something"
|
|
|
|
|
|
|
|
Bootsnap.expects(:setup).with(
|
|
|
|
cache_dir: @tmp_dir,
|
|
|
|
development_mode: true,
|
|
|
|
load_path_cache: true,
|
|
|
|
compile_cache_iseq: true,
|
|
|
|
compile_cache_yaml: true,
|
|
|
|
compile_cache_json: true,
|
|
|
|
ignore_directories: nil,
|
|
|
|
readonly: true,
|
|
|
|
revalidation: false,
|
|
|
|
)
|
|
|
|
|
|
|
|
Bootsnap.default_setup
|
|
|
|
|
|
|
|
ENV["BOOTSNAP_READONLY"] = "false"
|
|
|
|
|
|
|
|
Bootsnap.expects(:setup).with(
|
|
|
|
cache_dir: @tmp_dir,
|
|
|
|
development_mode: true,
|
|
|
|
load_path_cache: true,
|
|
|
|
compile_cache_iseq: true,
|
|
|
|
compile_cache_yaml: true,
|
|
|
|
compile_cache_json: true,
|
|
|
|
ignore_directories: nil,
|
|
|
|
readonly: false,
|
|
|
|
revalidation: false,
|
2022-11-09 05:49:04 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
Bootsnap.default_setup
|
|
|
|
end
|
|
|
|
|
2022-08-11 16:49:21 +08:00
|
|
|
def test_unload_cache
|
|
|
|
Bootsnap.unload_cache!
|
|
|
|
end
|
2021-02-01 17:43:39 +08:00
|
|
|
end
|
|
|
|
end
|