@@ -5,9 +5,9 @@ def sorted_file_content(file_path)
5
5
end
6
6
7
7
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 ) ) }
11
11
end
12
12
13
13
describe 'Directory File Sorting' do
@@ -16,26 +16,27 @@ def filtered_files(path, filter)
16
16
path : "#{ LKP_SRC } /distro/adaptation" ,
17
17
filter : -> ( filename ) { filename != 'README.md' }
18
18
} ,
19
+
19
20
'adaptation_pkg' => {
20
21
path : "#{ LKP_SRC } /distro/adaptation-pkg"
21
22
} ,
23
+
22
24
'programs' => {
23
25
path : "#{ LKP_SRC } /programs" ,
24
26
filter : -> ( filename ) { filename . start_with? ( 'depends' ) }
25
27
} ,
28
+
26
29
'etc' => {
27
30
path : "#{ LKP_SRC } /etc" ,
28
- filter : -> ( filename ) { filename != 'makepkg.conf' && filename !~ / \. (rb|yml)$/ }
31
+ filter : -> ( filename ) { filename != 'makepkg.conf' }
29
32
}
30
33
}
31
34
32
35
directories . each do |dir_name , config |
33
36
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 ) )
39
40
end
40
41
end
41
42
end
0 commit comments