This is an archive of the discontinued LLVM Phabricator instance.

[lldb][NFC] Specify guidelines for API tests
ClosedPublic

Authored by teemperor on Apr 23 2021, 4:10 AM.

Details

Reviewers
shafik
Group Reviewers
Restricted Project
Commits
rG4112f5ef69a1: [lldb][NFC] Specify guidelines for API tests
Summary

This patch specifies a few guidelines that our API tests should follow.

The motivations for this are twofold:

  1. API tests have unexpected pitfalls that especially new contributors run into when writing tests. To prevent the frustration of letting people figure those pitfalls out by trial-and-error, let's just document them briefly in one place.
  1. It prevents some arguing about what is the right way to write tests. I really like to have fast and reliable API test suite, but I also don't want to be the bogeyman that has to insist in every review that the test should be rewritten to not launch a process for no good reason. It's much easier to just point to a policy document.

I omitted some guidelines that I think could be controversial (e.g., the whole "should assert message describe failure or success").

Diff Detail

Event Timeline

teemperor created this revision.Apr 23 2021, 4:10 AM
teemperor requested review of this revision.Apr 23 2021, 4:10 AM
teemperor updated this revision to Diff 339978.Apr 23 2021, 4:14 AM
  • Improve some wording.

If anyone feels like any of the guidelines is actually controversial then let me know and I'll remove it from this review and split it out into its own patch.

(I am also aware that the text directly above has some small overlap with the guidelines as it for example also recommends the lldb utility functions for setup/checking. But given how frequently this comes up in patches I just put it in as its own guideline).

Thanks for taking all the lore around API tests and writing it down. I think this is going to be very useful and make our lives easier during code review.

This LGTM but I won't accept (yet) to give others a chance to see this show up in their review queue.

lldb/docs/resources/test.rst
215

Seems like the last sentence is incomplete?

229
shafik added a subscriber: shafik.Apr 23 2021, 9:47 AM

Thank you, this is awesome.

lldb/docs/resources/test.rst
206

While I agree with this, it also feels unhelpful because it does not give any examples nor explain the alternatives.

I can see the problem with pointing at specific tests which may disappear or change. I can also see the problem with attempting to enumerate all the possibilities below this as well.

Maybe we need a set of example tests as well?

Most of the rest of advice stands alone pretty well though.

264

Maybe some more examples with alternatives would be helpful here.

LGTM too, thanks for writing this up!

lldb/docs/resources/test.rst
264

Also mentioning why this check is bad would help spell it out. IIUC, it's because the full output will include $0 (if it's the first expression, as noted); in which case, a stronger example is something that's clearly wrong:

(lldb) expr 5-3
(int) $0 = 2

In which case, self.expect("expr 5 - 3", substrs=["0"]) passes, but shouldn't.

279–280

nit: extra "# Good"

DavidSpickett added inline comments.
lldb/docs/resources/test.rst
222

Does this mean only use the flags you really need, or to put those flags somewhere other than the makefile? (I guess the former since they'd have to be in the makefile for your test to work anyway)

Would be good to make it clear so the reader doesn't think that there's some other place to put compiler flags, which isn't specified.

teemperor marked 7 inline comments as done.Apr 26 2021, 5:37 AM

Addressing feedback.

lldb/docs/resources/test.rst
206

Good point. We actually have (or had?) example tests but they always end up being forgotten about and are probably in a bad shape these days. I think by now many tests are in a good enough shape that people find a good test they can copy/extend for their own purpose, so I think we are relatively fine without explicit example tests that demonstrate this.

I updated the text with a list of functionality that I would expect to avoid creating a process in their tests (and a list of features where creating a test is unavoidable in 99% of the cases). I don't think this list will every change and I think it should give people a general idea whether they can avoid launching a process.

222

Thanks! I clarified that specifying them anywhere is the problem (and how to avoid it).

229

Done. I actually believe the comma is correct (at least the internet says it is and if that's not a reliable source than what is).

264

Thanks!

I actually tried to avoid the formatting pain of having a code example in the middle a sphinx definition block. I put an explanation and a better alternative in the text now, but I don't think I can avoid that the non-inline code example terminates the first block. The only effect of this is just that the text following the definition blocks doesn't have the same indentation as the first text block (which actually doesn't look that bad, just a mild annoyance).

279–280

Thanks!

teemperor updated this revision to Diff 340520.Apr 26 2021, 7:22 AM
teemperor marked 5 inline comments as done.
  • Update diff with feedback.

Nice addition, these are great guidelines. I'd do a s/just// pass over the text, there's some extraneous "just"s that could go. This is a very bad habit of my own lately, I re-read emails I write, and try to remove "justs" that snuck into the text I typed before I send. I think my keyboard driver might be responsible for inserting them into sentences.

lldb/docs/resources/test.rst
229

two cents - if it were english, like "(that is, do not generate", I'd use a comma. I've never thought about which is correct with "i.e." but if I were thinking about it, I'd go with a comma.

JDevlieghere added inline comments.Apr 27 2021, 9:04 AM
lldb/docs/resources/test.rst
229

Interesting, so this is a British/American English thing, where the former generally does not use a comma while the latter does. I learned something new today :-) Anyway, well free to add the comma again as the docs are all using American English. (sorry for the churn!)

  • Americanized the commas (Her Majesty the Queen won't be pleased, won't she?).
  • Just removed some justs.
rovka added a subscriber: rovka.Apr 28 2021, 1:25 AM

This is awesome, thanks for writing this up!

lldb/docs/resources/test.rst
224

I don't think you need 'to' here.

256

program -> programs

310

You're using 'see' twice in the same sentence. Some alternatives:
"Check the documentation [...]",
"Read the documentation [...]",
"[...] learn what asserts are available",
or anything else along those lines :)

313

help -> helps

shafik accepted this revision as: shafik.Apr 29 2021, 9:32 AM

I don't have any other feedback, LGTM.

This revision is now accepted and ready to land.Apr 29 2021, 9:32 AM
teemperor updated this revision to Diff 341832.Apr 30 2021, 3:53 AM
  • Addressed Diana's comments (thanks!)
This revision was automatically updated to reflect the committed changes.