Skip to content

Commit d1f326c

Browse files
committed
spec/file_sorting_spec.rb: handle file recursively
Signed-off-by: Philip Li <[email protected]>
1 parent 3dbbe3e commit d1f326c

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

distro/adaptation/amazon_linux/2023

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,4 @@ sg3-utils:
4444
tshark:
4545
update-inetd:
4646
wpasupplicant:
47-
xutils-dev:
47+
xutils-dev:

spec/file_sorting_spec.rb

+10-9
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ def sorted_file_content(file_path)
55
end
66

77
def filtered_files(path, filter)
8-
Dir.entries(path)
9-
.reject { |f| File.symlink?(File.join(path, f)) || File.directory?(File.join(path, f)) || f.start_with?('.') }
10-
.select { |f| filter.nil? || filter.call(f) }
8+
Dir.glob("#{path}/**/*")
9+
.select { |f| File.file?(f) && !File.symlink?(f) && f !~ /\.(rb|yml)$/ }
10+
.select { |f| filter.nil? || filter.call(File.basename(f)) }
1111
end
1212

1313
describe 'Directory File Sorting' do
@@ -16,26 +16,27 @@ def filtered_files(path, filter)
1616
path: "#{LKP_SRC}/distro/adaptation",
1717
filter: ->(filename) { filename != 'README.md' }
1818
},
19+
1920
'adaptation_pkg' => {
2021
path: "#{LKP_SRC}/distro/adaptation-pkg"
2122
},
23+
2224
'programs' => {
2325
path: "#{LKP_SRC}/programs",
2426
filter: ->(filename) { filename.start_with?('depends') }
2527
},
28+
2629
'etc' => {
2730
path: "#{LKP_SRC}/etc",
28-
filter: ->(filename) { filename != 'makepkg.conf' && filename !~ /\.(rb|yml)$/ }
31+
filter: ->(filename) { filename != 'makepkg.conf' }
2932
}
3033
}
3134

3235
directories.each do |dir_name, config|
3336
context "in #{dir_name}" do
34-
filtered_files(config[:path], config[:filter]).each do |filename|
35-
file_path = File.join(config[:path], filename)
36-
37-
it "#{file_path} has sorted content and no duplicates" do
38-
expect(File.read(file_path)).to eq(sorted_file_content(file_path))
37+
filtered_files(config[:path], config[:filter]).each do |file|
38+
it "#{file} has sorted content and no duplicates" do
39+
expect(File.read(file)).to eq(sorted_file_content(file))
3940
end
4041
end
4142
end

0 commit comments

Comments
 (0)