barectf_config_check_fail(): check that failure is caused by cfg. error
[deliverable/barectf.git] / tests / config / common.bash
CommitLineData
0a7000dc
PP
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
60522caf
MJ
23barectf_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
35barectf_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
bed7233f 52barectf_config_check_fail() {
60522caf
MJ
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
25b9c2fe
PP
62 if [[ $output != *'configuration: cannot create configuration'* ]]; then
63 echo "Fail: barectf does not print a configuration error" 1>&2
64 popd >/dev/null
65 return 1
66 fi
67
60522caf 68 if [ "$status" -eq 0 ]; then
bed7233f 69 echo "Fail: exit code is 0" 1>&2
60522caf 70 popd >/dev/null
bed7233f
PP
71 return 1
72 fi
73
bed7233f 74 local find_output="$(find -iname '*.c' -o -iname '*.h' -o -iname metadata)"
60522caf 75 popd >/dev/null
bed7233f
PP
76
77 if [ -n "$find_output" ]; then
78 echo "Fail: barectf generated files" 1>&2
79 return 1
80 fi
81}
82
83setup() {
84 :
85}
86
87teardown() {
88 rm -f *ctf.c *ctf.h *ctf.o *ctf-bitfield.h metadata
89}
This page took 0.031312 seconds and 4 git commands to generate.