From 7a54464a8b8dc59a15d7ededb39e865650bbf098 Mon Sep 17 00:00:00 2001 From: Alek Mosingiewicz Date: Tue, 3 Apr 2018 17:51:16 +0200 Subject: [PATCH 1/5] Warn against environmental variables not set in test. --- unittests/multithreaded_test.cpp | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/unittests/multithreaded_test.cpp b/unittests/multithreaded_test.cpp index e2d0240b..670ccc6d 100644 --- a/unittests/multithreaded_test.cpp +++ b/unittests/multithreaded_test.cpp @@ -47,16 +47,26 @@ int main() const char *usepath = getenv("CHAI_USE_PATH"); const char *modulepath = getenv("CHAI_MODULE_PATH"); + + if(usepath == nullptr) + { + std::cout << "Warning: usepath not set!\n"; + } + + if(modulepath == nullptr) + { + std::cout << "Warning: modulepath not set!\n"; + } #ifdef CHAISCRIPT_MSVC #pragma warning(pop) #endif std::vector usepaths; - usepaths.push_back(""); + usepaths.emplace_back(""); if (usepath) { - usepaths.push_back(usepath); + usepaths.emplace_back(usepath); } std::vector modulepaths; @@ -64,10 +74,10 @@ int main() #ifdef CHAISCRIPT_NO_DYNLOAD chaiscript::ChaiScript chai(/* unused */modulepaths, usepaths); #else - modulepaths.push_back(""); + modulepaths.emplace_back(""); if (modulepath) { - modulepaths.push_back(modulepath); + modulepaths.emplace_back(modulepath); } // For this test we are going to load the dynamic stdlib From 12291d4f317e40fa41118b883287b0d68d9353d9 Mon Sep 17 00:00:00 2001 From: Alek Mosingiewicz Date: Tue, 3 Apr 2018 18:00:25 +0200 Subject: [PATCH 2/5] Warn against environmental variables not set in test - make it better. --- unittests/multithreaded_test.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/unittests/multithreaded_test.cpp b/unittests/multithreaded_test.cpp index 670ccc6d..59b19883 100644 --- a/unittests/multithreaded_test.cpp +++ b/unittests/multithreaded_test.cpp @@ -47,15 +47,16 @@ int main() const char *usepath = getenv("CHAI_USE_PATH"); const char *modulepath = getenv("CHAI_MODULE_PATH"); + const char *this_might_affect_test_result = "This might have adverse effect on the result of the test."; if(usepath == nullptr) { - std::cout << "Warning: usepath not set!\n"; + std::cout << "Warning: environmental variable CHAI_USE_PATH not set! " << this_might_affect_test_result << "\n"; } if(modulepath == nullptr) { - std::cout << "Warning: modulepath not set!\n"; + std::cout << "Warning: environmental variable CHAI_MODULE_PATH not set! " << this_might_affect_test_result; } #ifdef CHAISCRIPT_MSVC From 581561cb8862bb16495859af01136fa6e8eb20c3 Mon Sep 17 00:00:00 2001 From: Alek Mosingiewicz Date: Tue, 3 Apr 2018 18:02:19 +0200 Subject: [PATCH 3/5] Added missing newline. --- unittests/multithreaded_test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/unittests/multithreaded_test.cpp b/unittests/multithreaded_test.cpp index 59b19883..483afe0d 100644 --- a/unittests/multithreaded_test.cpp +++ b/unittests/multithreaded_test.cpp @@ -56,7 +56,7 @@ int main() if(modulepath == nullptr) { - std::cout << "Warning: environmental variable CHAI_MODULE_PATH not set! " << this_might_affect_test_result; + std::cout << "Warning: environmental variable CHAI_MODULE_PATH not set! " << this_might_affect_test_result << "\n"; } #ifdef CHAISCRIPT_MSVC From 49edbdc00bab220068302f784af6fa3d67c73b08 Mon Sep 17 00:00:00 2001 From: Alek Mosingiewicz Date: Tue, 3 Apr 2018 18:26:45 +0200 Subject: [PATCH 4/5] Actually catch the exception? --- unittests/multithreaded_test.cpp | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/unittests/multithreaded_test.cpp b/unittests/multithreaded_test.cpp index 483afe0d..9ff70da2 100644 --- a/unittests/multithreaded_test.cpp +++ b/unittests/multithreaded_test.cpp @@ -111,15 +111,22 @@ int main() { std::stringstream ss; ss << i; - if (chai.eval("getvalue(" + ss.str() + ")") != expected_value(4000)) + try { + if (chai.eval("getvalue(" + ss.str() + ")") != expected_value(4000)) + { + return EXIT_FAILURE; + } + + if (chai.eval("getid(" + ss.str() + ")") != static_cast(i)) + { + return EXIT_FAILURE; + } + } catch (chaiscript::exception::eval_error &e) { + std::cout << e.what(); return EXIT_FAILURE; } - if (chai.eval("getid(" + ss.str() + ")") != static_cast(i)) - { - return EXIT_FAILURE; - } } return EXIT_SUCCESS; From 13374013d7c2ea50c8c872d5c60dbc595bd97af9 Mon Sep 17 00:00:00 2001 From: Alek Mosingiewicz Date: Tue, 3 Apr 2018 18:45:15 +0200 Subject: [PATCH 5/5] Revert some of the recommended changes - perhaps to blame for CI not passing. --- unittests/multithreaded_test.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/unittests/multithreaded_test.cpp b/unittests/multithreaded_test.cpp index 9ff70da2..b208c3fd 100644 --- a/unittests/multithreaded_test.cpp +++ b/unittests/multithreaded_test.cpp @@ -49,12 +49,12 @@ int main() const char *modulepath = getenv("CHAI_MODULE_PATH"); const char *this_might_affect_test_result = "This might have adverse effect on the result of the test."; - if(usepath == nullptr) + if(usepath == NULL) { std::cout << "Warning: environmental variable CHAI_USE_PATH not set! " << this_might_affect_test_result << "\n"; } - if(modulepath == nullptr) + if(modulepath == NULL) { std::cout << "Warning: environmental variable CHAI_MODULE_PATH not set! " << this_might_affect_test_result << "\n"; } @@ -67,7 +67,7 @@ int main() usepaths.emplace_back(""); if (usepath) { - usepaths.emplace_back(usepath); + usepaths.push_back(usepath); } std::vector modulepaths; @@ -75,10 +75,10 @@ int main() #ifdef CHAISCRIPT_NO_DYNLOAD chaiscript::ChaiScript chai(/* unused */modulepaths, usepaths); #else - modulepaths.emplace_back(""); + modulepaths.push_back(""); if (modulepath) { - modulepaths.emplace_back(modulepath); + modulepaths.push_back(modulepath); } // For this test we are going to load the dynamic stdlib