commit cd8637ba45d54cee1e7b3d560f4f13e4709363ac
parent 965b9203d358a9ff145334ffc8b3c38aab7def5a
Author: Andrew Laack <andrew@laack.co>
Date: Tue, 29 Sep 2026 23:18:33 -0500
Fuzz tests for inputs
Diffstat:
4 files changed, 68 insertions(+), 9 deletions(-)
diff --git a/TODO.txt b/TODO.txt
@@ -130,3 +130,10 @@
- go to site -> vim buffer
- stdin?
- make sure keybindings are up to date on new tab page
+
+- multi-step builds
+
+---
+
+- perf metrics / benchmarks
+- handle downloading in tests...
diff --git a/config.mk b/config.mk
@@ -11,7 +11,7 @@ CC = g++
IFLAGS = -Ofast -std=c++23
DFLAGS = -O0 -fsanitize=address,undefined -g -std=c++23 -Wpedantic -Wall -Wextra -Wno-deprecated-declarations
-CTFLAGS = -O0 -fsanitize=undefined -g -std=c++23 -Wpedantic -Wall -Wextra -Wno-deprecated-declarations -fprofile-arcs -ftest-coverage -fPIC
+CTFLAGS = -O0 -fsanitize=undefined -g -std=c++23 -Wpedantic -Wall -Wextra -Wno-deprecated-declarations -fprofile-arcs -ftest-coverage -fPIC -D DEBUG_MODE
BASE_FILES = src/identity-manager.cpp src/quote.cpp src/list-item.cpp src/preformatted.cpp src/format-switch.cpp src/cache.cpp src/link.cpp src/plaintext.cpp src/site.cpp src/utils.cpp src/gemini-client.cpp src/browser.cpp src/heading.cpp src/render.cpp
diff --git a/include/shared.hpp b/include/shared.hpp
@@ -2,14 +2,7 @@
#include <string>
-
-
-#ifdef DEBUG_MODE
- const std::string DEFAULT_SEARCH_ENGINE = "gemini://laack.co/search?"; // this doesn't exist.
-#else
- const std::string DEFAULT_SEARCH_ENGINE = "gemini://tlgs.one/search?";
-#endif
-
+const std::string DEFAULT_SEARCH_ENGINE = "gemini://tlgs.one/search?";
const int SITE_CACHE_LIMIT = 10; // number of links to prefetch per page
const int THREAD_NUM = 4; // thread count in thread pool for pre-fetching
diff --git a/tests/puppet-test.cpp b/tests/puppet-test.cpp
@@ -1,6 +1,10 @@
#include <catch2/catch_test_macros.hpp>
+#include <rapidcheck.h>
#include "../include/render.hpp"
#include <ncurses.h>
+#include <rapidcheck/Check.h>
+#include <rapidcheck/Log.h>
+#include <string>
std::string genRandom(const int len) {
static const char alpha[] =
@@ -16,6 +20,21 @@ std::string genRandom(const int len) {
return tmp_s;
}
+std::string genAlNumNlSp(const int len) {
+ static const char alphanum[] =
+ "0123456789"
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
+ "abcdefghijklmnopqrstuvwxyz\n ";
+ std::string tmp_s;
+ tmp_s.reserve(len);
+
+ for (int i = 0; i < len; ++i) {
+ tmp_s += alphanum[rand() % (sizeof(alphanum) - 1)];
+ }
+
+ return tmp_s;
+}
+
// Puppet entire browser
@@ -219,3 +238,43 @@ TEST_CASE("Enter an input and then cancel") {
REQUIRE(b.getCurrentLink()->getLinkDestination().to_string() == "gemini://tlgs.one");
}
+
+TEST_CASE("Only return false on 'q' entry when not using input boxes, never crash, junk inputs") {
+ rc::check("Never return false / fail except with input 'q'", [] (std::string st) {
+ Browser b {};
+ DrawState ds {};
+ RC_LOG(st);
+ for(auto& cur : st) {
+ if(cur == 'q') {
+ if(!ds.handleInput && !ds.handleOpenOther && !ds.handleRedirect) {
+ REQUIRE_FALSE(mainLoop(ds,b,cur));
+ } else {
+ REQUIRE(mainLoop(ds,b,cur));
+ }
+ } else {
+ REQUIRE(mainLoop(ds,b,cur));
+ }
+ }
+ });
+}
+
+TEST_CASE("Only return false on 'q' entry when not using input boxes, alphanumeric inputs") {
+ for(int i = 0; i < 100; ++i) {
+ Browser b {};
+ DrawState ds {};
+ std::string st = genAlNumNlSp(rand()%1000);
+ INFO(st);
+ for(auto& cur : st) {
+ if(cur == 'q') {
+ if(!ds.handleInput && !ds.handleOpenOther && !ds.handleRedirect) {
+ REQUIRE_FALSE(mainLoop(ds,b,cur));
+ } else {
+ REQUIRE(mainLoop(ds,b,cur));
+ }
+ } else {
+ REQUIRE(mainLoop(ds,b,cur));
+ }
+ }
+ }
+}
+