Introduce new barectf configuration API and YAML configuration schema
[deliverable/barectf.git] / tests / config / common.bash
1 # The MIT License (MIT)
2 #
3 # Copyright (c) 2016 Philippe Proulx <pproulx@efficios.com>
4 #
5 # Permission is hereby granted, free of charge, to any person obtaining a copy
6 # of this software and associated documentation files (the "Software"), to deal
7 # in the Software without restriction, including without limitation the rights
8 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 # copies of the Software, and to permit persons to whom the Software is
10 # furnished to do so, subject to the following conditions:
11 #
12 # The above copyright notice and this permission notice shall be included in
13 # all copies or substantial portions of the Software.
14 #
15 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 # THE SOFTWARE.
22
23 barectf_assert_file_exists() {
24 if [ ! -f "$1" ]; then
25 echo "FATAL: "$1" does not exist" 1>&2
26 return 1
27 fi
28
29 if ! which barectf > /dev/null; then
30 echo "FATAL: cannot find barectf tool" 1>&2
31 return 1
32 fi
33 }
34
35 barectf_config_check_success() {
36 pushd "$BATS_TEST_DIRNAME" >/dev/null
37
38 if ! barectf_assert_file_exists "$1"; then
39 popd >/dev/null
40 return 1
41 fi
42
43 run barectf "$1"
44 popd >/dev/null
45
46 if [ "$status" -ne 0 ]; then
47 echo "Fail: exit code is $status" 1>&2
48 return 1
49 fi
50 }
51
52 barectf_config_check_fail() {
53 pushd "$BATS_TEST_DIRNAME" >/dev/null
54
55 if ! barectf_assert_file_exists "$1"; then
56 popd >/dev/null
57 return 1
58 fi
59
60 run barectf "$1"
61
62 if [[ $output != *'Cannot create configuration'* ]]; then
63 echo "Fail: barectf does not print a configuration error" 1>&2
64 echo "Output:" 1>&2
65 echo "$output" 1>&2
66 popd >/dev/null
67 return 1
68 fi
69
70 if [ "$status" -eq 0 ]; then
71 echo "Fail: exit code is 0" 1>&2
72 popd >/dev/null
73 return 1
74 fi
75
76 local find_output="$(find -iname '*.c' -o -iname '*.h' -o -iname metadata)"
77 popd >/dev/null
78
79 if [ -n "$find_output" ]; then
80 echo "Fail: barectf generated files" 1>&2
81 return 1
82 fi
83 }
84
85 setup() {
86 :
87 }
88
89 teardown() {
90 rm -f *ctf.c *ctf.h *ctf.o *ctf-bitfield.h metadata
91 }
This page took 0.03042 seconds and 4 git commands to generate.