From 6c0b329d57353175ce0c357a93db81f01e5c2f2d Mon Sep 17 00:00:00 2001 From: Brian Fiete Date: Wed, 3 Nov 2021 11:05:31 -0700 Subject: [PATCH] Fixed test ShouldFail cases --- BeefRT/rt/Internal.cpp | 37 ++++++++++++++++++++++++++----------- BeefySysLib/util/String.cpp | 10 ++++++++++ BeefySysLib/util/String.h | 1 + IDE/src/TestManager.bf | 2 +- 4 files changed, 38 insertions(+), 12 deletions(-) diff --git a/BeefRT/rt/Internal.cpp b/BeefRT/rt/Internal.cpp index a453ea43..51f66c1f 100644 --- a/BeefRT/rt/Internal.cpp +++ b/BeefRT/rt/Internal.cpp @@ -214,18 +214,20 @@ static void TestReadCmd(Beefy::String& str); static void Internal_FatalError(const char* error) { - if (gClientPipe != NULL) + if ((gClientPipe != NULL) && (!gTestBreakOnFailure)) { Beefy::String str = ":TestFatal\t"; str += error; + str.Replace('\n', '\r'); str += "\n"; TestString(str); Beefy::String result; - TestReadCmd(result); + TestReadCmd(result); + exit(1); } - - BfpSystem_FatalError(error, "BEEF FATAL ERROR"); + else + BfpSystem_FatalError(error, "BEEF FATAL ERROR"); } extern "C" BFRT_EXPORT int BF_CALLTYPE ftoa(float val, char* str) @@ -396,6 +398,13 @@ void* Internal::UnsafeCastToPtr(Object* obj) void Internal::ThrowIndexOutOfRange(intptr stackOffset) { + if (gClientPipe != NULL) + { + Beefy::String str = ":TestFail\tIndex out of range\n"; + TestString(str); + exit(1); + } + if ((stackOffset != -1) && (::IsDebuggerPresent())) { SETUP_ERROR("Index out of range", (int)(2 + stackOffset)); @@ -406,7 +415,17 @@ void Internal::ThrowIndexOutOfRange(intptr stackOffset) } void Internal::FatalError(bf::System::String* error, intptr stackOffset) -{ +{ + if (gClientPipe != NULL) + { + Beefy::String str = ":TestFail\t"; + str += error->CStr(); + str.Replace('\n', '\r'); + str += "\n"; + TestString(str); + exit(1); + } + if ((stackOffset != -1) && (::IsDebuggerPresent())) { SETUP_ERROR(error->CStr(), (int)(2 + stackOffset)); @@ -640,6 +659,7 @@ void Internal::Test_Error(char* error) { Beefy::String str = ":TestFail\t"; str += error; + str.Replace('\n', '\r'); str += "\n"; TestString(str); } @@ -651,12 +671,7 @@ void Internal::Test_Write(char* strPtr) { Beefy::String str = ":TestWrite\t"; str += strPtr; - for (char& c : str) - { - if (c == '\n') - c = '\r'; - } - + str.Replace('\n', '\r'); str += "\n"; TestString(str); } diff --git a/BeefySysLib/util/String.cpp b/BeefySysLib/util/String.cpp index 0e1c41d3..a64766bc 100644 --- a/BeefySysLib/util/String.cpp +++ b/BeefySysLib/util/String.cpp @@ -690,6 +690,16 @@ void StringImpl::ReplaceLargerHelper(const StringView& find, const StringView& r mLength = (int_strsize)destLength; } +void StringImpl::Replace(char find, char replace) +{ + auto ptr = GetMutablePtr(); + for (int i = 0; i < mLength; i++) + { + if (ptr[i] == find) + ptr[i] = replace; + } +} + void StringImpl::Replace(const StringView& find, const StringView & replace) { if (replace.mLength > find.mLength) diff --git a/BeefySysLib/util/String.h b/BeefySysLib/util/String.h index 231ed50c..3d7d8299 100644 --- a/BeefySysLib/util/String.h +++ b/BeefySysLib/util/String.h @@ -1015,6 +1015,7 @@ public: } void ReplaceLargerHelper(const StringView& find, const StringView& replace); + void Replace(char find, char replace); void Replace(const StringView& find, const StringView& replace); void TrimEnd(); void TrimStart(); diff --git a/IDE/src/TestManager.bf b/IDE/src/TestManager.bf index 1bb59775..e3c4bdb2 100644 --- a/IDE/src/TestManager.bf +++ b/IDE/src/TestManager.bf @@ -301,7 +301,7 @@ namespace IDE testEntry.mExecuted = true; String clientCmd = scope $":TestRun\t{testInstance.mCurTestIdx}"; - if ((gApp.mTestBreakOnFailure) && (mDebug)) + if ((gApp.mTestBreakOnFailure) && (mDebug) && (!testEntry.mShouldFail)) clientCmd.Append("\tFailBreak"); clientCmd.Append("\n");