From 1f74bb995e786ff29e417e57ecd4da2d2cb44ef8 Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Wed, 11 Sep 2024 13:48:52 -0600 Subject: [PATCH] Add a test that needs to fail. --- .../parsed_function_constants_with_errors.cc | 65 +++++++++++++++++++ ...ants_with_errors.with_muparser=true.output | 2 + 2 files changed, 67 insertions(+) create mode 100644 tests/bits/parsed_function_constants_with_errors.cc create mode 100644 tests/bits/parsed_function_constants_with_errors.with_muparser=true.output diff --git a/tests/bits/parsed_function_constants_with_errors.cc b/tests/bits/parsed_function_constants_with_errors.cc new file mode 100644 index 0000000000..2e603c3d73 --- /dev/null +++ b/tests/bits/parsed_function_constants_with_errors.cc @@ -0,0 +1,65 @@ +// ------------------------------------------------------------------------ +// +// SPDX-License-Identifier: LGPL-2.1-or-later +// Copyright (C) 2007 - 2018 by the deal.II authors +// +// This file is part of the deal.II library. +// +// Part of the source code is dual licensed under Apache-2.0 WITH +// LLVM-exception OR LGPL-2.1-or-later. Detailed license information +// governing the source code and code contributions can be found in +// LICENSE.md and CONTRIBUTING.md at the top level directory of deal.II. +// +// ------------------------------------------------------------------------ + + + +// This program tests the functionality of the function parser +// wrapper. + +#include +#include +#include + +#include + +#include "../tests.h" + +void +test() +{ + // A parameter handler + ParameterHandler prm; + + Functions::ParsedFunction<1>::declare_parameters(prm, 1); + + // Setting a constant to an expression should fail: + prm.set("Function constants", "f=100.0*60*60*24*365.2425"); + + prm.set("Function expression", "f*f+2*x"); + + Functions::ParsedFunction<1> function(1); + + bool caught_error = false; + try + { + function.parse_parameters(prm); + } + catch (...) + { + deallog << "Caught error about invalid set for function constant." + << std::endl; + caught_error = true; + // Ignore the actual error. + } + + Assert(caught_error == true, ExcInternalError()); +} + +int +main() +{ + initlog(); + + test(); +} diff --git a/tests/bits/parsed_function_constants_with_errors.with_muparser=true.output b/tests/bits/parsed_function_constants_with_errors.with_muparser=true.output new file mode 100644 index 0000000000..eaedd61452 --- /dev/null +++ b/tests/bits/parsed_function_constants_with_errors.with_muparser=true.output @@ -0,0 +1,2 @@ + +DEAL::Caught error about invalid set for function constant. -- 2.39.5