added first test
This commit is contained in:
parent
c5d70fdf7e
commit
b386c11043
|
@ -14,3 +14,4 @@ lexer.ll.c
|
||||||
parser.tab.c
|
parser.tab.c
|
||||||
parser.tab.h
|
parser.tab.h
|
||||||
build
|
build
|
||||||
|
/Testing/
|
||||||
|
|
|
@ -21,6 +21,15 @@ project(gemstone
|
||||||
DESCRIPTION "programming language compiler"
|
DESCRIPTION "programming language compiler"
|
||||||
LANGUAGES C)
|
LANGUAGES C)
|
||||||
|
|
||||||
|
set(GEMSTONE_TEST_DIR ${PROJECT_SOURCE_DIR}/tests)
|
||||||
|
set(GEMSTONE_BINARY_DIR ${PROJECT_SOURCE_DIR}/bin)
|
||||||
|
|
||||||
|
include(CTest)
|
||||||
|
|
||||||
|
if(BUILD_TESTING)
|
||||||
|
add_subdirectory(tests)
|
||||||
|
endif()
|
||||||
|
|
||||||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||||
|
|
||||||
# ------------------------------------------------ #
|
# ------------------------------------------------ #
|
||||||
|
@ -79,7 +88,7 @@ add_executable(release
|
||||||
set_target_properties(release
|
set_target_properties(release
|
||||||
PROPERTIES
|
PROPERTIES
|
||||||
OUTPUT_NAME "gsc"
|
OUTPUT_NAME "gsc"
|
||||||
RUNTIME_OUTPUT_DIRECTORY "bin/release")
|
RUNTIME_OUTPUT_DIRECTORY ${GEMSTONE_BINARY_DIR}/release)
|
||||||
|
|
||||||
# FIXME: cannot compile with /O2 because of /RTC1 flag
|
# FIXME: cannot compile with /O2 because of /RTC1 flag
|
||||||
if (MSVC)
|
if (MSVC)
|
||||||
|
@ -111,7 +120,7 @@ add_executable(debug
|
||||||
set_target_properties(debug
|
set_target_properties(debug
|
||||||
PROPERTIES
|
PROPERTIES
|
||||||
OUTPUT_NAME "gsc"
|
OUTPUT_NAME "gsc"
|
||||||
RUNTIME_OUTPUT_DIRECTORY "bin/debug")
|
RUNTIME_OUTPUT_DIRECTORY ${GEMSTONE_BINARY_DIR}/debug)
|
||||||
|
|
||||||
if (MSVC)
|
if (MSVC)
|
||||||
set(DEBUG_FLAGS /DEBUG)
|
set(DEBUG_FLAGS /DEBUG)
|
||||||
|
@ -140,7 +149,7 @@ add_executable(check
|
||||||
set_target_properties(check
|
set_target_properties(check
|
||||||
PROPERTIES
|
PROPERTIES
|
||||||
OUTPUT_NAME "gsc"
|
OUTPUT_NAME "gsc"
|
||||||
RUNTIME_OUTPUT_DIRECTORY "bin/check")
|
RUNTIME_OUTPUT_DIRECTORY ${GEMSTONE_BINARY_DIR}/check)
|
||||||
|
|
||||||
if (MSVC)
|
if (MSVC)
|
||||||
set(CHECK_FLAGS /DEBUG /WX)
|
set(CHECK_FLAGS /DEBUG /WX)
|
||||||
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
include(CTest)
|
||||||
|
|
||||||
|
set(PROJECT_BINARY_DIR bin)
|
||||||
|
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/tests)
|
||||||
|
set(CTEST_BINARY_DIRECTORY ${PROJECT_BINARY_DIR}/tests)
|
||||||
|
|
||||||
|
# Provide test to run here or include another CMakeLists.txt
|
||||||
|
|
||||||
|
add_subdirectory(logging)
|
|
@ -0,0 +1,9 @@
|
||||||
|
include(CTest)
|
||||||
|
|
||||||
|
add_executable(logging ${PROJECT_SOURCE_DIR}/src/sys/log.c main.c)
|
||||||
|
target_include_directories(logging PUBLIC ${PROJECT_SOURCE_DIR}/src)
|
||||||
|
set_target_properties(logging
|
||||||
|
PROPERTIES
|
||||||
|
OUTPUT_NAME "output"
|
||||||
|
RUNTIME_OUTPUT_DIRECTORY ${GEMSTONE_BINARY_DIR}/tests/logging)
|
||||||
|
add_test(NAME logging WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} COMMAND python ${GEMSTONE_TEST_DIR}/logging/check_output.py)
|
|
@ -0,0 +1,22 @@
|
||||||
|
import subprocess
|
||||||
|
|
||||||
|
|
||||||
|
def run_logger_test():
|
||||||
|
p = subprocess.run("bin/tests/logging/output", capture_output=True, text=True)
|
||||||
|
|
||||||
|
# check exit code
|
||||||
|
if p.returncode != 0:
|
||||||
|
exit(p.returncode)
|
||||||
|
|
||||||
|
output = p.stderr
|
||||||
|
|
||||||
|
# check if logs appear in default log output (stderr)
|
||||||
|
|
||||||
|
assert "logging some debug..." in output
|
||||||
|
assert "logging some info..." in output
|
||||||
|
assert "logging some warning..." in output
|
||||||
|
assert "logging some error..." in output
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
run_logger_test()
|
|
@ -0,0 +1,16 @@
|
||||||
|
//
|
||||||
|
// Created by servostar on 5/1/24.
|
||||||
|
//
|
||||||
|
|
||||||
|
#include "sys/log.h"
|
||||||
|
|
||||||
|
int main(void) {
|
||||||
|
log_init();
|
||||||
|
|
||||||
|
DEBUG("logging some debug...");
|
||||||
|
INFO("logging some info...");
|
||||||
|
WARN("logging some warning...");
|
||||||
|
ERROR("logging some error...");
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
Loading…
Reference in New Issue