diff mbox series

[v2,1/3] kunit: Improve format of the NOT_ERR_OR_NULL assertion

Message ID 20240822125459.2075-2-michal.wajdeczko@intel.com
State New
Headers show
Series kunit: Improve format of some assertion messages | expand

Commit Message

Michal Wajdeczko Aug. 22, 2024, 12:54 p.m. UTC
Diagnostic message for failed KUNIT_ASSERT|EXPECT_NOT_ERR_OR_NULL
shows only raw error code, like for this example:

  void *myptr = ERR_PTR(-ENOMEM);
  KUNIT_EXPECT_NOT_ERR_OR_NULL(test, myptr);

we will get:

  [ ] Expected myptr is not error, but is: -12

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

  [ ] Expected myptr is not error, but is -ENOMEM (-12)

Signed-off-by: Michal Wajdeczko <michal.wajdeczko@intel.com>
Reviewed-by: David Gow <davidgow@google.com>
---
v2: keep numerical error value (David,kunit-assert)
---
 lib/kunit/assert.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
diff mbox series

Patch

diff --git a/lib/kunit/assert.c b/lib/kunit/assert.c
index 867aa5c4bccf..aa3ae225f49f 100644
--- a/lib/kunit/assert.c
+++ b/lib/kunit/assert.c
@@ -77,13 +77,14 @@  void kunit_ptr_not_err_assert_format(const struct kunit_assert *assert,
 				  assert);
 
 	if (!ptr_assert->value) {
-		string_stream_add(stream,
-				  KUNIT_SUBTEST_INDENT "Expected %s is not null, but is\n",
+		string_stream_add(stream, KUNIT_SUBTEST_INDENT
+				  "Expected %s is not null, but is\n",
 				  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",
+		string_stream_add(stream, KUNIT_SUBTEST_INDENT
+				  "Expected %s is not error, but is %pe (%ld)\n",
 				  ptr_assert->text,
+				  ptr_assert->value,
 				  PTR_ERR(ptr_assert->value));
 	}
 	kunit_assert_print_msg(message, stream);