1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175
|
# frozen_string_literal: true
require "test_helper"
module Bootsnap
class SetupTest < Minitest::Test
def setup
@_old_env = ENV.to_h
@tmp_dir = Dir.mktmpdir("bootsnap-test")
ENV["BOOTSNAP_CACHE_DIR"] = @tmp_dir
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,
compile_cache_iseq: true,
compile_cache_yaml: true,
ignore_directories: nil,
readonly: false,
revalidation: false,
)
Bootsnap.default_setup
end
def test_default_setup_with_ENV_not_dev
ENV["ENV"] = "something"
Bootsnap.expects(:setup).with(
cache_dir: @tmp_dir,
development_mode: false,
load_path_cache: true,
compile_cache_iseq: true,
compile_cache_yaml: true,
ignore_directories: nil,
readonly: false,
revalidation: false,
)
Bootsnap.default_setup
end
def test_default_setup_with_DISABLE_BOOTSNAP_LOAD_PATH_CACHE
ENV["DISABLE_BOOTSNAP_LOAD_PATH_CACHE"] = "something"
Bootsnap.expects(:setup).with(
cache_dir: @tmp_dir,
development_mode: true,
load_path_cache: false,
compile_cache_iseq: true,
compile_cache_yaml: true,
ignore_directories: nil,
readonly: false,
revalidation: false,
)
Bootsnap.default_setup
end
def test_default_setup_with_DISABLE_BOOTSNAP_COMPILE_CACHE
ENV["DISABLE_BOOTSNAP_COMPILE_CACHE"] = "something"
Bootsnap.expects(:setup).with(
cache_dir: @tmp_dir,
development_mode: true,
load_path_cache: true,
compile_cache_iseq: false,
compile_cache_yaml: false,
ignore_directories: nil,
readonly: false,
revalidation: false,
)
Bootsnap.default_setup
end
def test_default_setup_with_DISABLE_BOOTSNAP
ENV["DISABLE_BOOTSNAP"] = "something"
Bootsnap.expects(:setup).never
Bootsnap.default_setup
end
def test_default_setup_with_BOOTSNAP_LOG
ENV["BOOTSNAP_LOG"] = "something"
Bootsnap.expects(:setup).with(
cache_dir: @tmp_dir,
development_mode: true,
load_path_cache: true,
compile_cache_iseq: true,
compile_cache_yaml: true,
ignore_directories: nil,
readonly: false,
revalidation: false,
)
Bootsnap.expects(:logger=).with($stderr.method(:puts))
Bootsnap.default_setup
end
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,
compile_cache_iseq: true,
compile_cache_yaml: true,
ignore_directories: %w[foo bar],
readonly: false,
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,
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,
ignore_directories: nil,
readonly: false,
revalidation: false,
)
Bootsnap.default_setup
end
def test_setup_appends_bootsnap_to_cache_dir
skip("Need a working Process.fork to test in isolation") unless Process.respond_to?(:fork)
pid = fork do
Bootsnap.setup(cache_dir: @tmp_dir)
assert_equal("#{@tmp_dir}/bootsnap", Bootsnap.cache_dir)
end
_, status = Process.waitpid2(pid)
assert_predicate status, :success?
ensure
Bootsnap.unload_cache!
end
def test_unload_cache
Bootsnap.unload_cache!
end
end
end
|