forked from metomi/rose
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_header
91 lines (81 loc) · 2.62 KB
/
test_header
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/bin/bash
#-------------------------------------------------------------------------------
# (C) British Crown Copyright 2012-6 Met Office.
#
# This file is part of Rose, a framework for meteorological suites.
#
# Rose is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Rose is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Rose. If not, see <http://www.gnu.org/licenses/>.
#-------------------------------------------------------------------------------
# Provides init, setup and teardown functions for rose macro tests.
#-------------------------------------------------------------------------------
. $(dirname $0)/../lib/bash/test_header
function init() {
mkdir -p $TEST_DIR/config
cat >$TEST_DIR/config/rose-app.conf
}
function init_opt() {
local opt_key=$1
mkdir -p $TEST_DIR/config/opt/
cat >$TEST_DIR/config/opt/rose-app-$opt_key.conf
}
function init_meta() {
mkdir -p $TEST_DIR/config/meta
cat >$TEST_DIR/config/meta/rose-meta.conf
}
function init_rose_meta() {
category=$1
mkdir -p $TEST_DIR/rose-meta/$category/
shift
for version; do
mkdir -p $TEST_DIR/rose-meta/$category/$version/
touch $TEST_DIR/rose-meta/$category/$version/rose-meta.conf
done
}
function init_rose_meta_content() {
category=$1
version=$2
cat >$TEST_DIR/rose-meta/$category/$version/rose-meta.conf
}
function init_macro() {
mkdir -p $TEST_DIR/config/meta/lib/python/macros/
cat >$TEST_DIR/config/meta/lib/python/macros/$1
}
function init_rose_meta_macro() {
category=$1
version=$2
macro_filename=$3
mkdir -p "$TEST_DIR/rose-meta/$category/$version/lib/python/macros/"
touch "$TEST_DIR/rose-meta/$category/$version/lib/python/macros/__init__.py"
cat >"$TEST_DIR/rose-meta/$category/$version/lib/python/macros/$macro_filename"
}
function setup() {
mkdir $TEST_DIR/run
cd $TEST_DIR/run
}
function teardown() {
cd $TEST_DIR
rm -rf $TEST_DIR/run
rm -rf $TEST_DIR/config/meta
}
function grep_count_ok() {
local TEST_KEY=$1
local PATTERN=$2
local FILE=$3
local COUNT=$4
if (( $(grep "$PATTERN" "$FILE" -c) == $COUNT )); then
pass "$TEST_KEY"
return
fi
fail "$TEST_KEY"
}