foxygit / fake-08-xbox360 Log in
commit bcf838be3bd03bec4e0e8a99cc128aff5067dfde
Author:     Jon Bell <j.to.the.bell@gmail.com>
AuthorDate: Sat Jun 25 18:52:00 2022 -0600
Commit:     Jon Bell <j.to.the.bell@gmail.com>
CommitDate: Sat Jun 25 18:52:00 2022 -0600

    Get errors from carts that do load
---
 source/filehelpers.cpp    |  5 +++++
 source/filehelpers.h      |  2 ++
 test/cartloadingtest.cpp  | 10 +++++++++-
 test/filehelperstests.cpp | 24 ++++++++++++++++++++++++
 4 files changed, 40 insertions(+), 1 deletion(-)

diff --git a/source/filehelpers.cpp b/source/filehelpers.cpp
index 267d928..50099d1 100644
--- a/source/filehelpers.cpp
+++ b/source/filehelpers.cpp
@@ -101,3 +101,8 @@ bool isCartFile (std::string const &fullString) {
         (hasEnding(fullString, ".p8") || hasEnding(fullString, ".png"));
 }

+bool isCPostFile (std::string const &fullString) {
+    return !isHiddenFile(fullString) &&
+       fullString.rfind("cpost", 0) == 0;
+}
+
diff --git a/source/filehelpers.h b/source/filehelpers.h
index e8ec73d..a4c9b02 100644
--- a/source/filehelpers.h
+++ b/source/filehelpers.h
@@ -10,6 +10,8 @@ bool hasEnding (std::string const &fullString, std::string const &ending);

 bool isCartFile (std::string const &fullString);

+bool isCPostFile (std::string const &fullString);
+
 bool isHiddenFile (std::string const &fullString);

 bool isAbsolutePath (std::string const &path);
diff --git a/test/cartloadingtest.cpp b/test/cartloadingtest.cpp
index a867bf0..bc61caf 100644
--- a/test/cartloadingtest.cpp
+++ b/test/cartloadingtest.cpp
@@ -529,7 +529,9 @@ TEST_CASE("Loading and running carts") {
     if ((dir = opendir (_cartDirectory.c_str())) != NULL) {
         /* print all the files and directories within directory */
         while ((ent = readdir (dir)) != NULL) {
-            if (isCartFile(ent->d_name) && std::find(cartsToIgnore.begin(), cartsToIgnore.end(), ent->d_name) == cartsToIgnore.end()){
+            if (isCartFile(ent->d_name)
+                && ! isCPostFile(ent->d_name)
+                && std::find(cartsToIgnore.begin(), cartsToIgnore.end(), ent->d_name) == cartsToIgnore.end()) {
                 carts.push_back(ent->d_name);
             }
         }
@@ -567,6 +569,12 @@ TEST_CASE("Loading and running carts") {
             errors.push_back(carts[i] + ": Timeout" + e.what());
         }
     }
+
+    printf("\n");
+    printf("ERRORS:\n");
+    for (int i = 0; i < errors.size(); i++) {
+        printf("%s\n", errors[i].c_str());
+    }

     delete vm;
     delete host;
diff --git a/test/filehelperstests.cpp b/test/filehelperstests.cpp
index 2db6d1a..e8fcb80 100644
--- a/test/filehelperstests.cpp
+++ b/test/filehelperstests.cpp
@@ -135,3 +135,27 @@ TEST_CASE("get_first_four_chars") {
         CHECK_EQ(get_first_four_chars("carts/test_legacypng_cart.p8.png"), "\x89PNG");
     }
 }
+
+TEST_CASE("isCPostFile") {
+    SUBCASE("empty string") {
+        CHECK_EQ(isCPostFile(""), false);
+    }
+    SUBCASE("filename no etension") {
+        CHECK_EQ(isCPostFile("file"), false);
+    }
+    SUBCASE("cart file") {
+        CHECK_EQ(isCPostFile("cart.p8"), false);
+    }
+    SUBCASE("filename with etension") {
+        CHECK_EQ(isCPostFile("cpost1234.png"), true);
+    }
+    SUBCASE("hidden file") {
+        CHECK_EQ(isCPostFile(".bash_rc"), false);
+    }
+    SUBCASE("macOS filesystem thing p8") {
+        CHECK_EQ(isCPostFile("._cpost1234.p8"), false);
+    }
+    SUBCASE("macOS filesystem thing png") {
+        CHECK_EQ(isCPostFile("._cpost1234.p8.png"), false);
+    }
+}