Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

consider catch2's FAIL() #147

Merged
merged 8 commits into from
Sep 17, 2024

Conversation

sshane
Copy link
Contributor

@sshane sshane commented Sep 17, 2024

I believe FAIL_CHECK also produces a Failure tag

https://github.com/catchorg/Catch2/blob/fa43b77429ba76c462b1898d6cd2f2d7a9416b14/docs/logging.md?plain=1#L119-L125

This wasn't being marked as a failure with pytest, now it is:

code:

void checkWidgetTrWrap(MainWindow &w) {
  for (auto widget : w.findChildren<T>()) {
  const QString text = widget->text();
    bool isNumber = RE_NUM.exactMatch(text);
    bool wrapped = text.contains(TEST_TEXT);
    QString parentWidgets = getParentWidgets(widget).join("->");

    if (!text.isEmpty() && !isNumber && !wrapped) {
      FAIL(("\"" + text + "\" must be wrapped. Parent widgets: " + parentWidgets).toStdString());
    }

    // warn if source string wrapped, but UI adds text
    // TODO: add way to ignore this
    if (wrapped && text != TEST_TEXT) {
      WARN(("\"" + text + "\" is dynamic and needs a custom retranslate function. Parent widgets: " + parentWidgets).toStdString());
    }
  }
}

output:

<?xml version="1.0" encoding="UTF-8"?>
<Catch name="test_translations">
  <Group name="test_translations">
    <TestCase name="UI: test all strings wrapped" filename="selfdrive/ui/tests/test_translations.cc" line="39">
      <Failure filename="selfdrive/ui/tests/test_translations.cc" line="27">
        "Disengage on Accelerator Pedal" must be wrapped. Parent widgets: ParamControl->TogglesPanel->QWidget->ScrollView->QStackedWidget->SettingsWindow->MainWindow
      </Failure>
      <OverallResult success="false"/>
    </TestCase>
    <OverallResults successes="0" failures="1" expectedFailures="0"/>
    <OverallResultsCases successes="0" failures="1" expectedFailures="0"/>
  </Group>
  <OverallResults successes="0" failures="1" expectedFailures="0"/>
  <OverallResultsCases successes="0" failures="1" expectedFailures="0"/>
</Catch>

@nicoddemus nicoddemus merged commit 8ffb245 into pytest-dev:master Sep 17, 2024
9 checks passed
@nicoddemus
Copy link
Member

Thanks @sshane!

@sshane sshane deleted the support-catch2-failures branch September 17, 2024 23:52
@nicoddemus
Copy link
Member

Released 2.6.0, thanks again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants