RunException

The RunException tester is used to check exceptions and expected error messages. The application is intentionally placed in a wrong/erroring configuration for the test, and the test makes sure that the problem is indeed caught and the simulation does not proceed.

Options

Test configuration options are specified in the tests file.

  • expect_err: A regular expression or literal string that must occur in the output (see match_literal). (Test may terminate unexpectedly and be considered passing)

  • expect_assert: DEBUG and DEVEL MODE ONLY: A regular expression that must occur in the output. (Test may terminate unexpectedly and be considered passing)

  • should_crash: Indicates that the test is expected to crash or otherwise terminate early. Defaults to True

Tests with an expect_assert parameter will only be run in DEBUG and DEVEL mode, not in OPT mode. Other test commands & restrictions may be found in the TestHarness documentation.

Example test configuration in the MOOSE test suite

In this example, a single Exodiff test is used to examine the outputs of the MaterialADConverter. But six RunException tests are then used to examine all the potential user input errors that could be made and that the MaterialADConverter should error out on.

[Tests]
  design = FunctorADConverter.md
  issues = '#19420'
  [exo]
    type = Exodiff
    input = 1d_dirichlet.i
    exodiff = 1d_dirichlet_out.e
    requirement = 'The system shall be able to convert functors from AD to regular and vice versa.'
  []
  [errors]
    design = 'FunctorADConverter.md'
    requirement = 'The system shall report an error with a clear parameter error if'
    [reg_in_ad_out]
      type = RunException
      input = 1d_dirichlet.i
      cli_args = 'Materials/converter_to_ad/ad_props_out=regular_sink_1'
      expect_err = 'Functor names may not overlap between reg_props_in and ad_props_out'
      detail = 'the names for the regular functors to be converted are going to overlap with the new automatic differentiation functors'
    []
    [reg_in_reg_out]
      type = RunException
      input = 1d_dirichlet.i
      cli_args = 'Materials/converter_to_ad/ad_props_in=sink Materials/converter_to_ad/reg_props_out=regular_sink_1'
      expect_err = 'Functor names may not overlap between reg_props_in and reg_props_out'
      detail = 'the names for the regular functors to be converted are going to overlap with the other new regular functors'
    []
    [ad_in_reg_out]
      type = RunException
      input = 1d_dirichlet.i
      cli_args = 'Materials/converter_to_regular/reg_props_out=sink'
      expect_err = 'Functor names may not overlap between ad_props_in and reg_props_out'
      detail = 'the names for the automatic differentiation functors to be converted are going to overlap with the new regular functors'
    []
    [ad_in_ad_out]
      type = RunException
      input = 1d_dirichlet.i
      cli_args = 'Materials/converter_to_ad/ad_props_in=sink Materials/converter_to_ad/reg_props_out=regular_sink_2 Materials/converter_to_ad/ad_props_out=sink'
      expect_err = 'Functor names may not overlap between ad_props_in and ad_props_out'
      detail = 'the names for the automatic differentiation functors to be converted are going to overlap with the other new automatic differentiation functors'
    []
    [size_ad_in]
      type = RunException
      input = 1d_dirichlet.i
      cli_args = "Materials/converter_to_regular/ad_props_in='sink 4'"
      expect_err = 'The number of output regular functors must match the number of input AD'
      detail = 'the number of automatic differentiation functors to convert does not match the number of names for the converted functors'
    []
    [size_reg_in]
      type = RunException
      input = 1d_dirichlet.i
      cli_args = "Materials/converter_to_ad/reg_props_in='regular_sink_1 1'"
      expect_err = 'The number of output AD functors must match the number of input regular'
      detail = 'the number of regular functors to convert does not match the number of names for the converted functors'
    []
  []
[]
(contrib/moose/test/tests/materials/functor_properties/ad_conversion/tests)