Previously I was tracking that I was getting the line number of the executable line one previous to where I expected when passing a value of 1. Now I'm getting the line number of the executable line after what I expect.
I'm using AS 2.23.1 currently. I do not rem I know, I do need to upgrade... Will likely catch it in 2.24.1 as working on a mess of other things at the moment - and 2.24.1 will likely contain the Xcode/Clang fixes I'm currently patching in manually.
Here's what I'm doing in C++:
std::string GetPreviousCallstackLine(const unsigned int& callstack_line_number) {
asIScriptContext* ctx = asGetActiveContext();
std::string result;
if (ctx != nullptr && callstack_line_number < ctx->GetCallstackSize()) {
asIScriptFunction* func;
const char* script_section;
int line, column;
func = ctx->GetFunction(callstack_line_number);
line = ctx->GetLineNumber(callstack_line_number, &column, &script_section);
result = std::string(script_section) + "(" + boost::lexical_cast<std::string>(line) + "):" + std::string(func->GetDeclaration());
}
return result;
}
// ... over in registration
ret = this->engine->SetDefaultNamespace("Engine::Debug"); assert(ret >= 0);
ret = this->engine->RegisterGlobalFunction("string GetPreviousCallstackLine(const uint &in a = 1)", asFUNCTION(GetPreviousCallstackLine), asCALL_CDECL); assert(ret >= 0);
// ...
And my use in AS is as such:
namespace UnitTest {
// ...
void EXPECT_TRUE (const bool&in a, string message = "") { if (!a) { Engine::LOG(Engine::LOG_PRIORITY::ERR, "EXPECT_TRUE failed in " + Engine::Debug::GetPreviousCallstackLine() + "! " + message); gTestStatus = false; } }
// ... This I will line number with arbitrary numbers for our reference:
100: EXPECT_TRUE(true);
101:
102: EXPECT_TRUE(false);
103: // Just another blank line
104: EXPECT_TRUE(true);
105:
107: EXPECT_TRUE(false);
I expect to have a message in my logger stating a line number of 102 for the first invalid test. In the past I instead got line 100, line 101 being skipped because it is blank. Currently I get line 104. Now, this is a trivial example, but it demonstrates what I've observed from the output of many variations. EXPECT_EQ, EXPECT_NE, and many other such functions all exhibit the same behavior, and it matter not what the previous or next executable line is: they could be a simple 0 + 0 and the system would show the same oddity.
Of course if I set the passed value to 0, the reported line is the line where Engine::Debug::GetPreviousCallstackLine() is called - as expected. If I set it to 2 it currently reports the line of execution one step even further in the future - though I thought the past would be a lot more defined.
-- EDIT --
GetPreviousCallstackLine(const uint &in a = 1) was GetPreviousCallstackLine(const uint &in a = 2)
The actual value used in my tests was 1, the 2 was spurious, coming from me exploring the system.