Skip to content

Commit

Permalink
Add test scaffolding (#3103)
Browse files Browse the repository at this point in the history
Signed-off-by: Adam Treat <treat.adam@gmail.com>
Signed-off-by: Jared Van Bortel <jared@nomic.ai>
Co-authored-by: Jared Van Bortel <jared@nomic.ai>
  • Loading branch information
manyoso and cebtenzzre authored Oct 18, 2024
1 parent c3357b7 commit 9cafd38
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 0 deletions.
11 changes: 11 additions & 0 deletions gpt4all-chat/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
28 changes: 28 additions & 0 deletions gpt4all-chat/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
5 changes: 5 additions & 0 deletions gpt4all-chat/tests/basic_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#include <gtest/gtest.h>

TEST(BasicTest, TestInitialization) {
EXPECT_TRUE(true);
}
7 changes: 7 additions & 0 deletions gpt4all-chat/tests/python_tests/test_executable.py
Original file line number Diff line number Diff line change
@@ -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'])
6 changes: 6 additions & 0 deletions gpt4all-chat/tests/test_main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include <gtest/gtest.h>

int main(int argc, char **argv) {
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}

0 comments on commit 9cafd38

Please sign in to comment.