diff options
author | Hisham Muhammad <hisham@gobolinux.org> | 2024-04-05 12:08:48 -0300 |
---|---|---|
committer | Hisham Muhammad <hisham@gobolinux.org> | 2024-04-05 17:32:15 -0300 |
commit | 8c4b4cf98ab1b46b24db3f1c6478bb8d521720e8 (patch) | |
tree | 4174f01d98192576567aaefaf4829fca0564bec4 | |
parent | c16bdbc4cbb98c560fb7e8d4895d4d84afca2eb9 (diff) | |
download | luarocks-8c4b4cf98ab1b46b24db3f1c6478bb8d521720e8.tar.gz luarocks-8c4b4cf98ab1b46b24db3f1c6478bb8d521720e8.tar.bz2 luarocks-8c4b4cf98ab1b46b24db3f1c6478bb8d521720e8.zip |
tests(quick): fix NOT_STDERR test refactoring output checks
-rw-r--r-- | spec/util/quick.lua | 69 |
1 files changed, 23 insertions, 46 deletions
diff --git a/spec/util/quick.lua b/spec/util/quick.lua index b2683ac6..a525aa96 100644 --- a/spec/util/quick.lua +++ b/spec/util/quick.lua | |||
@@ -284,6 +284,25 @@ local function parse(filename) | |||
284 | return tests | 284 | return tests |
285 | end | 285 | end |
286 | 286 | ||
287 | local function check_output(write, block, block_name, data_var) | ||
288 | if block then | ||
289 | local is_positive = not block_name:match("NOT") | ||
290 | local err_msg = is_positive and "did not match" or "did match unwanted output" | ||
291 | |||
292 | write([=[ do ]=]) | ||
293 | write([=[ local block_at = 1 ]=]) | ||
294 | write([=[ local s, e, line, ok ]=]) | ||
295 | for i, line in ipairs(block.data) do | ||
296 | write(([=[ line = %q ]=]):format(line)) | ||
297 | write(([=[ s, e = string.find(%s, line, block_at, true) ]=]):format(data_var)) | ||
298 | write(is_positive and ([=[ ok = s; if e then block_at = e + 1 end ]=]):format(i) | ||
299 | or ([=[ ok = not s ]=])) | ||
300 | write(([=[ assert(ok, error_message(%d, "%s %s: " .. line, %s)) ]=]):format(block.start + i, block_name, err_msg, data_var)) | ||
301 | end | ||
302 | write([=[ end ]=]) | ||
303 | end | ||
304 | end | ||
305 | |||
287 | function quick.compile(filename, env) | 306 | function quick.compile(filename, env) |
288 | local tests = parse(filename) | 307 | local tests = parse(filename) |
289 | 308 | ||
@@ -425,53 +444,11 @@ function quick.compile(filename, env) | |||
425 | write([=[ print() ]=]) | 444 | write([=[ print() ]=]) |
426 | end | 445 | end |
427 | 446 | ||
428 | if op.stdout then | 447 | check_output(write, op.stdout, "STDOUT", "stdout_data") |
429 | write([=[ do ]=]) | 448 | check_output(write, op.stderr, "STDERR", "stderr_data") |
430 | write([=[ local block_at = 1 ]=]) | ||
431 | write([=[ local s, e, line ]=]) | ||
432 | for i, line in ipairs(op.stdout.data) do | ||
433 | write(([=[ line = %q ]=]):format(line)) | ||
434 | write(([=[ s, e = string.find(stdout_data, line, 1, true) ]=])) | ||
435 | write(([=[ assert(s, error_message(%d, "STDOUT did not match: " .. line, stdout_data)) ]=]):format(op.stdout.start + i)) | ||
436 | write(([=[ block_at = e + 1 ]=]):format(i)) | ||
437 | end | ||
438 | write([=[ end ]=]) | ||
439 | end | ||
440 | 449 | ||
441 | if op.not_stdout then | 450 | check_output(write, op.not_stdout, "NOT_STDOUT", "stdout_data") |
442 | write([=[ do ]=]) | 451 | check_output(write, op.not_stderr, "NOT_STDERR", "stderr_data") |
443 | write([=[ local line ]=]) | ||
444 | for i, line in ipairs(op.not_stdout.data) do | ||
445 | write(([=[ line = %q ]=]):format(line)) | ||
446 | write(([=[ s = string.find(stdout_data, line, 1, true) ]=])) | ||
447 | write(([=[ assert(not s, error_message(%d, "NOT_STDOUT did match unwanted output: " .. line, stdout_data)) ]=]):format(op.stdout.start + i)) | ||
448 | end | ||
449 | write([=[ end ]=]) | ||
450 | end | ||
451 | |||
452 | if op.stderr then | ||
453 | write([=[ do ]=]) | ||
454 | write([=[ local block_at = 1 ]=]) | ||
455 | write([=[ local s, e, line ]=]) | ||
456 | for i, line in ipairs(op.stderr.data) do | ||
457 | write(([=[ line = %q ]=]):format(line)) | ||
458 | write(([=[ s, e = string.find(stderr_data, line, block_at, true) ]=])) | ||
459 | write(([=[ assert(s, error_message(%d, "STDERR did not match: " .. line, stderr_data)) ]=]):format(op.stderr.start + i)) | ||
460 | write(([=[ block_at = e + 1 ]=]):format(i)) | ||
461 | end | ||
462 | write([=[ end ]=]) | ||
463 | end | ||
464 | |||
465 | if op.not_stderr then | ||
466 | write([=[ do ]=]) | ||
467 | write([=[ local line ]=]) | ||
468 | for i, line in ipairs(op.not_stderr.data) do | ||
469 | write(([=[ line = %q ]=]):format(line)) | ||
470 | write(([=[ s = string.find(stderr_data, line, block_at, true) ]=])) | ||
471 | write(([=[ assert(not s, error_message(%d, "NOT_STDERR did match unwanted output: " .. line, stderr_data)) ]=]):format(op.not_stderr.start + i)) | ||
472 | end | ||
473 | write([=[ end ]=]) | ||
474 | end | ||
475 | 452 | ||
476 | if op.exit then | 453 | if op.exit then |
477 | write(([=[ assert.same(%d, code, error_message(%d, "EXIT did not match: " .. %d, stderr_data)) ]=]):format(op.exit, op.exit_line, op.exit)) | 454 | write(([=[ assert.same(%d, code, error_message(%d, "EXIT did not match: " .. %d, stderr_data)) ]=]):format(op.exit, op.exit_line, op.exit)) |