1#!/bin/bash
2#
3# Copyright (C) 2014-2020  Martin Dvorak <martin.dvorak@mindforger.com>
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9#    http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
17# Run HSTR w/ 1 history entry to hunt memleaks w/ valgrind
18
19#export OPT_ALL_SCENARIOS=true
20
21# both valid and INVALID history file to be tested
22#export HISTFILE=
23export HISTFILE="/tmp/invalid-history-file-01"
24#export HISTFILE="~/.bash_history"
25#export HISTFILE="~/.zhistory"
26#export HISTFILE="~/.zshrc"
27
28# build
29cd .. && qmake CONFIG+=hstrdebug hstr.pro && make clean && make -j 8
30if [ ${?} -ne 0 ]
31then
32    exit 1
33fi
34
35# test scenarios
36export FILE_SCENARIOS="/tmp/hstr-scenarios.txt"
37if [ ${OPT_ALL_SCENARIOS} ]
38then
39    echo "./hstr --help" > ${FILE_SCENARIOS}
40    echo "./hstr --version" >> ${FILE_SCENARIOS}
41    echo "./hstr --kill-last-command" > ${FILE_SCENARIOS}
42    echo "./hstr --show-configuration" >> ${FILE_SCENARIOS}
43    echo "./hstr --show-zsh-configuration" >> ${FILE_SCENARIOS}
44    echo "./hstr --show-blacklist" >> ${FILE_SCENARIOS}
45    echo "./hstr --non-interactive echo" >> ${FILE_SCENARIOS}
46    echo "./hstr -n log" >> ${FILE_SCENARIOS}
47else
48    echo "./hstr -k" > ${FILE_SCENARIOS}
49fi
50# ELSE following scenarios must be run MANUALLY from CLI
51# valgrind --track-origins=yes --tool=memcheck --leak-check=full --show-leak-kinds=all ./hstr
52#   ENTER
53#   Ctrl-g
54#   a > ENTER
55#   a > right arrow
56# valgrind --track-origins=yes --tool=memcheck --leak-check=full --show-leak-kinds=all ./hstr log
57#   ENTER
58#   Ctrl-g
59#   right arrow
60
61
62
63# test history file - comment ALL HISTFILE exports below for test w/ production
64#export HISTFILE=`pwd`/../test/resources/.bash_history_valgrind_empty
65#export HISTFILE=`pwd`/../test/resources/.bash_history_valgrind_1_entry
66
67# run tests w/ Valgrind
68cat ${FILE_SCENARIOS} | while read SCENARIO
69do
70    # Valgrind
71    valgrind --track-origins=yes --tool=memcheck --leak-check=full --show-leak-kinds=all ${SCENARIO}
72
73    # Valgrind's GDB
74    #valgrind --vgdb=yes --vgdb-error=0 --track-origins=yes --tool=memcheck --leak-check=full --show-leak-kinds=all ${SCENARIO}
75done
76
77# eof
78