/
test_helper.rb
114 lines (95 loc) · 2.52 KB
/
test_helper.rb
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
# frozen_string_literal: true
$LOAD_PATH.unshift(File.expand_path('../../lib', __FILE__))
if defined? Warning
if Warning.respond_to?(:[]=)
Warning[:deprecated] = true
end
end
require('bundler/setup')
require('bootsnap')
require('bootsnap/compile_cache/yaml')
require('bootsnap/compile_cache/json')
require('tmpdir')
require('fileutils')
require('minitest/autorun')
require('mocha/minitest')
cache_dir = File.expand_path('../../tmp/bootsnap/compile-cache', __FILE__)
Bootsnap::CompileCache.setup(cache_dir: cache_dir, iseq: true, yaml: false, json: false)
if GC.respond_to?(:verify_compaction_references)
# This method was added in Ruby 3.0.0. Calling it this way asks the GC to
# move objects around, helping to find object movement bugs.
GC.verify_compaction_references(double_heap: true, toward: :empty)
end
module TestHandler
def self.input_to_storage(_i, p)
'neato ' + p
end
def self.storage_to_output(d, _a)
d.upcase
end
def self.input_to_output(_d, _a)
raise('but why tho')
end
end
module NullCache
def self.get(*)
end
def self.set(*)
end
def self.transaction(*)
yield
end
def self.fetch(*)
yield
end
end
module MiniTest
class Test
module Help
class << self
def cache_path(dir, file, args_key = nil)
hash = fnv1a_64(file)
unless args_key.nil?
hash ^= fnv1a_64(args_key)
end
hex = hash.to_s(16).rjust(16, '0')
"#{dir}/#{hex[0..1]}/#{hex[2..-1]}"
end
def fnv1a_64(data)
hash = 0xcbf29ce484222325
data.bytes.each do |byte|
hash = hash ^ byte
hash = (hash * 0x100000001b3) % (2**64)
end
hash
end
def set_file(path, contents, mtime)
FileUtils.mkdir_p(File.dirname(path))
File.write(path, contents)
FileUtils.touch(path, mtime: mtime)
path
end
end
end
end
end
module TmpdirHelper
def setup
super
@prev_dir = Dir.pwd
@tmp_dir = Dir.mktmpdir('bootsnap-test')
Dir.chdir(@tmp_dir)
@prev = Bootsnap::CompileCache::ISeq.cache_dir
Bootsnap::CompileCache::ISeq.cache_dir = @tmp_dir
Bootsnap::CompileCache::YAML.cache_dir = @tmp_dir
Bootsnap::CompileCache::JSON.cache_dir = @tmp_dir
end
def teardown
super
Dir.chdir(@prev_dir)
FileUtils.remove_entry(@tmp_dir)
Bootsnap::CompileCache::ISeq.cache_dir = @prev
Bootsnap::CompileCache::YAML.cache_dir = @prev
Bootsnap::CompileCache::JSON.cache_dir = @prev
end
end