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

QTest: allow implicit std::nullopt to be used in data functions

XMLWordPrintable

    • Icon: Task Task
    • Resolution: Unresolved
    • Icon: P3: Somewhat important P3: Somewhat important
    • None
    • None
    • Testing: qtestlib
    • None
    • All

      When using optional types in data functions and directly assigning std::nullopt through operator <<, like this:

      void TestOptional::optional_data()
      {
          QTest::addColumn<std::optional<int>>("optInteger");
          auto retNullopt = []() -> std::optional<int> { return std::nullopt; };    std::optional<int> a = 1;
          QTest::newRow("ok1") << a;
          QTest::newRow("nullopt-ok") << retNullopt();
          QTest::newRow("nullopt-err") << std::nullopt;
      } 

      QTest will complain like this:

      QDEBUG : TestOptional::optional() expected data of type 'std::optional<int>', got 'std::nullopt_t' for element 0 of data with tag 'nullopt-err'
      QFATAL : TestOptional::optional() ASSERT: "false" in file /home/ddob/qt/qt6/qtbase/src/testlib/qtestdata.cpp, line 69
      FAIL!  : TestOptional::optional() Received a fatal error.
         Loc: [/home/ddob/qt/qt6/qtbase/src/testlib/qtestdata.cpp(69)] 

      When wrapping the std::nullopt through a function call it works again. I think having this implicit conversion seems logical. The same holds true for assigning the underlying type. QTest just strictly expects to receive the correct types but it's annoying for the std::nullopt case.

       

      Example attached.

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

            macadder Jason McDonald
            dennisoberst Dennis Oberst
            Vladimir Minenko Vladimir Minenko
            Alex Blasche Alex Blasche
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:

                There are no open Gerrit changes