Reduce the number of Makefiles in 'doc/'
[babeltrace.git] / tests / plugins / src.ctf.fs / query / test_query_metadata_info
CommitLineData
b34bfe00
FD
1#!/bin/bash
2#
0235b0db
MJ
3# SPDX-License-Identifier: GPL-2.0-only
4#
b34bfe00
FD
5# Copyright (C) 2019 Simon Marchi <simon.marchi@efficios.com>
6# Copyright (C) 2019 Francis Deslauriers <francis.deslauriers@efficios.com>
7#
b34bfe00
FD
8
9SH_TAP=1
10
75e396f6 11if [ -n "${BT_TESTS_SRCDIR:-}" ]; then
b34bfe00
FD
12 UTILSSH="$BT_TESTS_SRCDIR/utils/utils.sh"
13else
14 UTILSSH="$(dirname "$0")/../../../utils/utils.sh"
15fi
16
17# shellcheck source=../../../utils/utils.sh
18source "$UTILSSH"
19
20this_dir_relative="plugins/src.ctf.fs/query"
b34bfe00
FD
21succeed_trace_dir="$BT_CTF_TRACES_PATH/succeed"
22expect_dir="$BT_TESTS_DATADIR/$this_dir_relative"
23
24test_query_metadata_info() {
25 local name="$1"
26 local ret=0
27 local trace_path="$succeed_trace_dir/$name"
28 local expected_stdout="$expect_dir/metadata-info-$name.expect"
ba9ea7f5
SM
29 local temp_stdout_output_file
30 local temp_stderr_output_file
b34bfe00
FD
31 local query=("query" "src.ctf.fs" "metadata-info" "--params" "path=\"$trace_path\"")
32
ba9ea7f5
SM
33 temp_stdout_output_file="$(mktemp -t actual_stdout.XXXXXX)"
34 temp_stderr_output_file="$(mktemp -t actual_stderr.XXXXXX)"
35
b34bfe00
FD
36 bt_cli "$temp_stdout_output_file" "$temp_stderr_output_file" \
37 "${query[@]}"
38
39 bt_diff "$expected_stdout" "$temp_stdout_output_file"
40 ret_stdout=$?
41
42 bt_diff /dev/null "$temp_stderr_output_file"
43 ret_stderr=$?
44
45 if ((ret_stdout != 0 || ret_stderr != 0)); then
46 ret=1
47 fi
48
49 ok $ret "Trace '$name' \`metadata-info\` query gives the expected output"
50 rm -f "$temp_stdout_output_file" "$temp_stderr_output_file"
51}
52
0ac40cd4
SM
53test_non_existent_trace_dir() {
54 local empty_dir
55 local stdout_file
56 local stderr_file
57 local query
58
59 empty_dir=$(mktemp -d)
60 stdout_file="$(mktemp -t actual_stdout.XXXXXX)"
61 stderr_file="$(mktemp -t actual_stderr.XXXXXX)"
62 query=("query" "src.ctf.fs" "metadata-info" "--params" "path=\"$empty_dir\"")
63
64 bt_cli "$stdout_file" "$stderr_file" \
65 "${query[@]}"
66 isnt $? 0 "non existent trace dir: babeltrace exits with an error"
67
68 bt_diff "/dev/null" "${stdout_file}"
69 ok $? "non existent trace dir: babeltrace produces the expected stdout"
70
71 grep --silent "^CAUSED BY " "${stderr_file}"
72 ok $? "non existent trace dir: babeltrace produces an error stack"
73
74 grep --silent "Failed to open metadata file: No such file or directory: path=\".*metadata\"" \
75 "${stderr_file}"
76 ok $? "non existent trace dir: babeltrace produces the expected error message"
77
78 rm -f "${stdout_file}" "${stderr_file}"
79}
80
454605f1 81plan_tests 7
b34bfe00 82test_query_metadata_info succeed1
0ac40cd4 83test_non_existent_trace_dir
454605f1
MJ
84test_query_metadata_info lf-metadata
85test_query_metadata_info crlf-metadata
This page took 0.049944 seconds and 4 git commands to generate.