diff mbox series

[1/2] kunit: Improve format of the NOT_ERR_OR_NULL assertion

Message ID 20230928133821.1467-1-michal.wajdeczko@intel.com (mailing list archive)
State New
Delegated to: Brendan Higgins
Headers show
Series [1/2] kunit: Improve format of the NOT_ERR_OR_NULL assertion | expand

Commit Message

Michal Wajdeczko Sept. 28, 2023, 1:38 p.m. UTC
Diagnostic message for failed KUNIT_ASSERT|EXPECT_NOT_ERR_OR_NULL
shows only raw error code, like in this example:

[ ] # example_all_expect_macros_test: EXPECTATION FAILED at lib/kunit/kunit-example-test.c:126
[ ] Expected myptr is not error, but is: -12

but we can improve it by using more friendly error pointer format:

[ ] # example_all_expect_macros_test: EXPECTATION FAILED at lib/kunit/kunit-example-test.c:126
[ ] Expected myptr is not error, but is -ENOMEM

Signed-off-by: Michal Wajdeczko <michal.wajdeczko@intel.com>
Cc: David Gow <davidgow@google.com>
Cc: Rae Moar <rmoar@google.com>
---
 lib/kunit/assert.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/lib/kunit/assert.c b/lib/kunit/assert.c
index dd1d633d0fe2..96ef236d3ca3 100644
--- a/lib/kunit/assert.c
+++ b/lib/kunit/assert.c
@@ -80,9 +80,9 @@  void kunit_ptr_not_err_assert_format(const struct kunit_assert *assert,
 				  ptr_assert->text);
 	} else if (IS_ERR(ptr_assert->value)) {
 		string_stream_add(stream,
-				  KUNIT_SUBTEST_INDENT "Expected %s is not error, but is: %ld\n",
+				  KUNIT_SUBTEST_INDENT "Expected %s is not error, but is %pe\n",
 				  ptr_assert->text,
-				  PTR_ERR(ptr_assert->value));
+				  ptr_assert->value);
 	}
 	kunit_assert_print_msg(message, stream);
 }