Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-104867

QtTest: QCOMPARE prints matching <null>s for mismatches when unable to convert to string

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P2: Important
    • None
    • 6.4.0 Beta1
    • Testing: qtestlib
    • None
    • All

    Description

      When comparing classes that QtTest cannot convert to strings, effectively, missing a template specialisation of toString(), then in case of a test case failure, it just prints out <null> for both the expected and actual values.

       

      This can be easily reproduced by any class that toString() does not know how to convert to a string. So, a simple class Foo {}; would do it for comparison with some mismatching expected and actual values.

       

      class Foo {};
      Foo foo1, foo2;
      QCOMPARE(foo1, foo2);
      

       Resulting in this:

       

      Actual (foo1): <null>
      Expected (foo2) : <null>
      

      They are seemingly equally, so they do not seem to indicate a real test failure. They could potentially output something like "Values differ" instead. It is still not specific enough with concrete strings, but slightly better.

      It is also worth mentioning that instead of just printing something like "expected and actual did not match", it would be even better if a warning was issues to the QtTest user so that he is informed that a specialisation would need to be added for this particular type to get more information.

       

      Since it would just be a warning rather than an error,  the warning could be safely ignored if the user does not want to get the concrete values. Although, I cannot possibly imagine a case when they would not want.

       

      To be fair, it will not always be possible to add a template specialisation for custom classes outside of Qt, so those classes will need to convert themselves into some type covered by the existing template specialisations, e.g. convert themselves to QString.

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            vhilshei Volker Hilsheimer
            lpapp Laszlo Papp
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: