diff --git a/gpt4all-chat/CMakeLists.txt b/gpt4all-chat/CMakeLists.txt index b5c9fc52dd00..3f1a7d267bd2 100644 --- a/gpt4all-chat/CMakeLists.txt +++ b/gpt4all-chat/CMakeLists.txt @@ -22,6 +22,9 @@ if(APPLE) endif() endif() +find_package(Python3 QUIET COMPONENTS Interpreter) + +option(GPT4ALL_TEST "Build the tests" ${Python3_FOUND}) option(GPT4ALL_LOCALHOST "Build installer for localhost repo" OFF) option(GPT4ALL_OFFLINE_INSTALLER "Build an offline installer" OFF) option(GPT4ALL_SIGN_INSTALL "Sign installed binaries and installers (requires signing identities)" OFF) @@ -93,6 +96,14 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) add_subdirectory(deps) add_subdirectory(../gpt4all-backend llmodel) +if (GPT4ALL_TEST) + enable_testing() + add_subdirectory(tests) + + # The 'check' target makes sure the tests and their dependencies are up-to-date before running them + add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND} DEPENDS chat gpt4all_tests) +endif() + set(CHAT_EXE_RESOURCES) # Metal shader library diff --git a/gpt4all-chat/tests/CMakeLists.txt b/gpt4all-chat/tests/CMakeLists.txt new file mode 100644 index 000000000000..ba71959a6e3d --- /dev/null +++ b/gpt4all-chat/tests/CMakeLists.txt @@ -0,0 +1,28 @@ +include(FetchContent) + +find_package(Python3 REQUIRED COMPONENTS Interpreter) + +# Google test download and setup +FetchContent_Declare( + googletest + URL https://github.com/google/googletest/archive/refs/tags/v1.15.2.zip +) +FetchContent_MakeAvailable(googletest) + +add_test(NAME ChatPythonTests + COMMAND ${Python3_EXECUTABLE} -m pytest ${CMAKE_SOURCE_DIR}/tests/python_tests +) +set_tests_properties(ChatPythonTests PROPERTIES + ENVIRONMENT "CHAT_EXECUTABLE=${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/chat" + TIMEOUT 60 +) + +add_executable(gpt4all_tests + test_main.cpp + basic_test.cpp +) + +target_link_libraries(gpt4all_tests PRIVATE gtest gtest_main) + +include(GoogleTest) +gtest_discover_tests(gpt4all_tests) diff --git a/gpt4all-chat/tests/basic_test.cpp b/gpt4all-chat/tests/basic_test.cpp new file mode 100644 index 000000000000..326a7d56514f --- /dev/null +++ b/gpt4all-chat/tests/basic_test.cpp @@ -0,0 +1,5 @@ +#include + +TEST(BasicTest, TestInitialization) { + EXPECT_TRUE(true); +} diff --git a/gpt4all-chat/tests/python_tests/test_executable.py b/gpt4all-chat/tests/python_tests/test_executable.py new file mode 100644 index 000000000000..cf3cee0a878e --- /dev/null +++ b/gpt4all-chat/tests/python_tests/test_executable.py @@ -0,0 +1,7 @@ +import os + +import pytest + +# test that the chat executable exists +def test_chat_environment(): + assert os.path.exists(os.environ['CHAT_EXECUTABLE']) diff --git a/gpt4all-chat/tests/test_main.cpp b/gpt4all-chat/tests/test_main.cpp new file mode 100644 index 000000000000..76f841f1b15e --- /dev/null +++ b/gpt4all-chat/tests/test_main.cpp @@ -0,0 +1,6 @@ +#include + +int main(int argc, char **argv) { + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +}