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

@@ -488,8 +488,7 @@ static int testSocketSSH(const void *opaque)
}
buf[rv] = '\0';
if (STRNEQ(buf, data->expectOut)) {
virTestDifference(stderr, data->expectOut, buf);
if (virTestCompareToString(data->expectOut, buf) < 0) {
goto cleanup;
}