tests: Use virTestCompareToString() more

Instead of using:

  if (STRNEQ(a, b)) {
      virTestDifference(stderr, a, b);
      ...
  }

we can use:

  if (virTestCompareToString(a, b) < ) {
      ...
  }

Generated by the following spatch:

  @@
  expression a, b;
  @@

  - if (STRNEQ(a, b)) {
  + if (virTestCompareToString(a, b) < 0) {
      ...
  -   virTestDifference(stderr, a, b);
      ...
      }

and its variations (STRNEQ_NULLABLE() instead of STRNEQ(), then
in some cases variables passed to STRNEQ() are in reversed order
when compared to virTestCompareToString()).

However, coccinelle failed to recognize the pattern in
testNWFilterEBIPTablesAllTeardown() so I had to fix it manually.
Also, I manually fixed testFormat() in tests/sockettest.c as I
didn't bother writing another spatch rule just for that.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Jonathon Jongsma <jjongsma@redhat.com>
This commit is contained in:
Michal Privoznik
2022-11-30 09:57:49 +01:00
parent 1fffd1605d
commit a156b69c35
15 changed files with 51 additions and 103 deletions

View File

@@ -92,8 +92,7 @@ testVirNetDevBandwidthSet(const void *data)
* Maybe that's expected, actually. */
}
if (STRNEQ_NULLABLE(exp_cmd, actual_cmd)) {
virTestDifference(stderr, exp_cmd, actual_cmd);
if (virTestCompareToString(exp_cmd, actual_cmd) < 0) {
return -1;
}