Skip to content

Commit 755da1e

Browse files
make tests run automagically instead of only building them
1 parent 1d82b2e commit 755da1e

File tree

6 files changed

+40
-6
lines changed

6 files changed

+40
-6
lines changed

.gitignore

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,21 @@
1+
# Ignore all
2+
*
3+
4+
# Unignore all with extensions
5+
!*.*
6+
7+
# Unignore all dirs
8+
!*/
9+
110
tests/*/build
211
tests/build
312
tests/tests.pro
13+
Makefile
14+
.qmake.stash
15+
*.qmake.stash
16+
*qmake.stash
17+
/.qmake.stash
18+
*.o
19+
run-tests.sh
20+
tests.pro
21+
/.qmake.stash

tests/generate_tests.py

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,28 @@
11
#!/usr/bin/env python3
22

33
''' generates a tests.pro file by crawling the directory and generating a subdirs
4-
entry for each subdirectory '''
4+
entry for each subdirectory. Additionally it generates a run script for the tests to get executed,
5+
assuming the binary produced is named like the directory'''
56

67
import os
78

89
with open(os.path.dirname(os.path.realpath(__file__)) + "/tests.pro", "w") as projectfile:
9-
projectfile.write("TEMPLATE=subdirs\nSUBDIRS= \\\n")
10-
PATH = os.path.dirname(os.path.realpath(__file__))
11-
for item in os.listdir(PATH):
12-
if os.path.isdir(os.path.join(PATH, item)):
13-
projectfile.write(item + " \\\n")
10+
with open(os.path.dirname(os.path.realpath(__file__)) + "/run-tests.sh", "w") as runscript:
11+
projectfile.write("TEMPLATE=subdirs\nSUBDIRS= \\\n")
12+
runscriptContent = "\
13+
#!/bin/sh\n\
14+
set -e\n\
15+
set -x\n\
16+
if [ ! -z $1 ]; then\n\
17+
TEST_ROOT=$1\n\
18+
else\n\
19+
TEST_ROOT=.\n\
20+
fi\n"
21+
runscript.write(runscriptContent)
22+
PATH = os.path.dirname(os.path.realpath(__file__))
23+
for item in os.listdir(PATH):
24+
if os.path.isdir(os.path.join(PATH, item)):
25+
projectfile.write(item + " \\\n")
26+
runscript.write("timeout 10s $TEST_ROOT/" +
27+
item + "/" + item + "\n")
28+
os.chmod(os.path.dirname(os.path.realpath(__file__)) + "/run-tests.sh", 0o744)

tests/qt-hello-world/main.cpp renamed to tests/helloworld/main.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ int main()
44
{
55
QString hello("Hello World!");
66
qDebug() << hello;
7+
return 0;
78
}
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)