commit 85578a4e2e5d096bb9ebb055282612f9b9f19476
Author: Jon Bell <jondbell@protonmail.com>
AuthorDate: Wed Apr 15 09:44:26 2020 -0600
Commit: Jon Bell <jondbell@protonmail.com>
CommitDate: Wed Apr 15 09:44:26 2020 -0600
work on tests and excluding them from non test builds
---
source/cart.cpp | 18 ++----------------
source/main.cpp | 5 +----
source/tests/cart_test.cpp | 39 +++++++++++----------------------------
source/tests/cart_test.h | 6 ++++++
source/tests/test_base.cpp | 30 ++++++++++++++++++++++++++++++
source/tests/test_base.h | 17 +++++++++++++++++
source/tests/test_switch.h | 4 ----
7 files changed, 67 insertions(+), 52 deletions(-)
diff --git a/source/cart.cpp b/source/cart.cpp
index 568407e..27261f3 100644
--- a/source/cart.cpp
+++ b/source/cart.cpp
@@ -6,7 +6,7 @@
#include "utils.h"
-#include "tests/test_switch.h"
+#include "tests/test_base.h"
#if _TEST
#include "tests/cart_test.h"
#endif
@@ -19,6 +19,7 @@ void LoadCart(std::string filename){
std::string lua = "";
std::string spritesheet = "";
std::string currSec = "";
+
while (std::getline(s, line)) {
line = utils::trimright(line, " \n\r");
@@ -31,21 +32,6 @@ void LoadCart(std::string filename){
else if (currSec == "__gfx__"){
spritesheet += line + "\n";
}
-
- /*
- if (!check_include_file(line, cart, filenum)) {
- if (valid_sections.find(line) != valid_sections.end()) {
- cart.sections["cur_sect"] = line;
- logr << "section " << line;
- } else {
- if (cart.sections["cur_sect"] == "__lua__") {
- cart.source.push_back(Line{filenum, line});
- } else {
- cart.sections[cart.sections["cur_sect"]] += line + "\n";
- }
- }
- }
- */
}
diff --git a/source/main.cpp b/source/main.cpp
index f6460f1..cd916dd 100644
--- a/source/main.cpp
+++ b/source/main.cpp
@@ -12,7 +12,7 @@
#include "picointernals.h"
//this has the macro _TEST defined in it
-#include "tests/test_switch.h"
+#include "tests/test_base.h"
int main(int argc, char* argv[])
{
@@ -26,9 +26,6 @@ int main(int argc, char* argv[])
int bgcolor = 255;
consoleInit(GFX_BOTTOM, NULL);
- printf("testing console printing\n");
- printf("bgcolor %d\n", bgcolor);
-
loadcart("testcart.p8");
#else
diff --git a/source/tests/cart_test.cpp b/source/tests/cart_test.cpp
index e414e1f..6824ec1 100644
--- a/source/tests/cart_test.cpp
+++ b/source/tests/cart_test.cpp
@@ -1,9 +1,14 @@
-#include <stdio.h>
+
+#include "test_base.h"
+
+#if _TEST
#include <string>
#include "cart_test.h"
+
+
const char* full_cart_text = R"(pico-8 cartridge // http://www.pico-8.com
version 18
__lua__
@@ -97,15 +102,7 @@ e0000000000000000000000007700770000770000000000000000000000660005000000500000000
)";
bool verifyFullCartText(std::string cartText){
- bool equal = cartText == full_cart_text;
- if (equal) {
- printf("Full Cart Text: PASS;\n");
- }
- else {
- printf("Full Cart Text: FAIL;\n");
- }
-
- return equal;
+ return assertStringsEqual(full_cart_text, cartText, "Full Cart Text");
}
const char* expected_lua_text = R"(local r1x0 = 10
@@ -181,15 +178,7 @@ end
)";
bool verifyLuaText(std::string luaText){
- bool equal = luaText == expected_lua_text;
- if (equal) {
- printf("Lua Text: PASS;\n");
- }
- else {
- printf("Lua Text: FAIL;\n");
- }
-
- return equal;
+ return assertStringsEqual(expected_lua_text, luaText, "Lua Text");
}
const char* expected_spritesheet_text = R"(e0000000000000000000000007700770000770000000000000000000000660005000000500000000000000000000000000000000000000000000000000000000
@@ -211,13 +200,7 @@ const char* expected_spritesheet_text = R"(e000000000000000000000000770077000077
)";
bool verifySpriteSheetText(std::string spritesheet) {
- bool equal = spritesheet == expected_spritesheet_text;
- if (equal) {
- printf("Spritesheet Text: PASS;\n");
- }
- else {
- printf("Spritesheet Text: FAIL;\n");
- }
-
- return equal;
+ return assertStringsEqual(expected_spritesheet_text, spritesheet, "Spritesheet Text");
}
+
+#endif
diff --git a/source/tests/cart_test.h b/source/tests/cart_test.h
index 5885460..5f1fa6a 100644
--- a/source/tests/cart_test.h
+++ b/source/tests/cart_test.h
@@ -1,3 +1,7 @@
+#include "test_base.h"
+
+#if _TEST
+
#pragma once
#include <string>
@@ -5,3 +9,5 @@
bool verifyFullCartText(std::string cartText);
bool verifyLuaText(std::string luaText);
bool verifySpriteSheetText(std::string spritesheet);
+
+#endif
diff --git a/source/tests/test_base.cpp b/source/tests/test_base.cpp
new file mode 100644
index 0000000..c5f7501
--- /dev/null
+++ b/source/tests/test_base.cpp
@@ -0,0 +1,30 @@
+#include "test_base.h"
+
+#if _TEST
+
+
+#include <string>
+#include <sstream>
+
+bool assertStringsEqual(std::string expected, std::string actual, std::string testName){
+ bool equal = expected == actual;
+ printTestOuput(testName, equal);
+
+ return equal;
+}
+
+void printTestOuput(std::string testName, bool success) {
+ #if _PRINT_SUCCESS
+ bool print = true;
+ #else
+ bool print = !success;
+ #endif
+
+ if (print) {
+ std::stringstream output;
+ std::string status = success ? "PASS" : "FAIL";
+ output << testName << ": " << status << "\n";
+ printf(output.str().c_str());
+ }
+}
+#endif
\ No newline at end of file
diff --git a/source/tests/test_base.h b/source/tests/test_base.h
new file mode 100644
index 0000000..1471fc3
--- /dev/null
+++ b/source/tests/test_base.h
@@ -0,0 +1,17 @@
+#pragma once
+
+//if this is set to 1, test cases will be run on the test cart
+#define _TEST 1
+
+//if this flag is set, only failures get printed to console
+#define _PRINT_SUCCESS 1
+
+#if _TEST
+
+#include <string>
+
+bool assertStringsEqual(std::string expected, std::string actual, std::string testName);
+
+void printTestOuput(std::string testName, bool success);
+
+#endif
\ No newline at end of file
diff --git a/source/tests/test_switch.h b/source/tests/test_switch.h
deleted file mode 100644
index 1774f75..0000000
--- a/source/tests/test_switch.h
+++ /dev/null
@@ -1,4 +0,0 @@
-#pragma once
-
-//if this is set to 1, test cases will be run on the test cart
-#define _TEST 1