Skip to content

Commit 65498b2

Browse files
Don Andersonmschwartz
Don Anderson
authored andcommitted
230 - Add testing framework to MA (#243)
* initial * Delete Brewfile.lock.json * Update test_001.cpp * Create Brewfile.lock.json * Update test.cmake * Update test.cmake * Update Brewfile.lock.json * Update test.cmake * damn * Update test.sh
1 parent e301d43 commit 65498b2

File tree

11 files changed

+290
-4
lines changed

11 files changed

+290
-4
lines changed

.travis.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ install:
1414
- sudo pip install satsuki
1515
- "./.ci/travis/install_deps.sh"
1616
before_script: "./.ci/travis/lint.sh"
17-
script: "./scripts/build.sh"
17+
script:
18+
- "./scripts/build.sh"
19+
- "./scripts/test.sh"
1820
notifications:
1921
slack:
2022
secure: "XH59GGO2tpCt8reN1DDiuhVtKc6kMhf692Bf01HDPp2iIclvI9NJnbzyrSRpslYbt/3QBX/KNJkVkZh6HevprrWhBCXnn43vDFayh/84I5x43Qpwy+jAix1nhiw60fFkSze3Kuxqhd1u0vl87ahCmKbNkQrMPyom1D5+Ujyi0fcYwDeOLp7pHq+DexEjzCCqu/XtNLUzwB2pTCYmx3XAh8PTIE4LG1WO1uYF2XV2554BLJRIt6mGciR17x63kkCJy2NrJ2Gkve8CTknI1i/aoQWZYQzoJY8MCnpoU4565yt+bVI3eAYVEmimSqt5bai+SBwMeZ8QIZ0qGUfD53tX6C98XHFSeV+GF7TZjBbsS8m00uuuxMGZzD8dxZp9ga7ki0LeLefTGqFZsrLc++NMO0joAQNT55e6kYu/XC05Gg/fAqskGkJSD+tU5Tzhn3DYvYaGe6fIhbg4kX8u8l+Ddd6IrEwQad5G45qovEOi+AXHzM9lOpwOJ7IcBUOsZSZNAkzvonRaN4fhPE/Y5bGlw/qtc8VRN/W2xdVhEheQ67NzzbTgGzeflLe+b3pnKjNxTSMBVuLrlB9jF9PXKNcY0cuMwcqU2ImVLxe9cxlLA+qGIk866tLRRkkUMI5Kjx4S+PpGGcSVVtheEpR0cB2WsH+l17CYXE/xwuDMGpccv14="

Brewfile

-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,5 @@ brew "cmake"
33
brew "sdl2"
44
brew "sdl2_image"
55
brew "doxygen"
6-
brew "imagemagick"
76
brew "pkgconfig"
87
brew "jq"

Brewfile.lock.json

+141
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
{
2+
"entries": {
3+
"tap": {
4+
"homebrew/cask": {
5+
"revision": "38e6858b2eed5126bf6d1b4ce04b2b2c7d3c7eed"
6+
}
7+
},
8+
"brew": {
9+
"cmake": {
10+
"version": "3.15.5",
11+
"bottle": {
12+
"cellar": ":any_skip_relocation",
13+
"prefix": "/usr/local",
14+
"files": {
15+
"catalina": {
16+
"url": "https://homebrew.bintray.com/bottles/cmake-3.15.5.catalina.bottle.tar.gz",
17+
"sha256": "46b47f448f7690bbed70526a42f27bea54aa7562c9eefb86955102fc83d1366d"
18+
},
19+
"mojave": {
20+
"url": "https://homebrew.bintray.com/bottles/cmake-3.15.5.mojave.bottle.tar.gz",
21+
"sha256": "ded337f539d87466a83e50c4dee5ccd47356a3a4bc066a0cadbf4c8fc52c7179"
22+
},
23+
"high_sierra": {
24+
"url": "https://homebrew.bintray.com/bottles/cmake-3.15.5.high_sierra.bottle.tar.gz",
25+
"sha256": "e98220aa1eedd7e97926e160c76424cdb08ea5cfc6866ca65cd25a830605586d"
26+
}
27+
}
28+
}
29+
},
30+
"sdl2": {
31+
"version": "2.0.10",
32+
"bottle": {
33+
"cellar": ":any",
34+
"prefix": "/usr/local",
35+
"files": {
36+
"catalina": {
37+
"url": "https://homebrew.bintray.com/bottles/sdl2-2.0.10.catalina.bottle.tar.gz",
38+
"sha256": "dc47470e4dc13c7a0cf48330da2d4938695a5b60bf9d6ef31218f32a803ab48c"
39+
},
40+
"mojave": {
41+
"url": "https://homebrew.bintray.com/bottles/sdl2-2.0.10.mojave.bottle.tar.gz",
42+
"sha256": "ede7f2495e32fd7f1a1bee57db35542066993f7ad4d24bb4c2078a68b0856dfb"
43+
},
44+
"high_sierra": {
45+
"url": "https://homebrew.bintray.com/bottles/sdl2-2.0.10.high_sierra.bottle.tar.gz",
46+
"sha256": "e8e7c8484eaa791d312f9d77f626faad344f90db74bb93423ed2fc234c5f52a6"
47+
},
48+
"sierra": {
49+
"url": "https://homebrew.bintray.com/bottles/sdl2-2.0.10.sierra.bottle.tar.gz",
50+
"sha256": "67961a420c2a8632822f60f61710b95b1173b8b1c2ae05b5f92e4c9892cdc5b7"
51+
}
52+
}
53+
}
54+
},
55+
"sdl2_image": {
56+
"version": "2.0.5",
57+
"bottle": {
58+
"cellar": ":any",
59+
"prefix": "/usr/local",
60+
"files": {
61+
"catalina": {
62+
"url": "https://homebrew.bintray.com/bottles/sdl2_image-2.0.5.catalina.bottle.tar.gz",
63+
"sha256": "691d5407fef2bc374ac3b7c2fafbe46a6bc0f9ed609f98812b24fec33ab9bd27"
64+
},
65+
"mojave": {
66+
"url": "https://homebrew.bintray.com/bottles/sdl2_image-2.0.5.mojave.bottle.tar.gz",
67+
"sha256": "1b3a464579d9ef25b3bdd9276119efffd0134fda5c5dc27051a35f1b21c00cfd"
68+
},
69+
"high_sierra": {
70+
"url": "https://homebrew.bintray.com/bottles/sdl2_image-2.0.5.high_sierra.bottle.tar.gz",
71+
"sha256": "55c1f996fb523c2727d2b103f0a5ecfd7a073f55ff9a7230bb609d22bbf5a576"
72+
},
73+
"sierra": {
74+
"url": "https://homebrew.bintray.com/bottles/sdl2_image-2.0.5.sierra.bottle.tar.gz",
75+
"sha256": "e3c9cf45d97099e818c667d23af8352e6d1bba0e3b609cdddee654f2a9da80cf"
76+
}
77+
}
78+
}
79+
},
80+
"doxygen": {
81+
"version": "1.8.16",
82+
"bottle": {
83+
"cellar": ":any_skip_relocation",
84+
"prefix": "/usr/local",
85+
"files": {
86+
"mojave": {
87+
"url": "https://homebrew.bintray.com/bottles/doxygen-1.8.16.mojave.bottle.tar.gz",
88+
"sha256": "709545ed8f509c407d1a8ac2f36f396f783bd732c98ed18d79e57aa26e79fd74"
89+
},
90+
"high_sierra": {
91+
"url": "https://homebrew.bintray.com/bottles/doxygen-1.8.16.high_sierra.bottle.tar.gz",
92+
"sha256": "882a5c055350590d2dfa31cbc786dab9760acfd222a05ecbabd7833cd09a66d9"
93+
},
94+
"sierra": {
95+
"url": "https://homebrew.bintray.com/bottles/doxygen-1.8.16.sierra.bottle.tar.gz",
96+
"sha256": "5d002c6ee6d2619c5c5c9752c65537b81a135361f2c99f566a3e178de4f448f8"
97+
}
98+
}
99+
}
100+
},
101+
"pkgconfig": null,
102+
"jq": {
103+
"version": "1.6",
104+
"bottle": {
105+
"cellar": ":any",
106+
"prefix": "/usr/local",
107+
"files": {
108+
"catalina": {
109+
"url": "https://homebrew.bintray.com/bottles/jq-1.6.catalina.bottle.1.tar.gz",
110+
"sha256": "820a3c85fcbb63088b160c7edf125d7e55fc2c5c1d51569304499c9cc4b89ce8"
111+
},
112+
"mojave": {
113+
"url": "https://homebrew.bintray.com/bottles/jq-1.6.mojave.bottle.1.tar.gz",
114+
"sha256": "71f0e76c5b22e5088426c971d5e795fe67abee7af6c2c4ae0cf4c0eb98ed21ff"
115+
},
116+
"high_sierra": {
117+
"url": "https://homebrew.bintray.com/bottles/jq-1.6.high_sierra.bottle.1.tar.gz",
118+
"sha256": "dffcffa4ea13e8f0f2b45c5121e529077e135ae9a47254c32182231662ee9b72"
119+
},
120+
"sierra": {
121+
"url": "https://homebrew.bintray.com/bottles/jq-1.6.sierra.bottle.1.tar.gz",
122+
"sha256": "bb4d19dc026c2d72c53eed78eaa0ab982e9fcad2cd2acc6d13e7a12ff658e877"
123+
}
124+
}
125+
}
126+
}
127+
}
128+
},
129+
"system": {
130+
"macos": {
131+
"catalina": {
132+
"HOMEBREW_VERSION": "2.1.16",
133+
"HOMEBREW_PREFIX": "/usr/local",
134+
"Homebrew/homebrew-core": "fd1558ce39c3416e7ff9f21a4cdcbf6d08b862ab",
135+
"CLT": "",
136+
"Xcode": "11.2.1",
137+
"macOS": "10.15.1"
138+
}
139+
}
140+
}
141+
}

CMakeLists.txt

+2
Original file line numberDiff line numberDiff line change
@@ -81,3 +81,5 @@ if (APPLE)
8181
endif (APPLE)
8282

8383
TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${CREATIVE_ENGINE_LINK_LIBRARIES})
84+
85+
INCLUDE( ${CMAKE_CURRENT_SOURCE_DIR}/test/test.cmake )

scripts/test.sh

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/usr/bin/env bash
2+
3+
######################### Debugging and Directory Scaffolding #########
4+
5+
# Set bash unofficial strict mode http://redsymbol.net/articles/unofficial-bash-strict-mode/
6+
set -euo pipefail
7+
# our traps need access to some vars to do their job properly.
8+
set -o errtrace
9+
set -o functrace
10+
IFS=$'\n\t'
11+
12+
# Enable for enhanced debugging
13+
${DEBUG:-false} && set -vx
14+
15+
# Credit to https://stackoverflow.com/a/17805088
16+
# and http://wiki.bash-hackers.org/scripting/debuggingtips
17+
export PS4='+(${BASH_SOURCE}:${LINENO}): ${FUNCNAME[0]:+${FUNCNAME[0]}(): }'
18+
19+
# Credit to Stack Overflow questioner Jiarro and answerer Dave Dopson
20+
# http://stackoverflow.com/questions/59895/can-a-bash-script-tell-what-directory-its-stored-in
21+
# http://stackoverflow.com/a/246128/424301
22+
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
23+
BASE_DIR="$DIR/.."
24+
BUILD_DIR="$BASE_DIR/build"
25+
26+
if [[ "${TRAVIS:-}" == "true" ]]; then
27+
if [[ "${TRAVIS_OS_NAME:-}" == "osx" ]];then
28+
"$BUILD_DIR/test"
29+
else
30+
echo "TBD - make test work on headless (Travis) linux."
31+
fi
32+
else
33+
"$BUILD_DIR/test"
34+
fi
35+
36+

src/GameState/GGameState.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ class GGameState : public BGameEngine {
2828
~GGameState();
2929

3030
void GameLoop() OVERRIDE;
31-
void PreRender();
32-
void PostRender();
31+
void PreRender() OVERRIDE;
32+
void PostRender() OVERRIDE;
3333

3434
void NextLevel(const TInt16 aDungeon, const TInt16 aLevel);
3535
void LoadLevel(const char *aName, const TInt16 aLevel, TUint16 aTileMapId);

test/src/main.cpp

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#include "test.h"
2+
#include <stdio.h>
3+
#include <BResourceManager.h>
4+
5+
test_t tests[] = {
6+
{test_001, "TBD"},
7+
{test_002, "TBD"},
8+
{0, 0}
9+
};
10+
11+
int main(){
12+
13+
test_t *tst = tests;
14+
int cnt = 0;
15+
while(tst->func && tst->label){
16+
cnt++;
17+
if((*tst->func)()){
18+
printf("test_%03d: %s - PASSED\n", cnt, tst->label);
19+
}
20+
else{
21+
printf("test_%03d: %s - FAILED\n", cnt, tst->label);
22+
return 1;
23+
}
24+
tst++;
25+
}
26+
27+
printf("ALL TESTS PASSED");
28+
return 0;
29+
}

test/src/test.h

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#ifndef TEST_H
2+
#define TEST_H
3+
4+
#include <BTypes.h>
5+
6+
typedef bool (*test_func_t)();
7+
8+
typedef struct{
9+
test_func_t func;
10+
const char* label;
11+
} test_t;
12+
13+
bool test_001();
14+
bool test_002();
15+
16+
#endif

test/src/tests/test_001.cpp

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
#include "../test.h"
3+
4+
// Test Label
5+
bool test_001(){
6+
7+
return ETrue;
8+
}
9+
10+

test/src/tests/test_002.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#include "../test.h"
2+
3+
// Test Label
4+
bool test_002(){
5+
6+
return ETrue;
7+
}

test/test.cmake

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
2+
# CMake Module path (additional cmake files via find_package)
3+
FIND_PACKAGE(SDL2 REQUIRED)
4+
FIND_PACKAGE(SDL2_image REQUIRED)
5+
6+
########## RCOMP #########
7+
8+
# resource compiler
9+
SET(RCOMP "${CREATIVE_ENGINE_PATH}/tools/rcomp")
10+
11+
# build rcomp-src
12+
ADD_CUSTOM_COMMAND(
13+
OUTPUT rcomp
14+
COMMAND cd ${CREATIVE_ENGINE_PATH}/tools/rcomp-src && $(MAKE) # $(MAKE) passes -j to make
15+
COMMENT "Building rcomp ${CREATIVE_ENGINE_PATH}"
16+
)
17+
18+
# build Resources.bin
19+
ADD_CUSTOM_COMMAND(
20+
OUTPUT Resources.bin
21+
COMMAND find ${CMAKE_CURRENT_SOURCE_DIR} -name "Resources.bin" -exec rm -f {} +
22+
COMMAND find ${CMAKE_CURRENT_BINARY_DIR} -name "BResourceManager.cpp.o" -exec rm -f {} +
23+
COMMAND cd ${CMAKE_CURRENT_SOURCE_DIR}/src && ${RCOMP} Resources.r
24+
DEPENDS rcomp
25+
COMMENT "Compiling Resources ${CMAKE_CURRENT_SOURCE_DIR}"
26+
)
27+
28+
FILE(GLOB_RECURSE TESTS "${CMAKE_CURRENT_SOURCE_DIR}/test/src/tests/*.cpp")
29+
ADD_EXECUTABLE(test
30+
${CMAKE_CURRENT_SOURCE_DIR}/test/src/main.cpp
31+
${CMAKE_CURRENT_SOURCE_DIR}/test/src/test.h
32+
${TESTS}
33+
${CMAKE_CURRENT_SOURCE_DIR}
34+
${CREATIVE_ENGINE_SOURCE_FILES}
35+
Resources.bin
36+
)
37+
38+
TARGET_INCLUDE_DIRECTORIES( test PUBLIC
39+
${CREATIVE_ENGINE_INCLUDE_DIRS}
40+
${SDL2_INCLUDE_DIRS}
41+
${CMAKE_CURRENT_SOURCE_DIR}/test/src
42+
)
43+
TARGET_LINK_LIBRARIES(test ${CREATIVE_ENGINE_LINK_LIBRARIES})
44+
ADD_DEPENDENCIES( test ${PROJECT_NAME} )

0 commit comments

Comments
 (0)