This repository has been archived by the owner on Jul 22, 2023. It is now read-only.
forked from freddi-kit/fastlane
-
Notifications
You must be signed in to change notification settings - Fork 0
/
command_executor_spec.rb
90 lines (70 loc) · 3.01 KB
/
command_executor_spec.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
describe FastlaneCore do
describe FastlaneCore::CommandExecutor do
describe "execute" do
it 'executes a simple command successfully' do
unless FastlaneCore::Helper.windows?
expect(Process).to receive(:wait)
end
result = FastlaneCore::CommandExecutor.execute(command: 'echo foo')
expect(result).to eq('foo')
end
it 'handles reading which throws a EIO exception', requires_pty: true do
explodes_on_strip = 'danger! lasers!'
fake_std_in = ['a_filename', explodes_on_strip]
# In reality the exception is raised by the `each` call, but for easier mocking
# we manually raise the exception when the line is cleaned up with `strip` afterward
expect(explodes_on_strip).to receive(:strip).and_raise(Errno::EIO)
child_process_id = 1
expect(Process).to receive(:wait).with(child_process_id)
# Hacky approach because $? is not be defined since we skip the actual spawn
allow_message_expectations_on_nil
expect($?).to receive(:exitstatus).and_return(0)
# Make a fake child process so we have a valid PID and $? is set correctly
expect(PTY).to receive(:spawn) do |command, &block|
expect(command).to eq('ls')
block.yield(fake_std_in, 'not_really_std_out', child_process_id)
end
result = FastlaneCore::CommandExecutor.execute(command: 'ls')
# We are implicitly also checking that the error was not rethrown because that would
# have crashed the test
expect(result).to eq('a_filename')
end
end
describe "which" do
require 'tempfile'
it "does not find commands which are not on the PATH" do
expect(FastlaneCore::CommandExecutor.which('not_a_real_command')).to be_nil
end
it "finds commands without extensions which are on the PATH" do
Tempfile.open('foobarbaz') do |f|
File.chmod(0777, f)
temp_dir = File.dirname(f)
temp_cmd = File.basename(f)
with_env_values('PATH' => temp_dir) do
expect(FastlaneCore::CommandExecutor.which(temp_cmd)).to eq(f.path)
end
end
end
it "finds commands with known extensions which are on the PATH" do
Tempfile.open(['foobarbaz', '.exe']) do |f|
File.chmod(0777, f)
temp_dir = File.dirname(f)
temp_cmd = File.basename(f, '.exe')
with_env_values('PATH' => temp_dir, 'PATHEXT' => '.exe') do
expect(FastlaneCore::CommandExecutor.which(temp_cmd)).to eq(f.path)
end
end
end
it "does not find commands with unknown extensions which are on the PATH" do
Tempfile.open(['foobarbaz', '.exe']) do |f|
File.chmod(0777, f)
temp_dir = File.dirname(f)
temp_cmd = File.basename(f, '.exe')
with_env_values('PATH' => temp_dir, 'PATHEXT' => '') do
expect(FastlaneCore::CommandExecutor.which(temp_cmd)).to be_nil
end
end
end
end
end
end