diff options
Diffstat (limited to 'spec/util/quick.lua')
-rw-r--r-- | spec/util/quick.lua | 49 |
1 files changed, 25 insertions, 24 deletions
diff --git a/spec/util/quick.lua b/spec/util/quick.lua index 5c49fff9..80c75848 100644 --- a/spec/util/quick.lua +++ b/spec/util/quick.lua | |||
@@ -103,8 +103,8 @@ local function parse(filename) | |||
103 | local value | 103 | local value |
104 | if var == "tmpdir" then | 104 | if var == "tmpdir" then |
105 | value = "%{tmpdir}" | 105 | value = "%{tmpdir}" |
106 | elseif var == "url(tmpdir)" then | 106 | elseif var == "url(%{tmpdir})" then |
107 | value = "%{url(tmpdir)}" | 107 | value = "%{url(%{tmpdir})}" |
108 | elseif fn == "url" then | 108 | elseif fn == "url" then |
109 | value = expand_vars(fnarg) | 109 | value = expand_vars(fnarg) |
110 | value = value:gsub("\\", "/") | 110 | value = value:gsub("\\", "/") |
@@ -187,35 +187,35 @@ local function parse(filename) | |||
187 | elseif cmd == "EXISTS" then | 187 | elseif cmd == "EXISTS" then |
188 | cur_op = { | 188 | cur_op = { |
189 | op = "EXISTS", | 189 | op = "EXISTS", |
190 | file = dir.normalize(arg), | 190 | name = dir.normalize(arg), |
191 | line = cur_line, | 191 | line = cur_line, |
192 | } | 192 | } |
193 | table.insert(cur_test.ops, cur_op) | 193 | table.insert(cur_test.ops, cur_op) |
194 | elseif cmd == "NOT_EXISTS" then | 194 | elseif cmd == "NOT_EXISTS" then |
195 | cur_op = { | 195 | cur_op = { |
196 | op = "NOT_EXISTS", | 196 | op = "NOT_EXISTS", |
197 | file = dir.normalize(arg), | 197 | name = dir.normalize(arg), |
198 | line = cur_line, | 198 | line = cur_line, |
199 | } | 199 | } |
200 | table.insert(cur_test.ops, cur_op) | 200 | table.insert(cur_test.ops, cur_op) |
201 | elseif cmd == "MKDIR" then | 201 | elseif cmd == "MKDIR" then |
202 | cur_op = { | 202 | cur_op = { |
203 | op = "MKDIR", | 203 | op = "MKDIR", |
204 | file = dir.normalize(arg), | 204 | name = dir.normalize(arg), |
205 | line = cur_line, | 205 | line = cur_line, |
206 | } | 206 | } |
207 | table.insert(cur_test.ops, cur_op) | 207 | table.insert(cur_test.ops, cur_op) |
208 | elseif cmd == "RMDIR" then | 208 | elseif cmd == "RMDIR" then |
209 | cur_op = { | 209 | cur_op = { |
210 | op = "RMDIR", | 210 | op = "RMDIR", |
211 | file = dir.normalize(arg), | 211 | name = dir.normalize(arg), |
212 | line = cur_line, | 212 | line = cur_line, |
213 | } | 213 | } |
214 | table.insert(cur_test.ops, cur_op) | 214 | table.insert(cur_test.ops, cur_op) |
215 | elseif cmd == "RM" then | 215 | elseif cmd == "RM" then |
216 | cur_op = { | 216 | cur_op = { |
217 | op = "RM", | 217 | op = "RM", |
218 | file = dir.normalize(arg), | 218 | name = dir.normalize(arg), |
219 | line = cur_line, | 219 | line = cur_line, |
220 | } | 220 | } |
221 | table.insert(cur_test.ops, cur_op) | 221 | table.insert(cur_test.ops, cur_op) |
@@ -347,40 +347,41 @@ function quick.compile(filename, env) | |||
347 | write([=[ return function() ]=]) | 347 | write([=[ return function() ]=]) |
348 | write([=[ test_env.run_in_tmp(function(tmpdir) ]=]) | 348 | write([=[ test_env.run_in_tmp(function(tmpdir) ]=]) |
349 | write([=[ local function handle_tmpdir(s) ]=]) | 349 | write([=[ local function handle_tmpdir(s) ]=]) |
350 | write([=[ return (s:gsub("%%{url%(tmpdir%)}", (tmpdir:gsub("\\", "/"))) ]=]) | 350 | write([=[ return (s:gsub("%%{url%(%%{tmpdir}%)}", (tmpdir:gsub("\\", "/"))) ]=]) |
351 | write([=[ :gsub("%%{tmpdir}", (tmpdir:gsub("[\\/]", dir_sep)))) ]=]) | 351 | write([=[ :gsub("%%{tmpdir}", (tmpdir:gsub("[\\/]", dir_sep)))) ]=]) |
352 | write([=[ end ]=]) | 352 | write([=[ end ]=]) |
353 | write([=[ local ok, err ]=]) | 353 | write([=[ local ok, err ]=]) |
354 | for _, op in ipairs(t.ops) do | 354 | for _, op in ipairs(t.ops) do |
355 | if op.name then | ||
356 | op.name = native_slash(op.name) | ||
357 | write(([=[ local name = handle_tmpdir(%q) ]=]):format(op.name)) | ||
358 | end | ||
355 | if op.op == "FILE" then | 359 | if op.op == "FILE" then |
356 | if op.name:match("[\\/]") then | 360 | if op.name:match("[\\/]") then |
357 | write(([=[ make_dir(%q) ]=]):format(dir.dir_name(op.name))) | 361 | write(([=[ make_dir(handle_tmpdir(%q)) ]=]):format(dir.dir_name(op.name))) |
358 | end | 362 | end |
359 | write(([=[ test_env.write_file(handle_tmpdir(%q), handle_tmpdir([=====[ ]=]):format(op.name)) | 363 | write([=[ test_env.write_file(name, handle_tmpdir([=====[ ]=]) |
360 | for _, line in ipairs(op.data) do | 364 | for _, line in ipairs(op.data) do |
361 | write(line) | 365 | write(line) |
362 | end | 366 | end |
363 | write([=[ ]=====]), finally) ]=]) | 367 | write([=[ ]=====]), finally) ]=]) |
364 | elseif op.op == "EXISTS" then | 368 | elseif op.op == "EXISTS" then |
365 | write(([=[ ok, err = lfs.attributes(%q) ]=]):format(op.file)) | 369 | write(([=[ ok, err = lfs.attributes(name) ]=])) |
366 | write(([=[ assert.truthy(ok, error_message(%d, "EXISTS failed: " .. %q .. " - " .. (err or "") )) ]=]):format(op.line, op.file)) | 370 | write(([=[ assert.truthy(ok, error_message(%d, "EXISTS failed: " .. name .. " - " .. (err or "") )) ]=]):format(op.line)) |
367 | elseif op.op == "NOT_EXISTS" then | 371 | elseif op.op == "NOT_EXISTS" then |
368 | write(([=[ assert.falsy(lfs.attributes(%q), error_message(%d, "NOT_EXISTS failed: " .. %q .. " exists" )) ]=]):format(op.file, op.line, op.file)) | 372 | write(([=[ assert.falsy(lfs.attributes(name), error_message(%d, "NOT_EXISTS failed: " .. name .. " exists" )) ]=]):format(op.line)) |
369 | elseif op.op == "MKDIR" then | 373 | elseif op.op == "MKDIR" then |
370 | op.file = native_slash(op.file) | 374 | write(([=[ ok, err = make_dir(name) ]=])) |
371 | write(([=[ ok, err = make_dir(%q) ]=]):format(op.file)) | 375 | write(([=[ assert.truthy((lfs.attributes(name) or {}).mode == "directory", error_message(%d, "MKDIR failed: " .. name .. " - " .. (err or "") )) ]=]):format(op.line)) |
372 | write(([=[ assert.truthy((lfs.attributes(%q) or {}).mode == "directory", error_message(%d, "MKDIR failed: " .. %q .. " - " .. (err or "") )) ]=]):format(op.file, op.line, op.file)) | ||
373 | elseif op.op == "RMDIR" then | 376 | elseif op.op == "RMDIR" then |
374 | op.file = native_slash(op.file) | 377 | write(([=[ ok, err = test_env.remove_dir(name) ]=])) |
375 | write(([=[ ok, err = test_env.remove_dir(%q) ]=]):format(op.file)) | 378 | write(([=[ assert.falsy((lfs.attributes(name) or {}).mode == "directory", error_message(%d, "MKDIR failed: " .. name .. " - " .. (err or "") )) ]=]):format(op.line)) |
376 | write(([=[ assert.falsy((lfs.attributes(%q) or {}).mode == "directory", error_message(%d, "MKDIR failed: " .. %q .. " - " .. (err or "") )) ]=]):format(op.file, op.line, op.file)) | ||
377 | elseif op.op == "RM" then | 379 | elseif op.op == "RM" then |
378 | op.file = native_slash(op.file) | 380 | write(([=[ ok, err = os.remove(name) ]=])) |
379 | write(([=[ ok, err = os.remove(%q) ]=]):format(op.file)) | 381 | write(([=[ assert.falsy((lfs.attributes(name) or {}).mode == "file", error_message(%d, "RM failed: " .. name .. " - " .. (err or "") )) ]=]):format(op.line)) |
380 | write(([=[ assert.falsy((lfs.attributes(%q) or {}).mode == "file", error_message(%d, "RM failed: " .. %q .. " - " .. (err or "") )) ]=]):format(op.file, op.line, op.file)) | ||
381 | elseif op.op == "FILE_CONTENTS" then | 382 | elseif op.op == "FILE_CONTENTS" then |
382 | write(([=[ do ]=])) | 383 | write(([=[ do ]=])) |
383 | write(([=[ local fd_file = assert(io.open(%q, "rb")) ]=]):format(op.name)) | 384 | write(([=[ local fd_file = assert(io.open(name, "rb")) ]=])) |
384 | write(([=[ local file_data = fd_file:read("*a") ]=])) | 385 | write(([=[ local file_data = fd_file:read("*a") ]=])) |
385 | write(([=[ fd_file:close() ]=])) | 386 | write(([=[ fd_file:close() ]=])) |
386 | write([=[ local block_at = 1 ]=]) | 387 | write([=[ local block_at = 1 ]=]) |
@@ -388,7 +389,7 @@ function quick.compile(filename, env) | |||
388 | for i, line in ipairs(op.data) do | 389 | for i, line in ipairs(op.data) do |
389 | write(([=[ line = %q ]=]):format(line)) | 390 | write(([=[ line = %q ]=]):format(line)) |
390 | write(([=[ s, e = string.find(file_data, line, 1, true) ]=])) | 391 | write(([=[ s, e = string.find(file_data, line, 1, true) ]=])) |
391 | write(([=[ assert(s, error_message(%d, "FILE_CONTENTS %s did not match: " .. line, file_data)) ]=]):format(op.start + i, op.name)) | 392 | write(([=[ assert(s, error_message(%d, "FILE_CONTENTS " .. name .. " did not match: " .. line, file_data)) ]=]):format(op.start + i)) |
392 | write(([=[ block_at = e + 1 ]=]):format(i)) | 393 | write(([=[ block_at = e + 1 ]=]):format(i)) |
393 | end | 394 | end |
394 | write([=[ end ]=]) | 395 | write([=[ end ]=]) |