diff --git a/src/bout++.cxx b/src/bout++.cxx index 6de1c5713b..48ab96298b 100644 --- a/src/bout++.cxx +++ b/src/bout++.cxx @@ -67,11 +67,10 @@ const char DEFAULT_DIR[] = "data"; #include #include +#include #include #include -#include - // Value passed at compile time // Used for MD5SUM, BOUT_LOCALE_PATH, and REVISION #define BUILDFLAG1_(x) #x @@ -81,12 +80,6 @@ const char DEFAULT_DIR[] = "data"; #define INDIRECT0_BOUTMAIN(...) INDIRECT1_BOUTMAIN(#__VA_ARGS__) #define STRINGIFY(a) INDIRECT0_BOUTMAIN(a) -// Define S_ISDIR if not defined by system headers (that is, MSVC) -// Taken from https://github.com/curl/curl/blob/e59540139a398dc70fde6aec487b19c5085105af/lib/curl_setup.h#L748-L751 -#if !defined(S_ISDIR) && defined(S_IFMT) && defined(S_IFDIR) -#define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR) -#endif - #ifdef _MSC_VER #include inline auto getpid() -> int { return GetCurrentProcessId(); } @@ -506,9 +499,8 @@ auto parseCommandLineArgs(int argc, char** argv) -> CommandLineArgs { } void checkDataDirectoryIsAccessible(const std::string& data_dir) { - struct stat test; - if (stat(data_dir.c_str(), &test) == 0) { - if (!S_ISDIR(test.st_mode)) { + if (std::filesystem::exists(data_dir)) { + if (!std::filesystem::is_directory(data_dir)) { throw BoutException(_("DataDir \"{:s}\" is not a directory\n"), data_dir); } } else { diff --git a/tests/integrated/test-backtrace/CMakeLists.txt b/tests/integrated/test-backtrace/CMakeLists.txt index aa66eeed56..b20262f1b1 100644 --- a/tests/integrated/test-backtrace/CMakeLists.txt +++ b/tests/integrated/test-backtrace/CMakeLists.txt @@ -1,5 +1,6 @@ bout_add_integrated_test(test-backtrace SOURCES boutexcept.cxx REQUIRES BOUT_USE_BACKTRACE + CONFLICTS CMAKE_SYSTEM_NAME MATCHES "FreeBSD" USE_RUNTEST ) diff --git a/tests/integrated/test-bout-override-default-option/runtest b/tests/integrated/test-bout-override-default-option/runtest index 42d75ca100..c13f4439b3 100755 --- a/tests/integrated/test-bout-override-default-option/runtest +++ b/tests/integrated/test-bout-override-default-option/runtest @@ -1,3 +1,3 @@ -#!/bin/bash +#!/usr/bin/env bash make && ./test-bout-override-default-option diff --git a/tests/integrated/test-code-style/runtest b/tests/integrated/test-code-style/runtest index cfd277d71b..d392f9110f 100755 --- a/tests/integrated/test-code-style/runtest +++ b/tests/integrated/test-code-style/runtest @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash #requires not make diff --git a/tests/integrated/test-command-args/runtest b/tests/integrated/test-command-args/runtest index 6830959343..39939bb105 100755 --- a/tests/integrated/test-command-args/runtest +++ b/tests/integrated/test-command-args/runtest @@ -5,10 +5,14 @@ import os import re import shutil import unittest +import platform + + +OUTPUT_FILE = "stdout.log" if platform.system() == "FreeBSD" else "stderr.log" class TestCommandLineArgs(unittest.TestCase): - command = "./command-args 2>stderr.log" + command = "./command-args >stdout.log 2>stderr.log" def makeDirAndCopyInput(self, path): os.mkdir(path) @@ -16,7 +20,7 @@ class TestCommandLineArgs(unittest.TestCase): def setUp(self): try: - os.remove("stderr.log") + os.remove(OUTPUT_FILE) except OSError: pass shutil.rmtree("./data", ignore_errors=True) @@ -29,7 +33,7 @@ class TestCommandLineArgs(unittest.TestCase): def testNoArgumentsNoDirectory(self): with self.assertRaises(RuntimeError): launch_safe(self.command, pipe=True, nproc=1, mthread=1) - with open("stderr.log") as f: + with open(OUTPUT_FILE) as f: contents = f.read() self.assertIn( '"data" does not exist', @@ -97,7 +101,7 @@ class TestCommandLineArgs(unittest.TestCase): launch_safe( self.command + " -d non_existent", pipe=True, nproc=1, mthread=1 ) - with open("stderr.log") as f: + with open(OUTPUT_FILE) as f: contents = f.read() self.assertIn( '"non_existent" does not exist', @@ -108,7 +112,7 @@ class TestCommandLineArgs(unittest.TestCase): def testDirectoryArgumentNonDirectory(self): with self.assertRaises(RuntimeError): launch_safe(self.command + " -d runtest", pipe=True, nproc=1, mthread=1) - with open("stderr.log") as f: + with open(OUTPUT_FILE) as f: contents = f.read() self.assertIn( '"runtest" is not a directory', @@ -175,21 +179,24 @@ class TestCommandLineArgs(unittest.TestCase): "--foo_flag", "some:option=value", ] - _, out = launch_safe( + launch_safe( self.command + " " + " ".join(extra_options), pipe=True, nproc=1, mthread=1 ) - command_line_options = None - for line in out.splitlines(): - if line.lstrip().startswith("Command line"): - command_line_options = line + with open("stdout.log") as f: + contents = f.read() - for option in extra_options: - self.assertIn( - option, - command_line_options, - msg="FAIL: option {} not printed out".format(option), - ) + command_line_options = None + for line in contents.splitlines(): + if line.lstrip().startswith("Command line"): + command_line_options = line + + for option in extra_options: + self.assertIn( + option, + command_line_options, + msg="FAIL: option {} not printed out".format(option), + ) if __name__ == "__main__": diff --git a/tests/integrated/test-compile-examples-petsc/runtest b/tests/integrated/test-compile-examples-petsc/runtest index cd61c30ef5..0f9625af40 100755 --- a/tests/integrated/test-compile-examples-petsc/runtest +++ b/tests/integrated/test-compile-examples-petsc/runtest @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash #requires: all_tests #requires: not make diff --git a/tests/integrated/test-compile-examples/runtest b/tests/integrated/test-compile-examples/runtest index 31650adeab..765ea2cbfd 100755 --- a/tests/integrated/test-compile-examples/runtest +++ b/tests/integrated/test-compile-examples/runtest @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash #requires: all_tests #requires: not make diff --git a/tests/integrated/test-coordinates-initialization/runtest b/tests/integrated/test-coordinates-initialization/runtest index 53cda495e6..60c3e3c980 100755 --- a/tests/integrated/test-coordinates-initialization/runtest +++ b/tests/integrated/test-coordinates-initialization/runtest @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # Cores: 3 diff --git a/tests/integrated/test-drift-instability/qsubcase.sh b/tests/integrated/test-drift-instability/qsubcase.sh index a7124dc81b..056095b18b 100755 --- a/tests/integrated/test-drift-instability/qsubcase.sh +++ b/tests/integrated/test-drift-instability/qsubcase.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # # Create a set of runs and submit to a queueing system e.g. Sun Grid Engine # diff --git a/tests/integrated/test-include/runtest b/tests/integrated/test-include/runtest index f70036a9e4..4fa8096c4b 100755 --- a/tests/integrated/test-include/runtest +++ b/tests/integrated/test-include/runtest @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash #requires: all_tests #Requires: not make diff --git a/tests/integrated/test-interchange-instability/qsubcase.sh b/tests/integrated/test-interchange-instability/qsubcase.sh index 9713809a61..ba3e22e7fa 100755 --- a/tests/integrated/test-interchange-instability/qsubcase.sh +++ b/tests/integrated/test-interchange-instability/qsubcase.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash QSUB=mpich2sub # Common values are qsub, mpisub NP=4 diff --git a/tests/integrated/test-stopCheck/runtest b/tests/integrated/test-stopCheck/runtest index aa0920d087..5cb8f0f1fb 100755 --- a/tests/integrated/test-stopCheck/runtest +++ b/tests/integrated/test-stopCheck/runtest @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash make || exit diff --git a/tests/unit/src/test_bout++.cxx b/tests/unit/src/test_bout++.cxx index b31be16a67..cef518756c 100644 --- a/tests/unit/src/test_bout++.cxx +++ b/tests/unit/src/test_bout++.cxx @@ -70,7 +70,7 @@ class SignalHandlerTest : public ::testing::Test { using SignalHandlerTestDeathTest = SignalHandlerTest; -#if !defined(__NVCC__) +#if !defined(__NVCC__) and !defined(__FreeBSD__) TEST_F(SignalHandlerTestDeathTest, SegFault) { bout::experimental::setupSignalHandler(bout::experimental::defaultSignalHandler); // This test is *incredibly* expensive, maybe as much as 1s, so only test the one signal diff --git a/tests/unit/sys/test_timer.cxx b/tests/unit/sys/test_timer.cxx index 4ec934658d..7641c5f8cf 100644 --- a/tests/unit/sys/test_timer.cxx +++ b/tests/unit/sys/test_timer.cxx @@ -271,7 +271,7 @@ TEST(TimerTest, ListAllInfo) { using namespace ::testing; EXPECT_THAT(cout_capture.str(), HasSubstr("Timer name |")); - EXPECT_THAT(cout_capture.str(), ContainsRegex("one *| 0\\.\\d+ | 1 | 0\\.\\d+")); - EXPECT_THAT(cout_capture.str(), ContainsRegex("two *| 0 * | 2 | 0\\.\\d+")); + EXPECT_THAT(cout_capture.str(), ContainsRegex("one *| 0\\.[0-9]+ | 1 | 0\\.[0-9]+")); + EXPECT_THAT(cout_capture.str(), ContainsRegex("two *| 0 * | 2 | 0\\.[0-9]+")); } #endif