]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Add a test.
authorWolfgang Bangerth <bangerth@colostate.edu>
Fri, 5 May 2023 21:06:00 +0000 (15:06 -0600)
committerWolfgang Bangerth <bangerth@colostate.edu>
Sun, 7 May 2023 17:13:25 +0000 (11:13 -0600)
tests/base/scope_exit_01.cc [new file with mode: 0644]
tests/base/scope_exit_01.output [new file with mode: 0644]

diff --git a/tests/base/scope_exit_01.cc b/tests/base/scope_exit_01.cc
new file mode 100644 (file)
index 0000000..5976a6b
--- /dev/null
@@ -0,0 +1,78 @@
+// ---------------------------------------------------------------------
+//
+// Copyright (C) 2023 by the deal.II authors
+//
+// This file is part of the deal.II library.
+//
+// The deal.II library is free software; you can use it, redistribute
+// it, and/or modify it under the terms of the GNU Lesser General
+// Public License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+// The full text of the license can be found in the file LICENSE.md at
+// the top level directory of deal.II.
+//
+// ---------------------------------------------------------------------
+
+
+// Check that ScopeExit works in both regular return statements and
+// via `throw` statements.
+
+#include <deal.II/base/scope_exit.h>
+
+#include "../tests.h"
+
+
+void
+f1()
+{
+  ScopeExit s([]() { deallog << "Exiting function regularly." << std::endl; });
+
+  return;
+}
+
+
+void
+f2()
+{
+  ScopeExit s([]() { deallog << "Exiting function via throw." << std::endl; });
+
+  throw 123;
+}
+
+
+void
+f3()
+{
+  ScopeExit s([]() { deallog << "Exiting function regularly." << std::endl; });
+
+  try
+    {
+      throw 123;
+    }
+  catch (...)
+    {
+      // just eat the exception and return regularly
+      deallog << "Caught exception. Making it go away." << std::endl;
+    }
+}
+
+
+
+int
+main()
+{
+  initlog();
+
+  f1();
+
+  try
+    {
+      f2();
+    }
+  catch (int i)
+    {
+      deallog << "Caught int=" << i << std::endl;
+    }
+
+  f3();
+}
diff --git a/tests/base/scope_exit_01.output b/tests/base/scope_exit_01.output
new file mode 100644 (file)
index 0000000..761b801
--- /dev/null
@@ -0,0 +1,6 @@
+
+DEAL::Exiting function regularly.
+DEAL::Exiting function via throw.
+DEAL::Caught int=123
+DEAL::Caught exception. Making it go away.
+DEAL::Exiting function regularly.

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.