Meson tests fail but pass when ran locally #12736
-
Hi all, I had an issue that has been plaguing me for some time now. When I run unit test executables through Meson or Ninja, I keep getting timeouts on unit tests that read image files using Tested OSs: Example test // catch
#include <catch2/catch_test_macros.hpp>
#include <catch2/matchers/catch_matchers_all.hpp>
// std
#include <fstream>
#include <iostream>
#include <sstream>
#include <string>
TEST_CASE("image_test - scale_test")
{
std::ifstream is("some_file.tif", std::ios::binary);
REQUIRE(is.is_open()); // <-- here is my issue, it always returns false under Meson, but true when ran manually
} Example build script (for subdir tests) test_source_files = [
'my_test_file.cpp'
]
foreach test_file: test_source_files
source_name = test_file.split('.')[0]
exec = executable(
source_name,
test_file,
include_directories: my_lib_include,
dependencies: my_lib_deps + [catch2_dep],
cpp_args: ['-D_USE_MATH_DEFINES'],
link_with: my_lib
)
test(
source_name,
exec
)
endforeach
If necessary, I can make a working example sometime in the future. Additional Context I tried the following:
If this issue is a shared file related issue, then why? std::ifstream supports concurrency, if I remember correctly. For additional context, the library I am working on is a port from vcpkg to meson and is located here. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
As I suspected, it was an absolute path issue. What is happening is that the relative path is set to the build directory and not the directory containing the executables. For instance. the working directory set by meson on my Windows 11 environment is |
Beta Was this translation helpful? Give feedback.
-
Is this included in your current build files? I don't see it. For what it's worth, the tests do pass for me, with the following patch: diff --git a/tests/meson.build b/tests/meson.build
index 7be87be..b9f99fc 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -33,7 +33,8 @@ foreach test_file: test_source_files
test(
source_name,
- exec
+ exec,
+ workdir: meson.current_build_dir(),
)
endforeach
@@ -58,7 +59,8 @@ if found_benchmark
test(
source_name,
- exec
+ exec,
+ workdir: meson.current_build_dir(),
)
endforeach |
Beta Was this translation helpful? Give feedback.
Is this included in your current build files? I don't see it.
For what it's worth, the tests do pass for me, with the following patch: