]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Add a test. 18028/head
authorWolfgang Bangerth <bangerth@colostate.edu>
Mon, 27 Jan 2025 18:07:07 +0000 (11:07 -0700)
committerWolfgang Bangerth <bangerth@colostate.edu>
Mon, 27 Jan 2025 21:51:10 +0000 (14:51 -0700)
tests/parameter_handler/parameter_handler_6_spaces.cc [new file with mode: 0644]
tests/parameter_handler/parameter_handler_6_spaces.output [new file with mode: 0644]

diff --git a/tests/parameter_handler/parameter_handler_6_spaces.cc b/tests/parameter_handler/parameter_handler_6_spaces.cc
new file mode 100644 (file)
index 0000000..3045206
--- /dev/null
@@ -0,0 +1,101 @@
+// ------------------------------------------------------------------------
+//
+// SPDX-License-Identifier: LGPL-2.1-or-later
+// Copyright (C) 2003 - 2023 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 is a variation of the parameter_handler_6 test. At some point,
+// we made an inadvertent change that led to no longer correctly
+// indenting the parameters listed in a section when outputting the
+// current state of a ParameterHandler object. numdiff didn't catch it
+// because it ignores whitespace except to separate tokens. This test
+// therefore outputs everything into a stringstream, replaces every
+// space by an underscore, and outputs that. Changes in indentation
+// will then show up as changes in output in a way that can't be
+// ignored by numdiff.
+
+#include <deal.II/base/parameter_handler.h>
+
+#include "../tests.h"
+
+
+int
+main()
+{
+  try
+    {
+      initlog();
+
+      // same as parameter_handler_3
+      ParameterHandler prm;
+      prm.enter_subsection("Testing");
+      prm.declare_entry("string list",
+                        "a",
+                        Patterns::List(Patterns::Selection("a|b|c|d|e|f|g|h")),
+                        "docs 1");
+      prm.declare_entry("int", "1", Patterns::Integer());
+      prm.declare_entry("double", "3.1415926", Patterns::Double(), "docs 3");
+      prm.leave_subsection();
+
+      prm.parse_input(SOURCE_DIR "/prm/parameter_handler_3.prm");
+
+      // now set some of the entries to
+      // different values
+      prm.enter_subsection("Testing");
+      prm.set("string list", "a, c, b");
+      prm.set("int", "5");
+      prm.set("double", "2.71828");
+      prm.leave_subsection();
+
+      // Write output into a stringstream:
+      std::ostringstream o;
+      prm.print_parameters(o, ParameterHandler::PRM);
+
+      // Replace all spaces by underscores
+      std::string s = o.str();
+      for (unsigned int i = 0; i < s.size(); ++i)
+        if (s[i] == ' ')
+          s[i] = '_';
+
+      // Finally output things into deallog:
+      deallog.get_file_stream() << s;
+    }
+  catch (const std::exception &exc)
+    {
+      deallog << std::endl
+              << std::endl
+              << "----------------------------------------------------"
+              << std::endl;
+      deallog << "Exception on processing: " << std::endl
+              << exc.what() << std::endl
+              << "Aborting!" << std::endl
+              << "----------------------------------------------------"
+              << std::endl;
+
+      return 1;
+    }
+  catch (...)
+    {
+      deallog << std::endl
+              << std::endl
+              << "----------------------------------------------------"
+              << std::endl;
+      deallog << "Unknown exception!" << std::endl
+              << "Aborting!" << std::endl
+              << "----------------------------------------------------"
+              << std::endl;
+      return 1;
+    };
+
+  return 0;
+}
diff --git a/tests/parameter_handler/parameter_handler_6_spaces.output b/tests/parameter_handler/parameter_handler_6_spaces.output
new file mode 100644 (file)
index 0000000..77fa5c8
--- /dev/null
@@ -0,0 +1,13 @@
+
+#_Listing_of_Parameters
+#_---------------------
+subsection_Testing
+__#_docs_3
+__set_double______=_2.71828_#_default:_3.1415926
+__set_int_________=_5_______#_default:_1
+
+__#_docs_1
+__set_string_list_=_a,_c,_b_#_default:_a
+end
+
+

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.