foreseen

A text-based gemini browser with prefetching
git clone git://git.laack.co/foreseen.git
Log | Files | Refs | README | LICENSE

commit 7768e1cc4af922c3615a35fd274897768c20a3cb
parent 52c447ab4f884422dde5f250aaf752978bed70e0
Author: Andrew Laack <andrew@laack.co>
Date:   Tue, 29 Sep 2026 12:32:22 -0500

Fixed some warnings, added coverage to test outputs

Diffstat:
M.gitignore | 4++++
MMakefile | 10++++++++++
Mconfig.mk | 2++
Msrc/browser.cpp | 4----
Msrc/gemini-client.cpp | 2--
Msrc/utils.cpp | 10+++++-----
Mtests/browser-test.cpp | 4++--
7 files changed, 23 insertions(+), 13 deletions(-)

diff --git a/.gitignore b/.gitignore @@ -1,2 +1,6 @@ *.out vgcore* +*.gcno +*.gcda +coverage-html/ +*.info diff --git a/Makefile b/Makefile @@ -11,6 +11,8 @@ install: build clean: rm -rf test*.out foreseen.out + rm -rf *.gcda *.gcno + rm -rf coverage.info browser-test: ${TCOMMAND_P} tests/browser-test.cpp ${TCOMMAND_S} -o test1.out @@ -39,3 +41,11 @@ crash-test: rm test5.out test: pure-test browser-test fetch-test + lcov --capture --directory . --output-file coverage.info \ + --no-external \ + --rc geninfo_unexecuted_blocks=1 \ + --ignore-errors inconsistent,inconsistent + genhtml coverage.info --output-directory coverage-html \ + --ignore-errors inconsistent,inconsistent + rm -rf *.gcda *.gcno + rm -rf coverage.info diff --git a/config.mk b/config.mk @@ -11,6 +11,8 @@ 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 + 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 COMMAND_P = ${CC} ${CFLAGS} -D NDEBUG diff --git a/src/browser.cpp b/src/browser.cpp @@ -353,8 +353,6 @@ void Browser::goBack() { // but only in cases where they are right next to each other without any other 2X status code sites // between them. - Link* cur = getCurrentLink(); - std::string starting = getCurrentLink()->getLinkDestination().to_string(); previousIdx -= 1; @@ -386,8 +384,6 @@ void Browser::goForward() { int original = previousIdx; - Link* cur = getCurrentLink(); - std::string starting = getCurrentLink()->getLinkDestination().to_string(); previousIdx += 1; diff --git a/src/gemini-client.cpp b/src/gemini-client.cpp @@ -82,14 +82,12 @@ Site* GeminiClient::getNetworkedSite(Link link, std::string crtPath, std::string int n; int sizeRemaining = RESPONSE_SIZE_LIMIT_MB * 1024 * 1024; - bool truncated = false; while ((n = BIO_read(bio.get(), buf, sizeof buf)) > 0) { response.append(buf, n); sizeRemaining -= n; if(sizeRemaining <= 0) { - truncated = true; break; } } diff --git a/src/utils.cpp b/src/utils.cpp @@ -60,7 +60,7 @@ std::string readFileToString(std::string filePath) { } std::string stripLeadingWhiteSpace(std::string& input) { - int x = 0; + std::size_t x = 0; while(x < input.size() && isWhiteSpace(input, x)) { x += 1; @@ -69,7 +69,7 @@ std::string stripLeadingWhiteSpace(std::string& input) { } bool isWhiteSpace(std::string& line, int idx) { - if(idx < line.size() && idx >= 0) { + if(idx < (int)line.size() && idx >= 0) { return line[idx] == ' ' || line[idx] == '\t'; } return false; @@ -117,9 +117,9 @@ Line* lineToLine(std::string input, std::optional<uri> prior, int linkCount, boo Link* ln = new Link{input, prior, linkCount}; return ln; } - if(input.substr(0,1) == "#" && isWhiteSpace(input,1) || - input.substr(0,2) == "##" && isWhiteSpace(input,2) || - input.substr(0,3) == "###" && isWhiteSpace(input,3)) { + if( (input.substr(0,1) == "#" && isWhiteSpace(input,1)) || + (input.substr(0,2) == "##" && isWhiteSpace(input,2)) || + (input.substr(0,3) == "###" && isWhiteSpace(input,3))) { Heading* hd = new Heading{input}; return hd; diff --git a/tests/browser-test.cpp b/tests/browser-test.cpp @@ -123,9 +123,9 @@ TEST_CASE("Never crash from weird user inputs") { for(auto& str : ls) { auto res = handleDestinationResolution(str, false); if(res.t == STRING_DESTINATION) { - bool result = b.goToSite(res.destination); + b.goToSite(res.destination); } else if (res.t == NUMBER_DESTINATION) { - bool result = b.followLinkNumber(res.linkNumber); + b.followLinkNumber(res.linkNumber); } b.refresh(); b.goBack();