Skip to content

Commit 8a5b204

Browse files
committed
fix: fix tests failing on Windows for platform-specific reasons
1 parent 19eb327 commit 8a5b204

File tree

12 files changed

+116
-502
lines changed

12 files changed

+116
-502
lines changed

.github/workflows/continuous_integration.yml

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ env:
1515
JRUBY_OPTS: --debug
1616

1717
# Supported platforms / Ruby versions:
18-
# - Ubuntu: MRI (3.1, 3.2, 3.3), TruffleRuby (24), JRuby (9.4)
19-
# - Windows: MRI (3.1), JRuby (9.4)
18+
# - Ubuntu: MRI (3.1, 3.2, 3.3, 3.4), TruffleRuby (24), JRuby (9.4)
19+
# - Windows: MRI (3.1)
2020

2121
jobs:
2222
build:
@@ -25,16 +25,25 @@ jobs:
2525
runs-on: ${{ matrix.operating-system }}
2626
continue-on-error: true
2727

28+
env:
29+
FAIL_ON_LOW_COVERAGE: ${{ matrix.fail_on_low_coverage }}
30+
2831
strategy:
2932
fail-fast: false
3033
matrix:
31-
ruby: ["3.1", "3.2", "3.3", "jruby-9.4", "truffleruby-24"]
34+
ruby: ["3.1", "3.2", "3.3", "3.4"]
3235
operating-system: [ubuntu-latest]
36+
fail_on_low_coverage: [true]
3337
include:
3438
- ruby: "3.1"
3539
operating-system: windows-latest
40+
fail_on_low_coverage: false
3641
- ruby: "jruby-9.4"
37-
operating-system: windows-latest
42+
operating-system: ubuntu-latest
43+
fail_on_low_coverage: false
44+
- ruby: "truffleruby-24"
45+
operating-system: ubuntu-latest
46+
fail_on_low_coverage: false
3847

3948
steps:
4049
- name: Checkout

.github/workflows/experimental_ruby_builds.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ env:
1313

1414
# Experimental platforms / Ruby versions:
1515
# - Ubuntu: MRI (head), TruffleRuby (head), JRuby (head)
16-
# - Windows: MRI (head), JRuby (head)
16+
# - Windows: MRI (head), JRuby (head), JRuby (9.4)
1717

1818
jobs:
1919
build:
@@ -25,17 +25,24 @@ jobs:
2525
strategy:
2626
fail-fast: false
2727
matrix:
28+
fail_on_low_coverage: [true]
2829
include:
2930
- ruby: head
3031
operating-system: ubuntu-latest
3132
- ruby: head
3233
operating-system: windows-latest
3334
- ruby: truffleruby-head
3435
operating-system: ubuntu-latest
36+
fail_on_low_coverage: false
3537
- ruby: jruby-head
3638
operating-system: ubuntu-latest
39+
fail_on_low_coverage: false
40+
- ruby: "jruby-9.4"
41+
operating-system: windows-latest
42+
fail_on_low_coverage: false
3743
- ruby: jruby-head
3844
operating-system: windows-latest
45+
fail_on_low_coverage: false
3946

4047
steps:
4148
- name: Checkout

lib/ruby_git.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
require 'ruby_git/command_line'
44
require 'ruby_git/encoding_normalizer'
55
require 'ruby_git/errors'
6-
require 'ruby_git/file_helpers'
76
require 'ruby_git/git_binary'
87
require 'ruby_git/version'
98
require 'ruby_git/working_tree'

lib/ruby_git/command_line/runner.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ def initialize(env, binary_path, global_options, logger)
147147
#
148148
# This array should be splatted into the parameter list.
149149
#
150-
# @params options_hash [Hash] the options to initialize {RubyGit::CommandLine::Options}
150+
# @param options_hash [Hash] the options to initialize {RubyGit::CommandLine::Options}
151151
#
152152
# @return [RubyGit::CommandLine::Result] the result of the command
153153
#

lib/ruby_git/file_helpers.rb

Lines changed: 0 additions & 70 deletions
This file was deleted.

lib/ruby_git/git_binary.rb

Lines changed: 22 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,33 @@ module RubyGit
88
class GitBinary
99
# Return a new GitBinary object
1010
#
11+
# If the path is a command name, the command is search for in the PATH.
12+
#
13+
# If the path is a relative path, it is expanded to an absolute path relative to
14+
# the current directory.
15+
#
16+
# If the path is an absolute path, it is used as is.
17+
#
1118
# @example
1219
# GitBinary.new
1320
#
14-
def initialize(path = nil)
21+
# @param [String] path the path to the git binary
22+
#
23+
def initialize(path = 'git')
1524
@path = Pathname.new(path) unless path.nil?
1625
end
1726

27+
# @attribute [r] path
28+
#
29+
# The path to the git binary
30+
#
31+
# @example
32+
# error.result #=> #<Pathname:git>
33+
#
34+
# @return [RubyGit::CommandLineResult]
35+
#
36+
attr_reader :path
37+
1838
# Sets the path to the git binary
1939
#
2040
# The given path must point to an executable file or a RuntimeError is raised.
@@ -30,47 +50,7 @@ def initialize(path = nil)
3050
# to an existing executable file.
3151
#
3252
def path=(path)
33-
new_path = Pathname.new(path)
34-
raise "'#{new_path}' does not exist." unless new_path.exist?
35-
raise "'#{new_path}' is not a file." unless new_path.file?
36-
raise "'#{new_path}' is not executable." unless new_path.executable?
37-
38-
@path = new_path
39-
end
40-
41-
# Retrieve the path to the git binary
42-
#
43-
# @example Get the git found on the PATH
44-
# git = RubyGit::GitBinary.new
45-
# git.path
46-
# => #<Pathname:/usr/bin/git>
47-
#
48-
# @return [Pathname] the path to the git binary
49-
#
50-
# @raise [RuntimeError] if path was not set via `path=` and either PATH is not set
51-
# or git was not found on the path.
52-
#
53-
def path
54-
@path || (@path = self.class.default_path)
55-
end
56-
57-
# Get the default path to to a git binary by searching the PATH
58-
#
59-
# @example Find the pathname to `super_git`
60-
# git = RubyGit::GitBinary.new
61-
# git.default_path(basename: 'super_git')
62-
# => #<Pathname:/usr/bin/super_git>
63-
#
64-
# @param [String] basename The basename of the git command
65-
#
66-
# @return [Pathname] the path to the git binary found in the path
67-
#
68-
# @raise [RuntimeError] if either PATH is not set or an executable file
69-
# `basename` was not found on the path.
70-
#
71-
def self.default_path(basename: 'git', path: ENV.fetch('PATH', nil), path_ext: ENV.fetch('PATHEXT', nil))
72-
RubyGit::FileHelpers.which(basename, path:, path_ext:) ||
73-
raise("Could not find '#{basename}' in the PATH.")
53+
@path = Pathname.new(path)
7454
end
7555

7656
# The version of git referred to by the path

spec/lib/ruby_git/command_line/result_spec.rb

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,21 @@
1111

1212
describe '#stdout' do
1313
it 'should return the stdout' do
14-
expect(result.stdout.gsub("\r\n", "\n")).to eq("stdout message\n")
14+
expect(result.stdout.with_linux_eol).to eq("stdout message\n")
1515
end
1616

1717
context 'when #process_stdout has been called' do
1818
it 'should return the value returned from #process_stdout' do
1919
result.process_stdout { |s, _r| s.upcase! }
20-
expect(result.stdout).to eq("STDOUT MESSAGE\n")
20+
expect(result.stdout.with_linux_eol).to eq("STDOUT MESSAGE\n")
2121
end
2222
end
2323

2424
context 'when #process_stdout has been called multiple times' do
2525
it 'should return the value returned from the last #process_stdout' do
26-
result.process_stdout { |s, _r| s.upcase! }
26+
result.process_stdout { |s, _r| s.chomp!.upcase! }
2727
result.process_stdout { |s, _r| s.reverse! }
28-
expect(result.stdout).to eq("\nEGASSEM TUODTS")
28+
expect(result.stdout.with_linux_eol).to eq('EGASSEM TUODTS')
2929
end
3030
end
3131
end
@@ -40,49 +40,49 @@
4040
end
4141

4242
it 'should yield to the given block with the stdout and self' do
43-
expect { |b| result.process_stdout(&b) }.to yield_with_args("stdout message\n", result)
43+
expect { |b| result.process_stdout(&b) }.to yield_with_args("stdout message#{eol}", result)
4444
end
4545

4646
context 'when called multiple times' do
4747
it 'should yield most recent value returned from #process_stdout' do
4848
result.process_stdout { |s, _r| s.upcase! }
49-
expect { |b| result.process_stdout(&b) }.to yield_with_args("STDOUT MESSAGE\n", result)
49+
expect { |b| result.process_stdout(&b) }.to yield_with_args("STDOUT MESSAGE#{eol}", result)
5050
end
5151
end
5252
end
5353

5454
describe '#unprocessed_stdout' do
5555
context 'when #process_stdout HAS NOT been called' do
5656
it 'should return stdout' do
57-
expect(result.unprocessed_stdout).to eq("stdout message\n")
57+
expect(result.unprocessed_stdout).to eq("stdout message#{eol}")
5858
end
5959
end
6060

6161
context 'when #process_stdout HAS been called' do
6262
it 'should return the original stdout' do
6363
result.process_stdout { |s, _r| s.upcase! }
64-
expect(result.unprocessed_stdout).to eq("stdout message\n")
64+
expect(result.unprocessed_stdout).to eq("stdout message#{eol}")
6565
end
6666
end
6767
end
6868

6969
describe '#stderr' do
7070
it 'should return the stderr' do
71-
expect(result.stderr.gsub("\r\n", "\n")).to eq("stderr message\n")
71+
expect(result.stderr.with_linux_eol).to eq("stderr message\n")
7272
end
7373

7474
context 'when #process_stderr has been called' do
7575
it 'should return the value returned from #process_stderr' do
7676
result.process_stderr { |s, _r| s.upcase! }
77-
expect(result.stderr).to eq("STDERR MESSAGE\n")
77+
expect(result.stderr.with_linux_eol).to eq("STDERR MESSAGE\n")
7878
end
7979
end
8080

8181
context 'when #process_stderr has been called multiple times' do
8282
it 'should return the value returned from the last #process_stderr' do
83-
result.process_stderr { |s, _r| s.upcase! }
83+
result.process_stderr { |s, _r| s.chomp!.upcase! }
8484
result.process_stderr { |s, _r| s.reverse! }
85-
expect(result.stderr).to eq("\nEGASSEM RREDTS")
85+
expect(result.stderr.with_linux_eol).to eq('EGASSEM RREDTS')
8686
end
8787
end
8888
end
@@ -97,14 +97,14 @@
9797
end
9898

9999
it 'should yield to the given block with the stderr and self' do
100-
expect { |b| result.process_stderr(&b) }.to yield_with_args("stderr message\n", result)
100+
expect { |b| result.process_stderr(&b) }.to yield_with_args("stderr message#{eol}", result)
101101
end
102102

103103
context 'when called multiple times' do
104104
context 'on the last time it is called' do
105105
it 'should yield most recent value returned from #process_stderr' do
106106
result.process_stderr { |s, _r| s.upcase! }
107-
expect { |b| result.process_stderr(&b) }.to yield_with_args("STDERR MESSAGE\n", result)
107+
expect { |b| result.process_stderr(&b) }.to yield_with_args("STDERR MESSAGE#{eol}", result)
108108
end
109109
end
110110
end
@@ -113,14 +113,14 @@
113113
describe '#unprocessed_stderr' do
114114
context 'when #process_stderr HAS NOT been called' do
115115
it 'should return stderr' do
116-
expect(result.unprocessed_stderr).to eq("stderr message\n")
116+
expect(result.unprocessed_stderr.with_linux_eol).to eq("stderr message\n")
117117
end
118118
end
119119

120120
context 'when #process_stderr HAS been called' do
121121
it 'should return the original stderr' do
122122
result.process_stderr { |s, _r| s.upcase! }
123-
expect(result.unprocessed_stderr).to eq("stderr message\n")
123+
expect(result.unprocessed_stderr.with_linux_eol).to eq("stderr message\n")
124124
end
125125
end
126126
end

0 commit comments

Comments
 (0)