/
generateCodeCoverage.sh
76 lines (63 loc) · 2.95 KB
/
generateCodeCoverage.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/usr/bin/env bash
# WARNING, ASSUMES THAT YOU HAVE:
# lcov & google-chrome
# See issue 133 for motivation on why visual aspects were excluded from the code coverage report.
# Run the following command to install lcov:
# sudo apt-get install lcov
# Build the testing executable.
echo -e "\e[0;32m[STATUS] Building test executable ...\e[0m"
cd game
rm -r build
rm -r CodeCoverageReport
mkdir build
cd build
cmake ..
make
# Run the unit tests.
echo -e "\e[0;32m[STATUS] Running tests ...\e[0m"
cd testing
test_output=$(./unit-test 2>&1)
test_exitcode=$?
echo "$test_output"
echo -e "\e[0;31m[STATUS] Test runner exitcode = $test_exitcode \e[0m"
if [[ $test_exitcode = 1 ]]; then
echo -e "\e[0;31m[STATUS] The test suite failed! Fix failing tests before generating code coverage!\e[0m"
exit 1
fi
if [[ $test_exitcode = 139 ]]; then
echo -e "\e[0;31m[STATUS] The test suite failed! Fix failing tests before generating code coverage!\e[0m"
exit 1
fi
if [[ $test_exitcode = 0 ]]; then
echo -e "\e[0;35m[STATUS] The test suite passed! Continuing code coverage generation process ...\e[0m"
fi
# Generate html test report using lcov.
echo -e "\e[0;32m[STATUS] Generating coverage report ...\e[0m"
cd ..
cd ..
lcov --capture --directory build --output-file coverage.info
# These files are excluded from testing coverage because they are tested by the description-based-tests.
# It is not a good strategy to test visuals using unit tests because verification that something is displayed
# correctly is difficult and can be verified by a hum running the description-based-tests.
lcov -r coverage.info '/src/rendering/RenderWrapper.cpp' -o coverage.info
lcov -r coverage.info '/src/rendering/AssetFactory.cpp' -o coverage.info
lcov -r coverage.info '/src/rendering/AnimatedSprite.cpp' -o coverage.info
lcov -r coverage.info '/src/rendering/Animation.cpp' -o coverage.info
lcov -r coverage.info '/src/rendering/AnimationHandler.cpp' -o coverage.info
# Tests have been written for the AssetLoader and the AnimationData class but unfortunately they fail on CI because SFML has no headless mode.
# The tests can be run by enabling them from testMain.cpp.
# They cover the AssetLoader and the AnimationData class almost entirely thus we excluded it from coverage to get an accurate portrayal of
# what our coverage would be if it ran on CI.
lcov -r coverage.info '/src/rendering/AssetLoader.cpp' -o coverage.info
lcov -r coverage.info '/src/rendering/AnimationData.cpp' -o coverage.info
lcov -r coverage.info '/usr/include/*' -o coverage.info
lcov -r coverage.info '/testing/googletest/*' -o coverage.info
lcov -r coverage.info '/testing/test-src/*' -o coverage.info
lcov -r coverage.info '*.h' -o coverage.info
genhtml coverage.info --output-directory CodeCoverageReport
rm coverage.info
echo -e "\e[0;32m[STATUS] Coverage report generated!\e[0m"
# Open the report (remove/edit if you do not use chrome)
cd CodeCoverageReport
echo -e "\e[0;32m[STATUS] Opening page in chrome ...\e[0m"
google-chrome index.html