Testing by Assertions
String Check
Check whether a string contains required text.
substring assertion
`string.find` returns a position when the required text is present and `nil` when it is missing.
String Check
string_check.lua
Replay: real traced execution (multi-file project)
local text = "trace log"
local found = string.find(text, "trace") ~= nil
local status = "fail"
if found then
status = "pass"
end
print("text=" .. text)
print("status=" .. status)
local text = "debug log"
local found = string.find(text, "trace") ~= nil
local status = "fail"
if found then
status = "pass"
end
print("text=" .. text)
print("status=" .. status)
local text = "trace event"
local found = string.find(text, "trace") ~= nil
local status = "fail"
if found then
status = "pass"
end
print("text=" .. text)
print("status=" .. status)
text ← trace log, found ← true, status ← fail
1local text→ trace log = "trace log" --@text="debug log", "trace event"2local found→ true = string.find(texttrace log, "trace") ~= nil3local status→ fail = "fail"4if found thenstatus ← pass
3local status = "fail"4if foundtrue then5 status→ pass = "pass"6endprint("text=" .. text)
6end7print("text=" .. texttrace log)8print("status=" .. statuspass)outputtext=trace log status=pass
text ← debug log, found ← false, status ← fail
1local text→ debug log = "debug log"2local found→ false = string.find(textdebug log, "trace") ~= nil3local status→ fail = "fail"4if found then5 status = "pass"6end7print("text=" .. textdebug log)8print("status=" .. statusfail)outputtext=debug log status=fail
text ← trace event, found ← true, status ← fail
1local text→ trace event = "trace event"2local found→ true = string.find(texttrace event, "trace") ~= nil3local status→ fail = "fail"4if found thenstatus ← pass
3local status = "fail"4if foundtrue then5 status→ pass = "pass"6endprint("text=" .. text)
6end7print("text=" .. texttrace event)8print("status=" .. statuspass)outputtext=trace event status=pass