Skip to content

Commit 41113e3

Browse files
committed
Merge pull request #5950
3a3ecc0 Initialization: setup environment before starting QT tests (dexX7) fc3979a Initialization: setup environment before starting tests (dexX7) ba0fa0d Initialization: set fallback locale as environment variable (dexX7)
2 parents 5ff4065 + 3a3ecc0 commit 41113e3

File tree

3 files changed

+7
-3
lines changed

3 files changed

+7
-3
lines changed

src/qt/test/test_main.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "config/bitcoin-config.h"
77
#endif
88

9+
#include "util.h"
910
#include "uritests.h"
1011

1112
#ifdef ENABLE_WALLET
@@ -27,6 +28,7 @@ Q_IMPORT_PLUGIN(qkrcodecs)
2728
// This is all you need to run all the tests
2829
int main(int argc, char *argv[])
2930
{
31+
SetupEnvironment();
3032
bool fInvalid = false;
3133

3234
// Don't remove this, it's needed to access

src/test/test_bitcoin.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ extern void noui_connect();
2828

2929
BasicTestingSetup::BasicTestingSetup()
3030
{
31+
SetupEnvironment();
3132
fPrintToDebugLog = false; // don't want to write to debug.log file
3233
SelectParams(CBaseChainParams::MAIN);
3334
}

src/util.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -723,18 +723,19 @@ void RenameThread(const char* name)
723723

724724
void SetupEnvironment()
725725
{
726+
std::locale loc("C");
726727
// On most POSIX systems (e.g. Linux, but not BSD) the environment's locale
727728
// may be invalid, in which case the "C" locale is used as fallback.
728729
#if !defined(WIN32) && !defined(MAC_OSX) && !defined(__FreeBSD__) && !defined(__OpenBSD__)
729730
try {
730-
std::locale(""); // Raises a runtime error if current locale is invalid
731+
loc = std::locale(""); // Raises a runtime error if current locale is invalid
731732
} catch (const std::runtime_error&) {
732-
std::locale::global(std::locale("C"));
733+
setenv("LC_ALL", "C", 1);
733734
}
734735
#endif
735736
// The path locale is lazy initialized and to avoid deinitialization errors
736737
// in multithreading environments, it is set explicitly by the main thread.
737-
boost::filesystem::path::imbue(std::locale());
738+
boost::filesystem::path::imbue(loc);
738739
}
739740

740741
void SetThreadPriority(int nPriority)

0 commit comments

Comments
 (0)