-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test: add unit testing and some tests
* jsonutil stringsplit * location/section parser inheritance for empty child rules
- Loading branch information
1 parent
aafe839
commit 797bdcd
Showing
7 changed files
with
175 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,7 +21,7 @@ jobs: | |
- name: Install dependencies | ||
run: | | ||
sudo apt-get update -y -qq | ||
sudo apt-get install coreutils build-essential libsdl2-dev libsdl2-image-dev libsdl2-ttf-dev p7zip | ||
sudo apt-get install coreutils build-essential libsdl2-dev libsdl2-image-dev libsdl2-ttf-dev p7zip libgtest-dev | ||
- uses: actions/checkout@v4 | ||
with: | ||
submodules: recursive | ||
|
@@ -48,7 +48,7 @@ jobs: | |
- name: Install dependencies | ||
run: | | ||
sudo apt-get update -y -qq | ||
sudo apt-get install coreutils build-essential libsdl2-dev libsdl2-image-dev libsdl2-ttf-dev p7zip wget | ||
sudo apt-get install coreutils build-essential libsdl2-dev libsdl2-image-dev libsdl2-ttf-dev p7zip wget libgtest-dev | ||
- uses: actions/checkout@v4 | ||
with: | ||
submodules: recursive | ||
|
@@ -74,7 +74,7 @@ jobs: | |
steps: | ||
- name: Install dependencies | ||
run: | | ||
brew install coreutils SDL2 sdl2_ttf sdl2_image [email protected] automake libtool autoconf | ||
brew install coreutils SDL2 sdl2_ttf sdl2_image [email protected] automake libtool autoconf googletest | ||
- uses: actions/checkout@v4 | ||
with: | ||
submodules: recursive | ||
|
@@ -123,6 +123,7 @@ jobs: | |
mingw64/mingw-w64-x86_64-SDL2_ttf | ||
mingw64/mingw-w64-x86_64-freetype | ||
mingw64/mingw-w64-x86_64-openssl | ||
mingw64/mingw-w64-x86_64-gtest | ||
p7zip | ||
- uses: actions/checkout@v4 | ||
with: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,7 +41,7 @@ jobs: | |
- name: Install dependencies | ||
run: | | ||
sudo apt-get update -y -qq | ||
sudo apt-get install coreutils build-essential libsdl2-dev libsdl2-image-dev libsdl2-ttf-dev p7zip wget | ||
sudo apt-get install coreutils build-essential libsdl2-dev libsdl2-image-dev libsdl2-ttf-dev p7zip wget libgtest-dev | ||
- uses: actions/checkout@v4 | ||
with: | ||
submodules: recursive | ||
|
@@ -77,7 +77,7 @@ jobs: | |
- name: Install dependencies | ||
run: | | ||
sudo apt-get update -y -qq | ||
sudo apt-get install coreutils build-essential libsdl2-dev libsdl2-image-dev libsdl2-ttf-dev p7zip wget | ||
sudo apt-get install coreutils build-essential libsdl2-dev libsdl2-image-dev libsdl2-ttf-dev p7zip wget libgtest-dev | ||
- uses: actions/checkout@v4 | ||
with: | ||
submodules: recursive | ||
|
@@ -106,7 +106,7 @@ jobs: | |
steps: | ||
- name: Install dependencies | ||
run: | | ||
brew install coreutils SDL2 sdl2_ttf sdl2_image [email protected] automake libtool autoconf | ||
brew install coreutils SDL2 sdl2_ttf sdl2_image [email protected] automake libtool autoconf googletest | ||
- uses: actions/checkout@v4 | ||
with: | ||
submodules: recursive | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,11 +47,11 @@ jobs: | |
if: ${{ startsWith(matrix.os, 'ubuntu') }} | ||
run: | | ||
sudo apt-get update -y -qq | ||
sudo apt-get install coreutils build-essential libsdl2-dev libsdl2-image-dev libsdl2-ttf-dev | ||
sudo apt-get install coreutils build-essential libsdl2-dev libsdl2-image-dev libsdl2-ttf-dev libgtest-dev | ||
- name: Install dependencies (brew) | ||
if: ${{ startsWith(matrix.os, 'macos') }} | ||
run: | | ||
brew install coreutils SDL2 sdl2_ttf sdl2_image [email protected] | ||
brew install coreutils SDL2 sdl2_ttf sdl2_image [email protected] googletest | ||
- name: Install dependencies (msys2) | ||
if: ${{ startsWith(matrix.os, 'windows') }} | ||
uses: msys2/setup-msys2@v2 | ||
|
@@ -68,6 +68,7 @@ jobs: | |
mingw64/mingw-w64-x86_64-SDL2_ttf | ||
mingw64/mingw-w64-x86_64-freetype | ||
mingw64/mingw-w64-x86_64-openssl | ||
mingw64/mingw-w64-x86_64-gtest | ||
p7zip | ||
- uses: actions/checkout@v4 | ||
with: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# Automated PopTracker Tests | ||
|
||
PRs to add tests are welcome. | ||
|
||
We have 3 types of tests in mind: | ||
- **Unit tests:** test individual code fragments using googletest, see [How to add Unit Tests](#how-to-add-unit-tests). | ||
- **Render tests:** load packs and verify render output using `SDL_VIDEODRIVER=dummy` and a screenshot | ||
- **High level tests:** stuff that should be tested end-to-end may be hard to do with googletest because we'd need to | ||
mock all of PopTracker. Those will probably use an external test script that waits for e.g. a specific print from Lua. | ||
|
||
Tests should be run on both 64bit and 32bit to see if any integer size assumptions are wrong. | ||
|
||
Tests that should be done: | ||
- Render tests for all example packs | ||
- High level tests for AP | ||
- 64bit onItem | ||
- 64bit onLocationScout | ||
- 64bit onLocationCheck | ||
- 64bit CheckedLocations | ||
- 64bit MissingLocations | ||
- 64bit data storage | ||
- unicode data storage | ||
- 64bit slot data | ||
- unicode slot data | ||
|
||
## How to add Unit Tests | ||
|
||
We compile `test/*/*.cpp` together with googletest and `src/**` into a test binary. To add tests, simply pick a folder | ||
and add a `test_*.cpp` file that uses googletest API. | ||
|
||
## How to run Unit Tests | ||
|
||
* install `googltest`, sometimes called `gtest` or `libgtest-dev`, via pacman, apt, brew, etc. or from source | ||
* `make test` | ||
|
||
## Other Tests | ||
|
||
We have not decided on a solution for non unit tests yet. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#include <gtest/gtest.h> | ||
#include <nlohmann/json.hpp> | ||
#include "../../src/core/location.h" | ||
|
||
|
||
using namespace std; | ||
using nlohmann::json; | ||
|
||
|
||
TEST(LocationsParserTest, LocationRulesInheritAndEmpty) { | ||
// TODO: validate indirectly by checcking accessibility/visibilty via Tracker | ||
const list<list<string>> parentAccessRules = {{"a"}}; | ||
const list<list<string>> parentVisibilityRules = {{"b"}}; | ||
json childNode = R"( | ||
{ | ||
"name": "child", | ||
"access_rules": [], | ||
"visibility_rules": [] | ||
} | ||
)"_json; | ||
|
||
auto location = Location::FromJSON(childNode, {}, parentAccessRules, parentVisibilityRules).front(); | ||
EXPECT_EQ(location.getAccessRules(), | ||
parentAccessRules); | ||
EXPECT_EQ(location.getVisibilityRules(), | ||
parentVisibilityRules); | ||
} | ||
|
||
TEST(LocationsParserTest, SectionRulesInheritAndEmpty) { | ||
// TODO: validate indirectly by checcking accessibility/visibilty via Tracker | ||
json locationNode = R"( | ||
{ | ||
"name": "location", | ||
"access_rules": [["a"]], | ||
"visibility_rules": [["b"]], | ||
"sections": [ | ||
{ | ||
"name": "section", | ||
"access_rules": [], | ||
"visibility_rules": [] | ||
} | ||
] | ||
} | ||
)"_json; | ||
|
||
auto section = Location::FromJSON(locationNode, {}, {}, {}).front().getSections().front(); | ||
EXPECT_EQ(section.getAccessRules(), | ||
list<list<string>>({{"a"}})); | ||
EXPECT_EQ(section.getVisibilityRules(), | ||
list<list<string>>({{"b"}})); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#include <gtest/gtest.h> | ||
#include <list> | ||
#include <string> | ||
#include "../../src/core/jsonutil.h" | ||
|
||
|
||
using namespace std; | ||
|
||
|
||
// Living standard :TM: | ||
// only trailing empty fields should be dropped | ||
|
||
TEST(CommaSplitTest, Empty) { | ||
EXPECT_EQ(commasplit(""), | ||
list<string>({})); | ||
} | ||
|
||
TEST(CommaSplitTest, TrailingComma) { | ||
// Trailing empty values should be dropped | ||
EXPECT_EQ(commasplit("a,"), | ||
list<string>({"a"})); | ||
} | ||
|
||
TEST(CommaSplitTest, LeadingEmpty) { | ||
// Leading empty values should be kept | ||
EXPECT_EQ(commasplit(",b"), | ||
list<string>({"", "b"})); | ||
} | ||
|
||
TEST(CommaSplitTest, MiddleEmpty) { | ||
// Empty values in the middle should be kept | ||
EXPECT_EQ(commasplit("a,,b"), | ||
list<string>({"a", "", "b"})); | ||
} | ||
|
||
TEST(CommaSplitTest, TrailingWhitespace) { | ||
// If trailing whitespace results in trailing comma, it should behave the same as TrailingComma | ||
EXPECT_EQ(commasplit("a, "), | ||
list<string>({"a"})); | ||
} |