Skip to content

Commit 9cafd38

Browse files
manyosocebtenzzre
andauthored
Add test scaffolding (#3103)
Signed-off-by: Adam Treat <[email protected]> Signed-off-by: Jared Van Bortel <[email protected]> Co-authored-by: Jared Van Bortel <[email protected]>
1 parent c3357b7 commit 9cafd38

File tree

5 files changed

+57
-0
lines changed

5 files changed

+57
-0
lines changed

gpt4all-chat/CMakeLists.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ if(APPLE)
2222
endif()
2323
endif()
2424

25+
find_package(Python3 QUIET COMPONENTS Interpreter)
26+
27+
option(GPT4ALL_TEST "Build the tests" ${Python3_FOUND})
2528
option(GPT4ALL_LOCALHOST "Build installer for localhost repo" OFF)
2629
option(GPT4ALL_OFFLINE_INSTALLER "Build an offline installer" OFF)
2730
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)
9396
add_subdirectory(deps)
9497
add_subdirectory(../gpt4all-backend llmodel)
9598

99+
if (GPT4ALL_TEST)
100+
enable_testing()
101+
add_subdirectory(tests)
102+
103+
# The 'check' target makes sure the tests and their dependencies are up-to-date before running them
104+
add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND} DEPENDS chat gpt4all_tests)
105+
endif()
106+
96107
set(CHAT_EXE_RESOURCES)
97108

98109
# Metal shader library

gpt4all-chat/tests/CMakeLists.txt

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
include(FetchContent)
2+
3+
find_package(Python3 REQUIRED COMPONENTS Interpreter)
4+
5+
# Google test download and setup
6+
FetchContent_Declare(
7+
googletest
8+
URL https://github.com/google/googletest/archive/refs/tags/v1.15.2.zip
9+
)
10+
FetchContent_MakeAvailable(googletest)
11+
12+
add_test(NAME ChatPythonTests
13+
COMMAND ${Python3_EXECUTABLE} -m pytest ${CMAKE_SOURCE_DIR}/tests/python_tests
14+
)
15+
set_tests_properties(ChatPythonTests PROPERTIES
16+
ENVIRONMENT "CHAT_EXECUTABLE=${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/chat"
17+
TIMEOUT 60
18+
)
19+
20+
add_executable(gpt4all_tests
21+
test_main.cpp
22+
basic_test.cpp
23+
)
24+
25+
target_link_libraries(gpt4all_tests PRIVATE gtest gtest_main)
26+
27+
include(GoogleTest)
28+
gtest_discover_tests(gpt4all_tests)

gpt4all-chat/tests/basic_test.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#include <gtest/gtest.h>
2+
3+
TEST(BasicTest, TestInitialization) {
4+
EXPECT_TRUE(true);
5+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import os
2+
3+
import pytest
4+
5+
# test that the chat executable exists
6+
def test_chat_environment():
7+
assert os.path.exists(os.environ['CHAT_EXECUTABLE'])

gpt4all-chat/tests/test_main.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#include <gtest/gtest.h>
2+
3+
int main(int argc, char **argv) {
4+
::testing::InitGoogleTest(&argc, argv);
5+
return RUN_ALL_TESTS();
6+
}

0 commit comments

Comments
 (0)