mirror of
https://github.com/pnx/neotest-phpunit
synced 2026-06-16 03:54:55 +02:00
Get better short message output
This commit is contained in:
parent
a6351e49a4
commit
e09c38cc51
3 changed files with 54 additions and 100 deletions
|
|
@ -36,18 +36,24 @@ end
|
|||
|
||||
---Extract the failure messages from the tests
|
||||
---@param tests table,
|
||||
---@return boolean|table
|
||||
---@return boolean,table,table
|
||||
local function errors_or_fails(tests)
|
||||
local errors_fails = {}
|
||||
local failed = false
|
||||
local errors = {}
|
||||
local fails = {}
|
||||
|
||||
iterate_key(tests, "error", errors_fails)
|
||||
iterate_key(tests, "failure", errors_fails)
|
||||
iterate_key(tests, "error", errors)
|
||||
iterate_key(tests, "failure", fails)
|
||||
|
||||
if #errors_fails == 0 then
|
||||
return false
|
||||
if #errors > 0 or #fails > 0 then
|
||||
failed = true
|
||||
end
|
||||
|
||||
return errors_fails
|
||||
return failed, errors, fails
|
||||
end
|
||||
|
||||
local function make_short_output(test_attr, status)
|
||||
return string.upper(status) .. " | " .. test_attr.name
|
||||
end
|
||||
|
||||
---Make the outputs for a given test
|
||||
|
|
@ -64,23 +70,37 @@ local function make_outputs(test, output_file)
|
|||
|
||||
local test_output = {
|
||||
status = "passed",
|
||||
short = string.upper(test_attr.classname) .. "\n-> " .. "PASSED" .. " - " .. test_attr.name,
|
||||
short = make_short_output(test_attr, "passed"),
|
||||
output_file = output_file,
|
||||
}
|
||||
|
||||
local test_failed = errors_or_fails(test)
|
||||
logger.info("test_failed:", test_failed)
|
||||
local test_failed, errors, fails = errors_or_fails(test)
|
||||
|
||||
if test_failed then
|
||||
logger.info("test_failed:", { test_failed, errors, fails })
|
||||
test_output.status = "failed"
|
||||
test_output.short = test_failed[1]["failure"] or test_failed[1]["errors"]
|
||||
test_output.errors = {
|
||||
{
|
||||
line = test_attr.line,
|
||||
},
|
||||
}
|
||||
|
||||
if #errors > 0 then
|
||||
local message = errors[1][1]
|
||||
test_output.short = make_short_output(test_attr, "error") .. "\n\n" .. message
|
||||
test_output.errors = {
|
||||
{
|
||||
message = message
|
||||
},
|
||||
}
|
||||
elseif #fails > 0 then
|
||||
local message = fails[1][1]
|
||||
test_output.short = make_short_output(test_attr, "failed") .. "\n\n" .. message
|
||||
test_output.errors = {
|
||||
{
|
||||
message = message
|
||||
}
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
logger.debug("test_output:", test_output)
|
||||
|
||||
return test_id, test_output
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -217,127 +217,57 @@ describe("get_test_results", function()
|
|||
assert.are.same(utils.get_test_results(xml_output, output_file), expected)
|
||||
end)
|
||||
|
||||
it('parses output with a failing test', function()
|
||||
it('parses output with a single failing test', function()
|
||||
local xml_output = {
|
||||
testsuites = {
|
||||
testsuite = {
|
||||
_attr = {
|
||||
assertions = "16",
|
||||
assertions = "1",
|
||||
errors = "0",
|
||||
failures = "1",
|
||||
name = "/Users/michaelutz/Code/neotest-pest/tests/Feature/UserTest.php",
|
||||
name = "",
|
||||
skipped = "0",
|
||||
tests = "6",
|
||||
time = "0.007869",
|
||||
tests = "1",
|
||||
time = "0.004215",
|
||||
warnings = "0"
|
||||
},
|
||||
testsuite = {
|
||||
_attr = {
|
||||
assertions = "16",
|
||||
assertions = "1",
|
||||
errors = "0",
|
||||
failures = "1",
|
||||
file = "/Users/michaelutz/Code/neotest-pest/tests/Feature/UserTest.php",
|
||||
name = "P\\Tests\\Feature\\UserTest",
|
||||
skipped = "0",
|
||||
tests = "6",
|
||||
time = "0.007869",
|
||||
tests = "1",
|
||||
time = "0.004215",
|
||||
warnings = "0"
|
||||
},
|
||||
testcase = { {
|
||||
_attr = {
|
||||
assertions = "3",
|
||||
class = "Tests\\Feature\\UserTest",
|
||||
classname = "Tests.Feature.UserTest",
|
||||
file = "/Users/michaelutz/Code/neotest-pest/tests/Feature/UserTest.php",
|
||||
name = "class constructor",
|
||||
time = "0.003293"
|
||||
}
|
||||
}, {
|
||||
_attr = {
|
||||
assertions = "2",
|
||||
class = "Tests\\Feature\\UserTest",
|
||||
classname = "Tests.Feature.UserTest",
|
||||
file = "/Users/michaelutz/Code/neotest-pest/tests/Feature/UserTest.php",
|
||||
name = "tellName",
|
||||
time = "0.000584"
|
||||
}
|
||||
}, {
|
||||
_attr = {
|
||||
assertions = "2",
|
||||
class = "Tests\\Feature\\UserTest",
|
||||
classname = "Tests.Feature.UserTest",
|
||||
file = "/Users/michaelutz/Code/neotest-pest/tests/Feature/UserTest.php",
|
||||
name = "can tellAge",
|
||||
time = "0.000396"
|
||||
}
|
||||
}, {
|
||||
testcase = {
|
||||
_attr = {
|
||||
assertions = "1",
|
||||
class = "Tests\\Feature\\UserTest",
|
||||
classname = "Tests.Feature.UserTest",
|
||||
file = "/Users/michaelutz/Code/neotest-pest/tests/Feature/UserTest.php",
|
||||
name = "is false",
|
||||
time = "0.001134"
|
||||
time = "0.004215"
|
||||
},
|
||||
failure = { "/Users/michaelutz/Code/neotest-pest/tests/Feature/UserTest.php::it is false\nFailed asserting that true is false.\n\n/Users/michaelutz/Code/neotest-pest/tests/Feature/UserTest.php:33\n/Users/michaelutz/Code/neotest-pest/vendor/pestphp/pest/src/Expectation.php:316\n/Users/michaelutz/Code/neotest-pest/vendor/pestphp/pest/src/Support/Reflection.php:38\n/Users/michaelutz/Code/neotest-pest/vendor/pestphp/pest/src/Support/HigherOrderMessage.php:96\n/Users/michaelutz/Code/neotest-pest/vendor/pestphp/pest/src/Support/HigherOrderMessageCollection.php:43\n/Users/michaelutz/Code/neotest-pest/vendor/pestphp/pest/src/Factories/TestCaseFactory.php:148\n/Users/michaelutz/Code/neotest-pest/vendor/pestphp/pest/src/Concerns/Testable.php:302\n/Users/michaelutz/Code/neotest-pest/vendor/pestphp/pest/src/Support/ExceptionTrace.php:29\n/Users/michaelutz/Code/neotest-pest/vendor/pestphp/pest/src/Concerns/Testable.php:303\n/Users/michaelutz/Code/neotest-pest/vendor/pestphp/pest/src/Concerns/Testable.php:279\n/Users/michaelutz/Code/neotest-pest/vendor/pestphp/pest/src/Console/Command.php:119\n/Users/michaelutz/Code/neotest-pest/vendor/pestphp/pest/bin/pest:62\n/Users/michaelutz/Code/neotest-pest/vendor/pestphp/pest/bin/pest:63",
|
||||
failure = { "/Users/michaelutz/Code/neotest-pest/tests/Feature/UserTest.php::it is false\nFailed asserting that true is false.\n\n/Users/michaelutz/Code/neotest-pest/tests/Feature/UserTest.php:35\n/Users/michaelutz/Code/neotest-pest/vendor/pestphp/pest/src/Expectation.php:316\n/Users/michaelutz/Code/neotest-pest/vendor/pestphp/pest/src/Support/Reflection.php:38\n/Users/michaelutz/Code/neotest-pest/vendor/pestphp/pest/src/Support/HigherOrderMessage.php:96\n/Users/michaelutz/Code/neotest-pest/vendor/pestphp/pest/src/Support/HigherOrderMessageCollection.php:43\n/Users/michaelutz/Code/neotest-pest/vendor/pestphp/pest/src/Factories/TestCaseFactory.php:148\n/Users/michaelutz/Code/neotest-pest/vendor/pestphp/pest/src/Concerns/Testable.php:302\n/Users/michaelutz/Code/neotest-pest/vendor/pestphp/pest/src/Support/ExceptionTrace.php:29\n/Users/michaelutz/Code/neotest-pest/vendor/pestphp/pest/src/Concerns/Testable.php:303\n/Users/michaelutz/Code/neotest-pest/vendor/pestphp/pest/src/Concerns/Testable.php:279\n/Users/michaelutz/Code/neotest-pest/vendor/pestphp/pest/src/Console/Command.php:119\n/Users/michaelutz/Code/neotest-pest/vendor/pestphp/pest/bin/pest:62\n/Users/michaelutz/Code/neotest-pest/vendor/pestphp/pest/bin/pest:63",
|
||||
_attr = {
|
||||
type = "PHPUnit\\Framework\\ExpectationFailedException"
|
||||
}
|
||||
}
|
||||
}, {
|
||||
_attr = {
|
||||
assertions = "3",
|
||||
class = "Tests\\Feature\\UserTest",
|
||||
classname = "Tests.Feature.UserTest",
|
||||
file = "/Users/michaelutz/Code/neotest-pest/tests/Feature/UserTest.php",
|
||||
name = "addFavoriteMovie",
|
||||
time = "0.001189"
|
||||
}
|
||||
}, {
|
||||
_attr = {
|
||||
assertions = "5",
|
||||
class = "Tests\\Feature\\UserTest",
|
||||
classname = "Tests.Feature.UserTest",
|
||||
file = "/Users/michaelutz/Code/neotest-pest/tests/Feature/UserTest.php",
|
||||
name = "removeFavoriteMovie",
|
||||
time = "0.001273"
|
||||
}
|
||||
} }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
local expected = {
|
||||
["/Users/michaelutz/Code/neotest-pest/tests/Feature/UserTest.php::addFavoriteMovie"] = {
|
||||
output_file = output_file,
|
||||
short = "TESTS.FEATURE.USERTEST\n-> PASSED - addFavoriteMovie",
|
||||
status = "passed"
|
||||
},
|
||||
["/Users/michaelutz/Code/neotest-pest/tests/Feature/UserTest.php::can tellAge"] = {
|
||||
output_file = output_file,
|
||||
short = "TESTS.FEATURE.USERTEST\n-> PASSED - can tellAge",
|
||||
status = "passed"
|
||||
},
|
||||
["/Users/michaelutz/Code/neotest-pest/tests/Feature/UserTest.php::class constructor"] = {
|
||||
output_file = output_file,
|
||||
short = "TESTS.FEATURE.USERTEST\n-> PASSED - class constructor",
|
||||
status = "passed"
|
||||
},
|
||||
["/Users/michaelutz/Code/neotest-pest/tests/Feature/UserTest.php::is false"] = {
|
||||
errors = { {} },
|
||||
output_file = output_file,
|
||||
status = "failed"
|
||||
},
|
||||
["/Users/michaelutz/Code/neotest-pest/tests/Feature/UserTest.php::removeFavoriteMovie"] = {
|
||||
output_file = output_file,
|
||||
short = "TESTS.FEATURE.USERTEST\n-> PASSED - removeFavoriteMovie",
|
||||
status = "passed"
|
||||
},
|
||||
["/Users/michaelutz/Code/neotest-pest/tests/Feature/UserTest.php::tellName"] = {
|
||||
output_file = output_file,
|
||||
short = "TESTS.FEATURE.USERTEST\n-> PASSED - tellName",
|
||||
status = "passed"
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -21,13 +21,17 @@ test('class constructor')
|
|||
->favorite_movies->toBeEmpty();
|
||||
|
||||
test('tellName', function () {
|
||||
throw new \Exception("Oops!");
|
||||
expect($this->sut)
|
||||
->tellName()->toBeString()->toContain('John');
|
||||
})
|
||||
->skip()
|
||||
->group('special tests');
|
||||
|
||||
it('throws', function () {
|
||||
throw new \Exception('oops!');
|
||||
});
|
||||
|
||||
it('is skipped')->skip();
|
||||
|
||||
it('can tellAge')
|
||||
->expect($makeUser)
|
||||
->tellAge()->toBeString()->toContain('18');
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue