aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorPeter Melnichenko <mpeterval@gmail.com>2016-07-08 16:09:05 +0300
committerPeter Melnichenko <mpeterval@gmail.com>2016-07-08 16:09:55 +0300
commit1097d6cbc877b22b343b4f4531ce0a1d3b286307 (patch)
treefa9ba55f72bb976bf94795442d7a6cb30366fe3b /test
parentb57ce08dce1efa471bc1ae5fad2f154bae426f75 (diff)
downloadluarocks-1097d6cbc877b22b343b4f4531ce0a1d3b286307.tar.gz
luarocks-1097d6cbc877b22b343b4f4531ce0a1d3b286307.tar.bz2
luarocks-1097d6cbc877b22b343b4f4531ce0a1d3b286307.zip
Tests: adjust file/dir removing functions
Diffstat (limited to 'test')
-rw-r--r--test/test_environment.lua22
1 files changed, 9 insertions, 13 deletions
diff --git a/test/test_environment.lua b/test/test_environment.lua
index 94acf1c8..4f684f0a 100644
--- a/test/test_environment.lua
+++ b/test/test_environment.lua
@@ -122,11 +122,9 @@ function test_env.remove_dir(path)
122 for file in lfs.dir(path) do 122 for file in lfs.dir(path) do
123 if file ~= "." and file ~= ".." then 123 if file ~= "." and file ~= ".." then
124 local full_path = path..'/'..file 124 local full_path = path..'/'..file
125 local attr = lfs.attributes(full_path)
126 125
127 if attr.mode == "directory" then 126 if lfs.attributes(full_path, "mode") == "directory" then
128 test_env.remove_dir(full_path) 127 test_env.remove_dir(full_path)
129 os.remove(full_path)
130 else 128 else
131 os.remove(full_path) 129 os.remove(full_path)
132 end 130 end
@@ -136,28 +134,26 @@ function test_env.remove_dir(path)
136 os.remove(path) 134 os.remove(path)
137end 135end
138 136
139--- Remove directory recursively 137--- Remove subdirectories of a directory that match a pattern
140-- @param path string: directory path to delete 138-- @param path string: path to directory
141-- @param pattern string: pattern in directories 139-- @param pattern string: pattern matching basenames of subdirectories to be removed
142function test_env.remove_dir_pattern(path, pattern) 140function test_env.remove_subdirs(path, pattern)
143 if lfs.attributes(path) then 141 if lfs.attributes(path) then
144 for file in lfs.dir(path) do 142 for file in lfs.dir(path) do
145 if file ~= "." and file ~= ".." then 143 if file ~= "." and file ~= ".." then
146 local full_path = path..'/'..file 144 local full_path = path..'/'..file
147 local attr = lfs.attributes(full_path)
148 145
149 if attr.mode == "directory" and file:find(pattern) then 146 if lfs.attributes(full_path, "mode") == "directory" and file:find(pattern) then
150 test_env.remove_dir(full_path) 147 test_env.remove_dir(full_path)
151 os.remove(full_path)
152 end 148 end
153 end 149 end
154 end 150 end
155 end 151 end
156end 152end
157 153
158--- Remove files based on filename 154--- Remove files matching a pattern
159-- @param path string: directory where to delete files 155-- @param path string: directory where to delete files
160-- @param pattern string: pattern in filenames 156-- @param pattern string: pattern matching basenames of files to be deleted
161-- @return result_check boolean: true if one or more files deleted 157-- @return result_check boolean: true if one or more files deleted
162function test_env.remove_files(path, pattern) 158function test_env.remove_files(path, pattern)
163 local result_check = false 159 local result_check = false
@@ -535,7 +531,7 @@ end
535local function clean() 531local function clean()
536 print("Cleaning testing directory...") 532 print("Cleaning testing directory...")
537 test_env.remove_dir(test_env.testing_paths.luarocks_tmp) 533 test_env.remove_dir(test_env.testing_paths.luarocks_tmp)
538 test_env.remove_dir_pattern(test_env.testing_paths.testing_dir, "testing[_%-]") 534 test_env.remove_subdirs(test_env.testing_paths.testing_dir, "testing[_%-]")
539 test_env.remove_files(test_env.testing_paths.testing_dir, "testing_") 535 test_env.remove_files(test_env.testing_paths.testing_dir, "testing_")
540 test_env.remove_files(test_env.testing_paths.testing_dir, "luacov") 536 test_env.remove_files(test_env.testing_paths.testing_dir, "luacov")
541 print("Cleaning done!") 537 print("Cleaning done!")