commit 65531b4bc408733b937ab11a30dc180ef7484fff
parent 148b137f1829d5b63cfdfdd2257b95bc9a022d28
Author: Andrew Laack <andrew@laack.co>
Date: Thu, 1 Oct 2026 11:39:19 -0500
Refactoring to reduce dependence on network connections in tests
Diffstat:
6 files changed, 58 insertions(+), 78 deletions(-)
diff --git a/Makefile b/Makefile
@@ -1,5 +1,9 @@
include config.mk
+# this must be started and running before running tests that do network connections
+server:
+ python3 -m jetforce --dir tests
+
debug:
${DCOMMAND_P} src/main.cpp ${DCOMMAND_S} -o foreseen.out
diff --git a/TODO.txt b/TODO.txt
@@ -172,3 +172,9 @@
- imports
- tests
- remove useless ones
+
+---
+
+Bug:
+
+- can't open localhost from the 'o' menu
diff --git a/tests/browser-test.cpp b/tests/browser-test.cpp
@@ -27,7 +27,6 @@ std::string genRandom(const int len) {
}
-// TODO: Refactor this to use $HOME
TEST_CASE( "Basic rendering of all line types" ) {
Browser b{};
std::string cwd = std::filesystem::current_path();
@@ -93,7 +92,7 @@ TEST_CASE("Test browser doesn't crash on invalid sites.") {
TEST_CASE("Test browser doesn't crash when accessing sites with specified port number that is not responsive.") {
Browser b{};
- bool res = b.goToSite("gemini://laack.co:3847");
+ bool res = b.goToSite("gemini://localhost:3847");
REQUIRE(!res);
b.goForward();
b.goBack();
@@ -103,17 +102,17 @@ TEST_CASE("Test browser doesn't crash when accessing sites with specified port n
TEST_CASE("Test browser can access sites with specified (default) port number.") {
Browser b{};
- b.goToSite("gemini://laack.co:1965");
- REQUIRE(b.getCurrentSite()->getMeta() == "text/gemini;lang=en-US");
+ b.goToSite("gemini://localhost:1965");
+ REQUIRE(b.getCurrentSite()->getMeta() == "text/gemini");
}
// TODO: Test invalid meta lines (like the case where weird stuff is sent from server)
TEST_CASE("Test browser returns proper meta for visited sites.") {
Browser b{};
- b.goToSite("gemini://laack.co");
+ b.goToSite("gemini://localhost");
// meta strips status.
- REQUIRE(b.getCurrentSite()->getMeta() == "text/gemini;lang=en-US");
+ REQUIRE(b.getCurrentSite()->getMeta() == "text/gemini");
}
diff --git a/tests/cgi-bin/redirect.py b/tests/cgi-bin/redirect.py
@@ -0,0 +1,4 @@
+#!/usr/bin/env python3
+import random
+
+print(f"31 gemini://localhost", end="\r\n")
diff --git a/tests/cgi-bin/search.py b/tests/cgi-bin/search.py
@@ -0,0 +1,12 @@
+#!/usr/bin/env python3
+import random
+import os
+
+query = os.environ.get("QUERY_STRING", "")
+
+if not query:
+ print(f"10 enter some info", end="\r\n")
+else:
+ print(f"20 text/gemini", end="\r\n")
+ print("Hey, you entered: " + query)
+
diff --git a/tests/puppet-test.cpp b/tests/puppet-test.cpp
@@ -91,23 +91,6 @@ TEST_CASE("Open page and navigate to site") {
delete bPtr;
}
-TEST_CASE("Open page and search the web") {
- Browser* bPtr = new Browser {};
- Browser& b = *bPtr;
- DrawState ds {};
- ds.bPtr = bPtr;
- REQUIRE(mainLoop(ds, b, 'o',0,0));
-
- std::string rnd = genRandom(10);
- INFO(rnd);
- for(auto& ch : rnd) {
- REQUIRE(mainLoop(ds, b, ch,0,0));
- }
- REQUIRE(mainLoop(ds, b, '\n',0,0));
- REQUIRE(b.getCurrentLink()->getLinkDestination().to_string() == "gemini://tlgs.one/search?" + urlEncode(rnd));
- delete bPtr;
-}
-
TEST_CASE("Open page after backspacing character") {
Browser* bPtr = new Browser {};
Browser& b = *bPtr;
@@ -155,23 +138,17 @@ TEST_CASE("Handle redirects") {
Browser& b = *bPtr;
DrawState ds {};
ds.bPtr = bPtr;
- REQUIRE(mainLoop(ds, b, 'o',0,0));
- REQUIRE(mainLoop(ds, b, 'c',0,0));
- REQUIRE(mainLoop(ds, b, 'o',0,0));
- REQUIRE(mainLoop(ds, b, 'n',0,0));
- REQUIRE(mainLoop(ds, b, 'm',0,0));
- REQUIRE(mainLoop(ds, b, 'a',0,0));
- REQUIRE(mainLoop(ds, b, 'n',0,0));
- REQUIRE(mainLoop(ds, b, '.',0,0));
- REQUIRE(mainLoop(ds, b, 'o',0,0));
- REQUIRE(mainLoop(ds, b, 'r',0,0));
- REQUIRE(mainLoop(ds, b, 'g',0,0));
+ std::string st = "ogemini://localhost/cgi-bin/redirect.py";
+ for(auto& ch: st) {
+ REQUIRE(mainLoop(ds, b, ch,0,0));
+ }
+
REQUIRE(mainLoop(ds, b, '\n',0,0));
- REQUIRE(b.getCurrentLink()->getLinkDestination().to_string() == "gemini://conman.org");
+ REQUIRE(b.getCurrentLink()->getLinkDestination().to_string() == "gemini://localhost/cgi-bin/redirect.py");
REQUIRE(mainLoop(ds, b, 'y',0,0)); // follow redirect
- REQUIRE(b.getCurrentLink()->getLinkDestination().to_string() == "gemini://gemini.conman.org/");
+ REQUIRE(b.getCurrentLink()->getLinkDestination().to_string() == "gemini://localhost");
delete bPtr;
}
@@ -180,22 +157,17 @@ TEST_CASE("Handle redirect rejection") {
Browser& b = *bPtr;
DrawState ds {};
ds.bPtr = bPtr;
- REQUIRE(mainLoop(ds, b, 'o',0,0));
- REQUIRE(mainLoop(ds, b, 'c',0,0));
- REQUIRE(mainLoop(ds, b, 'o',0,0));
- REQUIRE(mainLoop(ds, b, 'n',0,0));
- REQUIRE(mainLoop(ds, b, 'm',0,0));
- REQUIRE(mainLoop(ds, b, 'a',0,0));
- REQUIRE(mainLoop(ds, b, 'n',0,0));
- REQUIRE(mainLoop(ds, b, '.',0,0));
- REQUIRE(mainLoop(ds, b, 'o',0,0));
- REQUIRE(mainLoop(ds, b, 'r',0,0));
- REQUIRE(mainLoop(ds, b, 'g',0,0));
+
+ std::string st = "ogemini://localhost/cgi-bin/redirect.py";
+ for(auto& ch: st) {
+ REQUIRE(mainLoop(ds, b, ch,0,0));
+ }
+
REQUIRE(mainLoop(ds, b, '\n',0,0));
- REQUIRE(b.getCurrentLink()->getLinkDestination().to_string() == "gemini://conman.org");
+ REQUIRE(b.getCurrentLink()->getLinkDestination().to_string() == "gemini://localhost/cgi-bin/redirect.py");
- REQUIRE(mainLoop(ds, b, 'n',0,0)); // follow redirect
+ REQUIRE(mainLoop(ds, b, 'n',0,0)); // don't follow redirect
REQUIRE(b.getCurrentLink()->getLinkDestination().to_string() == "about://newtab");
delete bPtr;
}
@@ -207,23 +179,15 @@ TEST_CASE("Enter an input") {
ds.bPtr = bPtr;
REQUIRE(mainLoop(ds, b, 'o',0,0));
- REQUIRE(mainLoop(ds, b, 't',0,0));
- REQUIRE(mainLoop(ds, b, 'l',0,0));
- REQUIRE(mainLoop(ds, b, 'g',0,0));
- REQUIRE(mainLoop(ds, b, 's',0,0));
- REQUIRE(mainLoop(ds, b, '.',0,0));
- REQUIRE(mainLoop(ds, b, 'o',0,0));
- REQUIRE(mainLoop(ds, b, 'n',0,0));
- REQUIRE(mainLoop(ds, b, 'e',0,0));
- REQUIRE(mainLoop(ds, b, '\n',0,0));
- REQUIRE(b.getCurrentLink()->getLinkDestination().to_string() == "gemini://tlgs.one");
+ std::string st = "gemini://localhost/cgi-bin/search.py";
+ for(auto& ch: st) {
+ REQUIRE(mainLoop(ds, b, ch,0,0));
+ }
- REQUIRE(mainLoop(ds,b,'o',0,0));
- REQUIRE(mainLoop(ds,b,'2',0,0));
REQUIRE(mainLoop(ds, b, '\n',0,0));
- REQUIRE(b.getCurrentLink()->getLinkDestination().to_string() == "gemini://tlgs.one/search");
+ REQUIRE(b.getCurrentLink()->getLinkDestination().to_string() == "gemini://localhost/cgi-bin/search.py");
std::string rnd = genRandom(10);
@@ -235,7 +199,7 @@ TEST_CASE("Enter an input") {
REQUIRE(mainLoop(ds, b, '\n',0,0));
- REQUIRE(b.getCurrentLink()->getLinkDestination().to_string() == "gemini://tlgs.one/search?" + urlEncode(rnd));
+ REQUIRE(b.getCurrentLink()->getLinkDestination().to_string() == "gemini://localhost/cgi-bin/search.py?" + urlEncode(rnd));
delete bPtr;
}
@@ -245,24 +209,15 @@ TEST_CASE("Enter an input and then cancel") {
DrawState ds {};
ds.bPtr = bPtr;
- REQUIRE(mainLoop(ds, b, 'o',0,0));
- REQUIRE(mainLoop(ds, b, 't',0,0));
- REQUIRE(mainLoop(ds, b, 'l',0,0));
- REQUIRE(mainLoop(ds, b, 'g',0,0));
- REQUIRE(mainLoop(ds, b, 's',0,0));
- REQUIRE(mainLoop(ds, b, '.',0,0));
- REQUIRE(mainLoop(ds, b, 'o',0,0));
- REQUIRE(mainLoop(ds, b, 'n',0,0));
- REQUIRE(mainLoop(ds, b, 'e',0,0));
- REQUIRE(mainLoop(ds, b, '\n',0,0));
- REQUIRE(b.getCurrentLink()->getLinkDestination().to_string() == "gemini://tlgs.one");
+ std::string st = "ogemini://localhost/cgi-bin/search.py";
+ for(auto& ch: st) {
+ REQUIRE(mainLoop(ds, b, ch,0,0));
+ }
- REQUIRE(mainLoop(ds,b,'o',0,0));
- REQUIRE(mainLoop(ds,b,'2',0,0));
REQUIRE(mainLoop(ds, b, '\n',0,0));
- REQUIRE(b.getCurrentLink()->getLinkDestination().to_string() == "gemini://tlgs.one/search");
+ REQUIRE(b.getCurrentLink()->getLinkDestination().to_string() == "gemini://localhost/cgi-bin/search.py");
std::string rnd = genRandom(10);
@@ -274,7 +229,7 @@ TEST_CASE("Enter an input and then cancel") {
REQUIRE(mainLoop(ds, b, 27,0,0)); // escape
- REQUIRE(b.getCurrentLink()->getLinkDestination().to_string() == "gemini://tlgs.one");
+ REQUIRE(b.getCurrentLink()->getLinkDestination().to_string() == "about://newtab");
delete bPtr;
}