luassert icon indicating copy to clipboard operation
luassert copied to clipboard

assertions for log files

Open Tieske opened this issue 5 years ago • 1 comments

Quite common we need to validate behaviour by checking log files. Some helper assertions would be nice.

Issues:

  • applications don't always restart with clean logs in-between tests; so a start marker would be necessary
  • log file might not exist when start marker is called?
  • assertions for "contains"
  • needs filename where to look
local logfile = require "luassert.logfile"

it("checks a log file", function()
    local log = logfile("./logs/error.log")   -- sets a start marker (file size?), should not fail if file doesn't exist

    -- do stuff 

    assert.logfile(log).exists()
    assert.logfile(log).contains("some Lua pattern", [occurrences])
end)

Tieske avatar Nov 22 '20 21:11 Tieske

not a bad idea! how about just "file" though?

DorianGray avatar Dec 02 '20 02:12 DorianGray