rust-for-linux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: David Gow <davidgow@google.com>
To: Miguel Ojeda <miguel.ojeda.sandonis@gmail.com>
Cc: "Tamir Duberstein" <tamird@gmail.com>,
	"Miguel Ojeda" <ojeda@kernel.org>,
	"Brendan Higgins" <brendan.higgins@linux.dev>,
	"Alex Gaynor" <alex.gaynor@gmail.com>,
	"Rae Moar" <rmoar@google.com>,
	linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com,
	"Boqun Feng" <boqun.feng@gmail.com>,
	"Gary Guo" <gary@garyguo.net>,
	"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
	"Benno Lossin" <benno.lossin@proton.me>,
	"Andreas Hindborg" <a.hindborg@kernel.org>,
	"Alice Ryhl" <aliceryhl@google.com>,
	"Trevor Gross" <tmgross@umich.edu>,
	"Danilo Krummrich" <dakr@kernel.org>,
	rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org,
	patches@lists.linux.dev
Subject: Re: [PATCH 2/7] rust: kunit: support checked `-> Result`s in KUnit `#[test]`s
Date: Mon, 5 May 2025 14:03:03 +0800	[thread overview]
Message-ID: <CABVgOSmTCXD1HnBZZOUBTPwANGUzxa+w3+xcFr=HDtWkot0NzQ@mail.gmail.com> (raw)
In-Reply-To: <CANiq72=C1+2B221ecxM5Dy1rF8nEtR4ikgAA2nEh3M1=EkkXyg@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 1230 bytes --]

On Mon, 5 May 2025 at 02:00, Miguel Ojeda
<miguel.ojeda.sandonis@gmail.com> wrote:
>
> On Sun, May 4, 2025 at 7:34 PM Tamir Duberstein <tamird@gmail.com> wrote:
> >
> > Why not restrict this to Result<(), E>?
>
> I guess it is an option -- not sure if there may be a use case.
>
> > Is it possible to include the error in the output?
>
> I thought about giving some more context somehow and perhaps printing
> it "manually" in the log, possibly in a KUnit `# ...`. David can
> probably suggest the "proper" way.

Yeah, writing it to the log is fine: probably the best way of handling
this would be to have a kunit assertion macro for "assert_is_ok!()",
which prints the error nicely.
We could just use the existing kernel::kunit::err() function (which
could use some improvement, but is a good start), or even add a proper
assertion formatter which handles rust types via %pA.

That being said, there's no guarantee that the Err branch of a
Result<> can be printed: so there'd need to be some magic to handle
both the case where (e.g.) Err derives Debug, and the case where it
doesn't (in which case, we're basically stuck with what we've got
here: "expected is_ok()" or similar.

Cheers,
-- David

[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 5281 bytes --]

  reply	other threads:[~2025-05-05  6:03 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-05-02 21:51 [PATCH 0/7] Rust KUnit `#[test]` support improvements Miguel Ojeda
2025-05-02 21:51 ` [PATCH 1/7] rust: kunit: support KUnit-mapped `assert!` macros in `#[test]`s Miguel Ojeda
2025-05-04 17:41   ` Tamir Duberstein
2025-05-27  0:02     ` Miguel Ojeda
2025-05-05  6:02   ` David Gow
2025-05-27  0:08     ` Miguel Ojeda
2025-05-02 21:51 ` [PATCH 2/7] rust: kunit: support checked `-> Result`s in KUnit `#[test]`s Miguel Ojeda
2025-05-04 17:33   ` Tamir Duberstein
2025-05-04 17:59     ` Miguel Ojeda
2025-05-05  6:03       ` David Gow [this message]
2025-05-05  6:02   ` David Gow
2025-05-05 19:34     ` Boqun Feng
2025-05-06  6:32       ` David Gow
2025-05-27 15:22         ` Miguel Ojeda
2025-05-02 21:51 ` [PATCH 3/7] rust: add `kunit_tests` to the prelude Miguel Ojeda
2025-05-05  6:02   ` David Gow
2025-05-02 21:51 ` [PATCH 4/7] rust: str: convert `rusttest` tests into KUnit Miguel Ojeda
2025-05-04 17:30   ` Tamir Duberstein
2025-05-04 18:31     ` Miguel Ojeda
2025-05-04 18:39       ` Tamir Duberstein
2025-05-04 19:02         ` Miguel Ojeda
2025-05-05  6:03           ` David Gow
2025-05-05  6:02   ` David Gow
2025-05-10  1:58   ` John Hubbard
2025-05-02 21:51 ` [PATCH 5/7] rust: str: take advantage of the `-> Result` support in KUnit `#[test]`'s Miguel Ojeda
2025-05-04 17:29   ` Tamir Duberstein
2025-05-04 18:15     ` Miguel Ojeda
2025-05-04 18:22       ` Tamir Duberstein
2025-05-04 21:54         ` Miguel Ojeda
2025-05-05  6:03           ` David Gow
2025-05-05  6:02   ` David Gow
2025-05-02 21:51 ` [PATCH 6/7] Documentation: rust: rename `#[test]`s to "`rusttest` host tests" Miguel Ojeda
2025-05-05  6:02   ` David Gow
2025-05-02 21:51 ` [PATCH 7/7] Documentation: rust: testing: add docs on the new KUnit `#[test]` tests Miguel Ojeda
2025-05-05  6:02   ` David Gow
2025-05-05 16:57 ` [PATCH 0/7] Rust KUnit `#[test]` support improvements Danilo Krummrich
2025-05-05 17:07   ` Miguel Ojeda
2025-05-27  0:10 ` Miguel Ojeda
2025-05-27  0:12   ` Miguel Ojeda
2025-05-28  8:03   ` Miguel Ojeda

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CABVgOSmTCXD1HnBZZOUBTPwANGUzxa+w3+xcFr=HDtWkot0NzQ@mail.gmail.com' \
    --to=davidgow@google.com \
    --cc=a.hindborg@kernel.org \
    --cc=alex.gaynor@gmail.com \
    --cc=aliceryhl@google.com \
    --cc=benno.lossin@proton.me \
    --cc=bjorn3_gh@protonmail.com \
    --cc=boqun.feng@gmail.com \
    --cc=brendan.higgins@linux.dev \
    --cc=dakr@kernel.org \
    --cc=gary@garyguo.net \
    --cc=kunit-dev@googlegroups.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=miguel.ojeda.sandonis@gmail.com \
    --cc=ojeda@kernel.org \
    --cc=patches@lists.linux.dev \
    --cc=rmoar@google.com \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=tamird@gmail.com \
    --cc=tmgross@umich.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).