Browse Source

Tests for application interface functions

Bob Mottram 8 years ago
parent
commit
4123b712fc
2 changed files with 102 additions and 0 deletions
  1. 6
    0
      src/freedombone
  2. 96
    0
      src/freedombone-tests

+ 6
- 0
src/freedombone View File

@@ -329,6 +329,12 @@ function parse_args {
329 329
 	fi
330 330
 }
331 331
 
332
+# run some initial tests
333
+${PROJECT_NAME}-tests
334
+if [ ! "$?" = "0" ]; then
335
+	exit 768252
336
+fi
337
+
332 338
 setup_utils
333 339
 setup_mesh
334 340
 setup_email

+ 96
- 0
src/freedombone-tests View File

@@ -0,0 +1,96 @@
1
+#!/bin/bash
2
+#
3
+# .---.                  .              .
4
+# |                      |              |
5
+# |--- .--. .-.  .-.  .-.|  .-. .--.--. |.-.  .-. .--.  .-.
6
+# |    |   (.-' (.-' (   | (   )|  |  | |   )(   )|  | (.-'
7
+# '    '     --'  --'  -' -  -' '  '   -' -'   -' '   -  --'
8
+#
9
+#                    Freedom in the Cloud
10
+#
11
+# Run tests on the system
12
+
13
+# License
14
+# =======
15
+#
16
+# Copyright (C) 2015-2016 Bob Mottram <bob@robotics.uk.to>
17
+#
18
+# This program is free software: you can redistribute it and/or modify
19
+# it under the terms of the GNU Affero General Public License as published by
20
+# the Free Software Foundation, either version 3 of the License, or
21
+# (at your option) any later version.
22
+#
23
+# This program is distributed in the hope that it will be useful,
24
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
25
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
26
+# GNU Affero General Public License for more details.
27
+#
28
+# You should have received a copy of the GNU Affero General Public License
29
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
30
+
31
+PROJECT_NAME='freedombone'
32
+
33
+export TEXTDOMAIN=${PROJECT_NAME}-tests
34
+export TEXTDOMAINDIR="/usr/share/locale"
35
+
36
+function show_help {
37
+    echo ''
38
+    echo $"${PROJECT_NAME}-tests"
39
+    echo ''
40
+    echo $'Runs tests on the system'
41
+    echo ''
42
+    echo $'     --help                   Show help'
43
+    echo ''
44
+    exit 0
45
+}
46
+
47
+function test_app_function_type {
48
+    filename=$1
49
+    fn_type=$2
50
+	app_name=$(echo "${filename}" | awk -F '-app-' '{print $2}')
51
+	app_function=$(cat "${filename}" | grep "function ${fn_type}_${app_name} {" | awk -F "${fn_type}_" '{print $2}' | awk -F ' ' '{print $1}')
52
+	if [ ! ${app_function} ]; then
53
+		echo $"Application ${app_name} does not contain a function called '${fn_type}_${app_name}'"
54
+		echo ''
55
+		echo "See ${filename}"
56
+		exit 72852
57
+	fi
58
+}
59
+
60
+function test_app_functions {
61
+	if [ -f /usr/local/bin/${PROJECT_NAME} ]; then
62
+		FILES=/usr/local/bin/${PROJECT_NAME}-app-*
63
+	else
64
+		FILES=/usr/bin/${PROJECT_NAME}-app-*
65
+	fi
66
+	
67
+	for filename in $FILES
68
+	do
69
+		test_app_function_type ${filename} install
70
+		test_app_function_type ${filename} remove
71
+		test_app_function_type ${filename} backup
72
+	done	
73
+}
74
+
75
+while [[ $# > 1 ]]
76
+do
77
+    key="$1"
78
+
79
+    case $key in
80
+        -h|--help)
81
+            show_help
82
+            ;;
83
+        *)
84
+            # unknown option
85
+            ;;
86
+    esac
87
+    shift
88
+done
89
+
90
+echo $'Running tests'
91
+
92
+test_app_functions
93
+
94
+echo $'All tests passed'
95
+
96
+exit 0