Skip to content

Commit 369807e

Browse files
committed
feat: APPMAP_AUTOREQUIRE and APPMAP_INITIALIZE env vars to customize loading behavior
1 parent 890ea0a commit 369807e

File tree

3 files changed

+21
-6
lines changed

3 files changed

+21
-6
lines changed

lib/appmap.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,6 @@
7474
require 'appmap/depends'
7575
end
7676

77-
end.call
77+
end.call unless ENV['APPMAP_AUTOREQUIRE'] == 'false'
7878

79-
AppMap.initialize_configuration if ENV['APPMAP'] == 'true'
79+
AppMap.initialize_configuration if ENV['APPMAP'] == 'true' && ENV['APPMAP_INITIALIZE'] != 'false'

test/fixtures/mocha_mock_app/test/sheep_test.rb

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
$LOAD_PATH.unshift File.expand_path('../lib', __dir__)
22

3-
require 'appmap/minitest'
3+
require 'minitest/autorun'
4+
5+
require 'appmap'
6+
require 'appmap/minitest' if ENV['APPMAP_AUTOREQUIRE'] == 'false'
47

58
require 'sheep'
6-
require 'minitest/autorun'
79
require 'mocha/minitest'
810

911
class SheepTest < Minitest::Test

test/mock_compatibility_test.rb

+15-2
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
require 'test_helper'
55

66
class MockCompatibilityTest < Minitest::Test
7-
def perform_minitest_test(test_name)
7+
def perform_minitest_test(test_name, env = {})
88
Bundler.with_clean_env do
99
Dir.chdir 'test/fixtures/mocha_mock_app' do
1010
FileUtils.rm_rf 'tmp'
1111
system 'bundle config --local local.appmap ../../..'
1212
system 'bundle'
13-
system({ 'APPMAP' => 'true' }, %(bundle exec ruby -Ilib -Itest test/#{test_name}_test.rb))
13+
system(env.merge({ 'APPMAP' => 'true' }), %(bundle exec ruby -Ilib -Itest test/#{test_name}_test.rb))
1414

1515
yield
1616
end
@@ -29,4 +29,17 @@ def test_expectation
2929
assert_equal 'succeeded', metadata['test_status']
3030
end
3131
end
32+
33+
def test_expectation_without_autorequire
34+
perform_minitest_test('sheep', 'APPMAP_AUTOREQUIRE' => 'false') do
35+
appmap_file = 'tmp/appmap/minitest/Sheep_sheep.appmap.json'
36+
37+
assert File.file?(appmap_file), 'appmap output file does not exist'
38+
appmap = JSON.parse(File.read(appmap_file))
39+
assert_equal AppMap::APPMAP_FORMAT_VERSION, appmap['version']
40+
assert_includes appmap.keys, 'metadata'
41+
metadata = appmap['metadata']
42+
assert_equal 'succeeded', metadata['test_status']
43+
end
44+
end
3245
end

0 commit comments

Comments
 (0)