Skip to content

Commit 6d13a32

Browse files
committed
Test command with env
1 parent bffaadd commit 6d13a32

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

tests/units/test_merge.rb

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,30 @@ def env
7474
end
7575

7676
def env_var(name)
77+
windows_platform? ? "%#{name}%" : "$#{name}"
78+
end
7779

80+
def windows_platform?
81+
# Check if on Windows via RUBY_PLATFORM (CRuby) and RUBY_DESCRIPTION (JRuby)
82+
win_platform_regex = /mingw|mswin/
83+
RUBY_PLATFORM =~ win_platform_regex || RUBY_DESCRIPTION =~ win_platform_regex
7884
end
85+
7986
def command(cmd)
87+
puts '-' * 80
88+
puts "Running: #{cmd}"
89+
puts '-' * 10
90+
output, status = Open3.capture2e("#{cmd} 2>&1")
91+
puts output
92+
puts '-' * 10
93+
pp status
94+
puts '-' * 80
95+
puts
96+
97+
exit 1 unless status.success?
98+
end
99+
100+
def command_with_env(env, cmd)
80101
puts '-' * 80
81102
puts "Running: #{cmd}"
82103
puts '-' * 10
@@ -106,7 +127,10 @@ def work_tree
106127
end
107128

108129
def test_command_with_env
109-
130+
command_with_env(
131+
{ 'PATH' => 'testing' },
132+
%Q(echo "#{env_var('PATH')}" 2>&1)
133+
)
110134
end
111135

112136
def test_octopus_merge

0 commit comments

Comments
 (0)