Skip to content

Commit

Permalink
Fix googletest rebase errors
Browse files Browse the repository at this point in the history
Make googletests use the new compiler calling convention
use `compile(source, options, scrip, messages)`
  • Loading branch information
fernewelten committed Sep 9, 2024
1 parent b084056 commit 6617e0a
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 70 deletions.
35 changes: 18 additions & 17 deletions Compiler/test2/cc_bytecode_test_0.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,9 @@ TEST_F(Bytecode0, P_r_o_t_o_t_y_p_e) {
return a*a; \n\
}";
int compileResult = cc_compile(inpl, scrip);
ASSERT_STREQ("Ok", (compileResult >= 0) ? "Ok" : last_seen_cc_error());
int compile_result = cc_compile(inpl, options, scrip, mh);
std::string err_msg = mh.GetError().Message;
ASSERT_STREQ("Ok", mh.HasError() ? err_msg.c_str() : "Ok");
// WriteOutput("P_r_o_t_o_t_y_p_e", scrip);
// run the test, comment out the previous line
Expand Down Expand Up @@ -256,9 +257,9 @@ TEST_F(Bytecode0, Float01) {
} \n\
";

MessageHandler mh;
int compile_result = cc_compile(inpl, 0, scrip, mh);
ASSERT_STREQ("Ok", (compile_result >= 0) ? "Ok" : mh.GetError().Message.c_str());
int compile_result = cc_compile(inpl, kNoOptions, scrip, mh);
std::string err_msg = mh.GetError().Message;
ASSERT_STREQ("Ok", mh.HasError() ? err_msg.c_str() : "Ok");
ASSERT_LE(1u, mh.GetMessages().size());
EXPECT_NE(std::string::npos, mh.GetMessages().at(0).Message.find("reach this point"));

Expand Down Expand Up @@ -1874,9 +1875,9 @@ TEST_F(Bytecode0, FlowSwitch06) {
} \n\
";

MessageHandler mh;
int compile_result = cc_compile(inpl, 0u, scrip, mh);
ASSERT_STREQ("Ok", (compile_result >= 0) ? "Ok" : mh.GetError().Message.c_str());
int compile_result = cc_compile(inpl, kNoOptions, scrip, mh);
std::string err_msg = mh.GetError().Message;
ASSERT_STREQ("Ok", mh.HasError() ? err_msg.c_str() : "Ok");
ASSERT_LE(1u, mh.GetMessages().size());
EXPECT_NE(std::string::npos, mh.GetMessages().at(0u).Message.find("execution"));
EXPECT_EQ(11u, mh.GetMessages().at(0u).Lineno);
Expand Down Expand Up @@ -2478,9 +2479,9 @@ TEST_F(Bytecode0, Struct05) {
} \n\
";

MessageHandler mh;
int compile_result = cc_compile(inpl, 0u, scrip, mh);
ASSERT_STREQ("Ok", (compile_result >= 0) ? "Ok" : mh.GetError().Message.c_str());
int compile_result = cc_compile(inpl, kNoOptions, scrip, mh);
std::string err_msg = mh.GetError().Message;
ASSERT_STREQ("Ok", mh.HasError() ? err_msg.c_str() : "Ok");
EXPECT_LE(2u, mh.GetMessages().size());
EXPECT_NE(std::string::npos, mh.GetMessages().at(0u).Message.find("zero"));
EXPECT_NE(std::string::npos, mh.GetMessages().at(1u).Message.find("zero"));
Expand Down Expand Up @@ -4144,9 +4145,9 @@ TEST_F(Bytecode0, Func12) {
} \n\
";

MessageHandler mh;
int compile_result = cc_compile(inpl, 0u, scrip, mh);
ASSERT_STREQ("Ok", (compile_result >= 0) ? "Ok" : mh.GetError().Message.c_str());
int compile_result = cc_compile(inpl, kNoOptions, scrip, mh);
std::string err_msg = mh.GetError().Message;
ASSERT_STREQ("Ok", mh.HasError() ? err_msg.c_str() : "Ok");
ASSERT_LE(1u, mh.GetMessages().size());
EXPECT_NE(std::string::npos, mh.GetMessages().at(0u).Message.find("'0'"));

Expand Down Expand Up @@ -4219,9 +4220,9 @@ TEST_F(Bytecode0, Func13) {
} \n\
";

MessageHandler mh;
int compile_result = cc_compile(inpl, 0u, scrip, mh);
ASSERT_STREQ("Ok", (compile_result >= 0) ? "Ok" : mh.GetError().Message.c_str());
int compile_result = cc_compile(inpl, kNoOptions, scrip, mh);
std::string err_msg = mh.GetError().Message;
ASSERT_STREQ("Ok", mh.HasError() ? err_msg.c_str() : "Ok");
ASSERT_LE(1u, mh.GetMessages().size());
EXPECT_NE(std::string::npos, mh.GetMessages().at(0u).Message.find("'0'"));

Expand Down
24 changes: 9 additions & 15 deletions Compiler/test2/cc_bytecode_test_1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1594,7 +1594,6 @@ TEST_F(Bytecode1, Attributes08) {

int compile_result = cc_compile(inpl, kNoOptions, scrip, mh);
std::string err_msg = mh.GetError().Message;
std::string msg = last_seen_cc_error();
ASSERT_STREQ("Ok", mh.HasError() ? err_msg.c_str() : "Ok");

// WriteOutput("Attributes08", scrip);
Expand Down Expand Up @@ -1672,7 +1671,6 @@ TEST_F(Bytecode1, Attributes09) {

int compile_result = cc_compile(inpl, kNoOptions, scrip, mh);
std::string err_msg = mh.GetError().Message;
std::string msg = last_seen_cc_error();
ASSERT_STREQ("Ok", mh.HasError() ? err_msg.c_str() : "Ok");

// WriteOutput("Attributes09", scrip);
Expand Down Expand Up @@ -1746,7 +1744,6 @@ TEST_F(Bytecode1, Attributes10) {

int compile_result = cc_compile(inpl, kNoOptions, scrip, mh);
std::string err_msg = mh.GetError().Message;
std::string msg = last_seen_cc_error();
ASSERT_STREQ("Ok", mh.HasError() ? err_msg.c_str() : "Ok");

// WriteOutput("Attributes10", scrip);
Expand Down Expand Up @@ -1834,7 +1831,6 @@ TEST_F(Bytecode1, Attributes11) {

int compile_result = cc_compile(inpl, kNoOptions, scrip, mh);
std::string err_msg = mh.GetError().Message;
std::string msg = last_seen_cc_error();
ASSERT_STREQ("Ok", mh.HasError() ? err_msg.c_str() : "Ok");

// WriteOutput("Attributes11", scrip);
Expand Down Expand Up @@ -2122,9 +2118,9 @@ TEST_F(Bytecode1, Ternary1) {
} \n\
";

MessageHandler mh;
int compileResult = cc_compile(inpl, 0, scrip, mh);
ASSERT_STREQ("Ok", (compileResult >= 0) ? "Ok" : mh.GetError().Message.c_str());
int compile_result = cc_compile(inpl, kNoOptions, scrip, mh);
std::string err_msg = mh.GetError().Message;
ASSERT_STREQ("Ok", mh.HasError() ? err_msg.c_str() : "Ok");
ASSERT_LE(1u, mh.GetMessages().size());
EXPECT_EQ(8, mh.GetMessages().at(0).Lineno);
EXPECT_NE(std::string::npos, mh.GetMessages().at(0).Message.find("reach"));
Expand Down Expand Up @@ -3483,10 +3479,9 @@ TEST_F(Bytecode1, Linenum01)
";


MessageHandler mh;
AGS::ccCompiledScript scrip{ true };
int compileResult = cc_compile(inpl, 0, scrip, mh);
ASSERT_STREQ("Ok", (compileResult >= 0) ? "Ok" : mh.GetError().Message.c_str());
int compile_result = cc_compile(inpl, kNoOptions, scrip, mh);
std::string err_msg = mh.GetError().Message;
ASSERT_STREQ("Ok", mh.HasError() ? err_msg.c_str() : "Ok");

// WriteOutput("Linenum01", scrip);

Expand Down Expand Up @@ -3530,10 +3525,9 @@ TEST_F(Bytecode1, Linenum02)
} \n\
";

MessageHandler mh;
AGS::ccCompiledScript scrip{ true };
int compileResult = cc_compile(inpl, 0, scrip, mh);
ASSERT_STREQ("Ok", (compileResult >= 0) ? "Ok" : mh.GetError().Message.c_str());
int compile_result = cc_compile(inpl, kNoOptions, scrip, mh);
std::string err_msg = mh.GetError().Message;
ASSERT_STREQ("Ok", mh.HasError() ? err_msg.c_str() : "Ok");

// WriteOutput("Linenum02", scrip);

Expand Down
97 changes: 59 additions & 38 deletions Compiler/test2/cc_parser_test_1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -804,10 +804,12 @@ TEST_F(Compile1, FuncReturnStruct2) {
} \n\
";

MessageHandler mh;
int compile_result = cc_compile(inpl, 0u, scrip, mh);
ASSERT_STREQ("Ok", (compile_result >= 0) ? "Ok" : mh.GetError().Message.c_str());
ASSERT_LE(1u, mh.GetMessages().size());
int compile_result = cc_compile(inpl, kNoOptions, scrip, mh);
std::string err_msg = mh.GetError().Message;
size_t err_line = mh.GetError().Lineno;
EXPECT_LE(1u, mh.WarningsCount());

ASSERT_STREQ("Ok", mh.HasError() ? err_msg.c_str() : "Ok");
EXPECT_NE(std::string::npos, mh.GetMessages().at(0).Message.find("return"));
}

Expand All @@ -822,10 +824,12 @@ TEST_F(Compile1, FuncReturnStruct3) {
} \n\
";

MessageHandler mh;
int compile_result = cc_compile(inpl, 0u, scrip, mh);
ASSERT_STREQ("Ok", (compile_result >= 0) ? "Ok" : mh.GetError().Message.c_str());
ASSERT_LE(1u, mh.GetMessages().size());
int compile_result = cc_compile(inpl, kNoOptions, scrip, mh);
std::string err_msg = mh.GetError().Message;
size_t err_line = mh.GetError().Lineno;
EXPECT_LE(1u, mh.WarningsCount());

ASSERT_STREQ("Ok", mh.HasError() ? err_msg.c_str() : "Ok");
EXPECT_NE(std::string::npos, mh.GetMessages().at(0).Message.find("return"));
}

Expand All @@ -846,10 +850,12 @@ TEST_F(Compile1, FuncReturn1) {
} \n\
";

MessageHandler mh;
int compile_result = cc_compile(inpl, 0u, scrip, mh);
ASSERT_STREQ("Ok", (compile_result >= 0) ? "Ok" : mh.GetError().Message.c_str());
ASSERT_LE(1u, mh.GetMessages().size());
int compile_result = cc_compile(inpl, kNoOptions, scrip, mh);
std::string err_msg = mh.GetError().Message;
size_t err_line = mh.GetError().Lineno;
EXPECT_LE(1u, mh.WarningsCount());

ASSERT_STREQ("Ok", mh.HasError() ? err_msg.c_str() : "Ok");
EXPECT_NE(std::string::npos, mh.GetMessages().at(0).Message.find("Code execution"));
}

Expand All @@ -873,10 +879,12 @@ TEST_F(Compile1, FuncReturn2) {
} \n\
";

MessageHandler mh;
int compile_result = cc_compile(inpl, 0u, scrip, mh);
ASSERT_STREQ("Ok", (compile_result >= 0) ? "Ok" : mh.GetError().Message.c_str());
ASSERT_LE(1u, mh.GetMessages().size());
int compile_result = cc_compile(inpl, kNoOptions, scrip, mh);
std::string err_msg = mh.GetError().Message;
size_t err_line = mh.GetError().Lineno;
EXPECT_LE(1u, mh.WarningsCount());

ASSERT_STREQ("Ok", mh.HasError() ? err_msg.c_str() : "Ok");
EXPECT_NE(std::string::npos, mh.GetMessages().at(0).Message.find("Code execution"));
}

Expand Down Expand Up @@ -1282,8 +1290,7 @@ TEST_F(Compile1, FuncUndeclaredStruct1) {
EXPECT_EQ(0u, mh.WarningsCount());

ASSERT_STRNE("Ok", mh.HasError() ? err_msg.c_str() : "Ok");
std::string message = err_msg;
EXPECT_NE(std::string::npos, message.find("Func"));
EXPECT_NE(std::string::npos, err_msg.find("Func"));
}

TEST_F(Compile1, FuncUndeclaredStruct2) {
Expand Down Expand Up @@ -2104,8 +2111,7 @@ TEST_F(Compile1, SpuriousExpression)
} \n\
";

MessageHandler mh;
int compile_result = cc_compile(inpl, 0, scrip, mh);
int compile_result = cc_compile(inpl, kNoOptions, scrip, mh);
std::string err_msg = mh.GetError().Message;
size_t err_line = mh.GetError().Lineno;

Expand Down Expand Up @@ -2209,10 +2215,12 @@ TEST_F(Compile1, SideEffectExpression1)
} \n\
";

AGS::MessageHandler mh;
int const compile_result = cc_compile(inpl, 0, scrip, mh);
ASSERT_STREQ("Ok", (compile_result >= 0) ? "Ok" : mh.GetError().Message.c_str());
ASSERT_EQ(0u, mh.GetMessages().size());
int const compile_result = cc_compile(inpl, kNoOptions, scrip, mh);
std::string err_msg = mh.GetError().Message;
size_t err_line = mh.GetError().Lineno;
EXPECT_EQ(0u, mh.WarningsCount());

ASSERT_STREQ("Ok", mh.HasError() ? err_msg.c_str() : "Ok");
}

TEST_F(Compile1, SideEffectExpression2)
Expand All @@ -2230,10 +2238,13 @@ TEST_F(Compile1, SideEffectExpression2)
} \n\
";

AGS::MessageHandler mh;
int const compile_result = cc_compile(inpl, 0, scrip, mh);
ASSERT_STRNE("Ok", (compile_result >= 0) ? "Ok" : mh.GetError().Message.c_str());
EXPECT_NE(std::string::npos, mh.GetError().Message.find("'('"));
int const compile_result = cc_compile(inpl, kNoOptions, scrip, mh);
std::string err_msg = mh.GetError().Message;
size_t err_line = mh.GetError().Lineno;
EXPECT_EQ(0u, mh.WarningsCount());

ASSERT_STRNE("Ok", mh.HasError() ? err_msg.c_str() : "Ok");
EXPECT_NE(std::string::npos, err_msg.find("'('"));
}

TEST_F(Compile1, SideEffectExpression3)
Expand All @@ -2252,10 +2263,13 @@ TEST_F(Compile1, SideEffectExpression3)
} \n\
";

AGS::MessageHandler mh;
int const compile_result = cc_compile(inpl, 0, scrip, mh);
ASSERT_STRNE("Ok", (compile_result >= 0) ? "Ok" : mh.GetError().Message.c_str());
EXPECT_NE(std::string::npos, mh.GetError().Message.find("'('"));
int const compile_result = cc_compile(inpl, kNoOptions, scrip, mh);
std::string err_msg = mh.GetError().Message;
size_t err_line = mh.GetError().Lineno;
EXPECT_EQ(0u, mh.WarningsCount());

ASSERT_STRNE("Ok", mh.HasError() ? err_msg.c_str() : "Ok");
EXPECT_NE(std::string::npos, err_msg.find("'('"));
}

TEST_F(Compile1, SideEffectExpression4)
Expand All @@ -2274,9 +2288,13 @@ TEST_F(Compile1, SideEffectExpression4)
} \n\
";

AGS::MessageHandler mh;
int const compile_result = cc_compile(inpl, 0, scrip, mh);
ASSERT_STRNE("Ok", (compile_result >= 0) ? "Ok" : mh.GetError().Message.c_str());

int const compile_result = cc_compile(inpl, kNoOptions, scrip, mh);
std::string err_msg = mh.GetError().Message;
size_t err_line = mh.GetError().Lineno;
EXPECT_EQ(0u, mh.WarningsCount());

ASSERT_STRNE("Ok", mh.HasError() ? err_msg.c_str() : "Ok");
}

TEST_F(Compile1, DisallowStaticVariables)
Expand Down Expand Up @@ -2476,15 +2494,18 @@ TEST_F(Compile1, ParensAfterNew) {

AGS::MessageHandler mh;
int compile_result = cc_compile(inpl, 0u, scrip, mh);
ASSERT_STREQ("Ok", (compile_result >= 0) ? "Ok" : mh.GetError().Message.c_str());
ASSERT_EQ(1u, mh.GetMessages().size());
std::string err_msg = mh.GetError().Message;
size_t err_line = mh.GetError().Lineno;
EXPECT_EQ(1u, mh.WarningsCount());

ASSERT_STREQ("Ok", mh.HasError() ? err_msg.c_str() : "Ok");
}

TEST_F(Compile1, DynarrayOfArray) {

// Refuse a dynarray of an array

const char *inpl = "\
char const *inpl = "\
int game_start() \n\
{ \n\
float Test[][5, 7]; \n\
Expand Down

0 comments on commit 6617e0a

Please sign in to comment.