Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

9 basic testing suite #25

Merged
merged 3 commits into from
Jul 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ log.txt
*.dll
*.pyc

deps/*
29 changes: 29 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,32 @@ if(MINGW)
target_link_libraries(craft ws2_32.lib glfw
${GLFW_LIBRARIES} ${CURL_LIBRARIES})
endif()

# GTest setup
# do not want main included so it is a valid executable
#MESSAGE(STATUS "${SOURCE_FILES}")
FOREACH(item ${SOURCE_FILES})
IF(${item} MATCHES "src/main.c")
LIST(REMOVE_ITEM SOURCE_FILES ${item})
ENDIF(${item} MATCHES "src/main.c")
ENDFOREACH(item)
#MESSAGE(STATUS "${SOURCE_FILES}")

enable_testing()
find_package(GTest REQUIRED)
include_directories(${GTEST_INCLUDE_DIR})
add_executable(
runTests
tests/tests.cpp
${SOURCE_FILES}
deps/glew/src/glew.c
deps/lodepng/lodepng.c
deps/noise/noise.c
deps/sqlite/sqlite3.c
deps/tinycthread/tinycthread.c)
target_link_libraries(runTests
${GTEST_BOTH_LIBRARIES}
pthread
dl glfw
${GLFW_LIBRARIES}
${CURL_LIBRARIES} )
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,17 @@ the installation:

#### Linux (Ubuntu)

GTest install and build from dev package:
```bash
sudo apt-get install libgtest-dev # install gtest dev package
cd /usr/src/gtest
sudo cmake CMakeLists.txt
sudo make
# copy or symlink libgtest.a and libgtest_main.a to your /usr/lib folder
sudo cp *.a /usr/lib
```
The rest of the dependencies can be found below.

sudo apt-get install cmake libglew-dev xorg-dev libcurl4-openssl-dev
sudo apt-get build-dep glfw

Expand Down Expand Up @@ -63,6 +74,12 @@ terminal.
make
./craft

### Tests

Follow the TEST structure within `tests/tests.cpp` to add unit tests to your code. It is structured to allow multiple tests under one test suite, so each feature can have multiple tests under it.

Once your tests are written, follow the normal build procedure above and then target the new `./runTests` executable.

### Multiplayer

After many years, craft.michaelfogleman.com has been taken down. See the [Server](#server) section for info on self-hosting.
Expand Down
22 changes: 22 additions & 0 deletions tests/tests.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include <gtest/gtest.h>

extern "C" { // necessary to link to the c code
#include "../src/util.h"
}

// TEST(TestSuiteName, TestName) {
// ... test body ...
// }

TEST(UtilTests, stringWidth) {
ASSERT_EQ(string_width("1"), 3);
ASSERT_EQ(string_width("2"), 6);
ASSERT_EQ(string_width("3"), 6);
}



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