Added testing with Catch2
Some checks failed
ci/woodpecker/push/workflow Pipeline failed

This commit is contained in:
2025-09-30 21:46:26 +03:00
committed by Emin Arslan
parent 34d35d6039
commit 8fc3e82173
3 changed files with 47 additions and 4 deletions

View File

@@ -13,6 +13,8 @@ steps:
- name: test
image: ubuntu
commands:
# TODO: Probably make actual tests at some point
# Automated tests, this should not fail
- ./test
# Manual test, you can see the output of this in woodpecker
- echo "(print 42)" | ./build/main
# TODO: add publish step, when we're at a working state.

View File

@@ -1,10 +1,30 @@
cmake_minimum_required(VERSION 3.16)
project(lispy_stuff)
# we'll use catch2 as testing library.
include(FetchContent)
FetchContent_Declare(
Catch2
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
GIT_TAG v3.8.1
)
FetchContent_MakeAvailable(Catch2)
list(APPEND CMAKE_MODULE_PATH ${catch2_SOURCE_DIR}/extras)
include(Catch)
set(HEADER_FILES src/include/lex.hpp)
set(SOURCE_FILES src/main.cpp src/lex.cpp)
set(SOURCE_FILES src/lex.cpp)
# we're not actually shipping a library yet,
# this is so we don't have to compile twice for main and tests.
add_library(libmash STATIC ${SOURCE_FILES} ${HEADER_FILES})
target_include_directories(libmash PUBLIC src/include/)
add_executable(main ${SOURCE_FILES} ${HEADER_FILES})
# Main target
add_executable(main src/main.cpp)
target_link_libraries(main libmash)
# tests
add_executable(test src/tests/test.cpp)
target_link_libraries(test PRIVATE libmash Catch2::Catch2WithMain)
target_include_directories(main PRIVATE src/include/)

21
src/tests/test.cpp Normal file
View File

@@ -0,0 +1,21 @@
#include <catch2/catch_test_macros.hpp>
#include <lex.hpp>
using namespace std;
TEST_CASE("Lexer lexes doubles correctly", "[Lexer]") {
SECTION("double and negative syntax") {
Lexer l("(1.0 0.1 -.1 -1. . - -. .-)");
REQUIRE(l.next() == Token({OpenParen}));
REQUIRE(l.next() == Token({Double, 1.0}));
REQUIRE(l.next() == Token({Double, 0.1}));
REQUIRE(l.next() == Token({Double, -0.1}));
REQUIRE(l.next() == Token({Double, -1.0}));
REQUIRE(l.next() == Token({Symbol, "."}));
REQUIRE(l.next() == Token({Symbol, "-"}));
REQUIRE(l.next() == Token({Symbol, "-."}));
REQUIRE(l.next() == Token({Symbol, ".-"}));
REQUIRE(l.next() == Token({CloseParen}));
}
}