2020-10-29 01:29:23 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
require('test_helper')
|
|
|
|
require('bootsnap/cli')
|
|
|
|
|
|
|
|
module Bootsnap
|
|
|
|
class CLITest < Minitest::Test
|
|
|
|
include(TmpdirHelper)
|
|
|
|
|
|
|
|
def setup
|
|
|
|
super
|
2020-11-11 16:23:32 +08:00
|
|
|
@cache_dir = File.expand_path('tmp/cache/bootsnap/compile-cache')
|
2020-10-29 01:29:23 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_precompile_single_file
|
|
|
|
path = Help.set_file('a.rb', 'a = a = 3', 100)
|
2021-01-25 23:30:31 +08:00
|
|
|
CompileCache::ISeq.expects(:precompile).with(File.expand_path(path), cache_dir: @cache_dir)
|
2021-01-26 21:33:17 +08:00
|
|
|
assert_equal 0, CLI.new(['precompile', '-j', '0', path]).run
|
2020-10-29 01:29:23 +08:00
|
|
|
end
|
|
|
|
|
2021-01-25 23:30:31 +08:00
|
|
|
def test_no_iseq
|
|
|
|
path = Help.set_file('a.rb', 'a = a = 3', 100)
|
|
|
|
CompileCache::ISeq.expects(:precompile).never
|
2021-01-26 21:33:17 +08:00
|
|
|
assert_equal 0, CLI.new(['precompile', '-j', '0', '--no-iseq', path]).run
|
2021-01-25 23:30:31 +08:00
|
|
|
end
|
|
|
|
|
2020-10-29 01:29:23 +08:00
|
|
|
def test_precompile_directory
|
|
|
|
path_a = Help.set_file('foo/a.rb', 'a = a = 3', 100)
|
|
|
|
path_b = Help.set_file('foo/b.rb', 'b = b = 3', 100)
|
|
|
|
|
2021-01-25 23:30:31 +08:00
|
|
|
CompileCache::ISeq.expects(:precompile).with(File.expand_path(path_a), cache_dir: @cache_dir)
|
|
|
|
CompileCache::ISeq.expects(:precompile).with(File.expand_path(path_b), cache_dir: @cache_dir)
|
2021-01-26 21:33:17 +08:00
|
|
|
assert_equal 0, CLI.new(['precompile', '-j', '0', 'foo']).run
|
2020-10-29 01:29:23 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_precompile_exclude
|
|
|
|
path_a = Help.set_file('foo/a.rb', 'a = a = 3', 100)
|
2020-10-30 22:07:44 +08:00
|
|
|
Help.set_file('foo/b.rb', 'b = b = 3', 100)
|
2020-10-29 01:29:23 +08:00
|
|
|
|
2021-01-25 23:30:31 +08:00
|
|
|
CompileCache::ISeq.expects(:precompile).with(File.expand_path(path_a), cache_dir: @cache_dir)
|
2021-01-26 21:33:17 +08:00
|
|
|
assert_equal 0, CLI.new(['precompile', '-j', '0', '--exclude', 'b.rb', 'foo']).run
|
2020-10-29 01:29:23 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_precompile_gemfile
|
|
|
|
assert_equal 0, CLI.new(['precompile', '--gemfile']).run
|
|
|
|
end
|
2021-01-25 23:30:31 +08:00
|
|
|
|
|
|
|
def test_precompile_yaml
|
|
|
|
path = Help.set_file('a.yaml', 'foo: bar', 100)
|
|
|
|
CompileCache::YAML.expects(:precompile).with(File.expand_path(path), cache_dir: @cache_dir)
|
2021-01-26 21:33:17 +08:00
|
|
|
assert_equal 0, CLI.new(['precompile', '-j', '0', path]).run
|
2021-01-25 23:30:31 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_no_yaml
|
|
|
|
path = Help.set_file('a.yaml', 'foo: bar', 100)
|
|
|
|
CompileCache::YAML.expects(:precompile).never
|
2021-01-26 21:33:17 +08:00
|
|
|
assert_equal 0, CLI.new(['precompile', '-j', '0', '--no-yaml', path]).run
|
2021-01-25 23:30:31 +08:00
|
|
|
end
|
2020-10-29 01:29:23 +08:00
|
|
|
end
|
|
|
|
end
|