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

@@ -134,8 +134,7 @@ testCompareOutputLit(const char *expectData,
if (filter && testFilterLine(actualData, filter) < 0)
return -1;
if (STRNEQ(expectData, actualData)) {
virTestDifference(stderr, expectData, actualData);
if (virTestCompareToString(expectData, actualData) < 0) {
return -1;
}