Skip to content

Commit eab3bae

Browse files
committed
Convert ci_config to use pathname
1 parent 0f47a7e commit eab3bae

File tree

3 files changed

+11
-9
lines changed

3 files changed

+11
-9
lines changed

Diff for: CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1010
- C++ definitions of `ARDUINO_CI_COMPILATION_MOCKS` and `ARDUINO_CI_GODMODE` to aid in compilation macros
1111

1212
### Changed
13+
- `CIConfig` now uses `Pathname` instead of strings
1314

1415
### Deprecated
1516

Diff for: lib/arduino_ci/ci_config.rb

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
require 'yaml'
2+
require 'pathname'
23

34
# base config (platforms)
45
# project config - .arduino_ci_platforms.yml
@@ -58,7 +59,7 @@ class << self
5859
def default
5960
ret = new
6061
ret.instance_variable_set("@is_default", true)
61-
ret.load_yaml(File.expand_path("../../misc/default.yml", __dir__))
62+
ret.load_yaml((Pathname.new(__dir__) + ("../../misc/default.yml")).realpath)
6263
ret
6364
end
6465
end
@@ -205,8 +206,8 @@ def with_override_config(config_hash)
205206
# @return [ArduinoCI::CIConfig]
206207
def with_config(base_dir, val_when_no_match)
207208
CONFIG_FILENAMES.each do |f|
208-
path = base_dir.nil? ? f : File.join(base_dir, f)
209-
return (yield path) if File.exist?(path)
209+
path = base_dir.nil? ? Pathname.new(f) : base_dir + f
210+
return (yield path) if path.exist?
210211
end
211212
val_when_no_match
212213
end
@@ -219,10 +220,10 @@ def from_project_library
219220

220221
# Produce a configuration override taken from an Arduino library example path
221222
# handle either path to example file or example dir
222-
# @param path [String] the path to the settings yaml file
223+
# @param path [Pathname] the path to the settings yaml file
223224
# @return [ArduinoCI::CIConfig] the new settings object
224225
def from_example(example_path)
225-
base_dir = File.directory?(example_path) ? example_path : File.dirname(example_path)
226+
base_dir = example_path.directory? ? example_path : example_path.dirname
226227
with_config(base_dir, self) { |path| with_override(path) }
227228
end
228229

Diff for: spec/ci_config_spec.rb

+4-4
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
context "hash" do
4444
it "converts to hash" do
4545
base = ArduinoCI::CIConfig.new
46-
base.load_yaml(File.join(File.dirname(__FILE__), "yaml", "o2.yaml"))
46+
base.load_yaml(Pathname.new(__dir__) + "yaml" + "o2.yaml")
4747

4848
expect(base.to_h).to eq(
4949
packages: {},
@@ -82,7 +82,7 @@
8282

8383
context "with_override" do
8484
it "loads from yaml" do
85-
override_file = File.join(File.dirname(__FILE__), "yaml", "o1.yaml")
85+
override_file = Pathname.new(__dir__) + "yaml" + "o1.yaml"
8686
base = ArduinoCI::CIConfig.default
8787
expect(base.is_default).to be true
8888
combined_config = base.with_override(override_file)
@@ -123,7 +123,7 @@
123123

124124
context "with_config" do
125125
it "loads from yaml" do
126-
override_dir = File.join(File.dirname(__FILE__), "yaml", "override1")
126+
override_dir = Pathname.new(__dir__) + "yaml" + "override1"
127127
base_config = ArduinoCI::CIConfig.default
128128
combined_config = base_config.from_example(override_dir)
129129

@@ -188,7 +188,7 @@
188188
"mars.cpp"
189189
])
190190

191-
override_file = File.join(File.dirname(__FILE__), "yaml", "o1.yaml")
191+
override_file = Pathname.new(__dir__) + "yaml" + "o1.yaml"
192192
combined_config = ArduinoCI::CIConfig.default.with_override(override_file)
193193
expect(combined_config.unittest_info[:testfiles][:select]).to match_array(["*-*.*"])
194194
expect(combined_config.unittest_info[:testfiles][:reject]).to match_array(["sam-squamsh.*"])

0 commit comments

Comments
 (0)