Introducing new main() to enable creation of UNIT tests.

This commit is contained in:
Martin Dvorak 2018-08-12 08:25:04 +02:00
parent 05b667e0e3
commit 742c51c756
10 changed files with 141 additions and 10 deletions

3
.gitignore vendored
View file

@ -15,6 +15,7 @@ Makefile
Makefile.in
*.o
*.snap
hstr.pro.user
*.*~
hstr
*.pro.user
test/hstr-unit-tests

View file

@ -1,4 +1,4 @@
# Maintainer: Christian Wieden <wiedenchr at gmail dot com
# Maintainer: Christian Wieden <wiedenchr at gmail dot com>
# Contributor: Ricardo Band <me at xengi dot de>
# Contributor: Filip Szymański <fszymanski at, fedoraproject.org>

View file

@ -1,5 +1,4 @@
# configure.ac Autoconf configuration file
# process this file with autoconf to produce a configure script
#
# Copyright (C) 2014-2018 Martin Dvorak <martin.dvorak@mindforger.com>
#
@ -15,12 +14,16 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Process this file with autoconf to produce a configure script.
#
AC_PREREQ([2.69])
AC_INIT(hh, 1.27.0, martin.dvorak@mindforger.com)
AC_CONFIG_FILES([Makefile src/Makefile man/Makefile])
# Checks for src dir existence.
# Check src dir existence.
AC_CONFIG_SRCDIR([src/hstr.c])
# Init (no longer takes parameters).

View file

@ -1,4 +1,4 @@
# hstr.pro Qt project file for HSTR
# hstr.pro Qt project file for HSTR shell history compleation utility
#
# Copyright (C) 2014-2018 Martin Dvorak <martin.dvorak@mindforger.com>
#
@ -31,7 +31,8 @@ SOURCES += \
src/hstr_regexp.c \
src/hstr_utils.c \
src/hstr.c \
src/radixsort.c
src/radixsort.c \
src/main.c
HEADERS += \
src/include/hashset.h \
@ -41,7 +42,8 @@ HEADERS += \
src/include/hstr_history.h \
src/include/hstr_regexp.h \
src/include/hstr_utils.h \
src/include/radixsort.h
src/include/radixsort.h \
src/include/hstr.h
# compiler and linker
QMAKE_CC = ccache gcc

View file

@ -30,7 +30,8 @@ hh_SOURCES = \
hstr_blacklist.c include/hstr_blacklist.h \
hstr_regexp.c include/hstr_regexp.h \
radixsort.c include/radixsort.h \
hstr.c
hstr.c include/hstr.h \
main.c
# create hh > hstr hard link on installation
install-exec-hook:

View file

@ -1,5 +1,5 @@
/*
hstr.c BASH history completion utility
hstr.c HSTR shell history completion utility
Copyright (C) 2014-2018 Martin Dvorak <martin.dvorak@mindforger.com>
@ -47,6 +47,8 @@
#include "include/hstr_regexp.h"
#include "include/hstr_utils.h"
#include "include/hstr.h"
#define SELECTION_CURSOR_IN_PROMPT -1
#define SELECTION_PREFIX_MAX_LNG 512
#define CMDLINE_LNG 2048
@ -1490,7 +1492,7 @@ void hstr_getopt(int argc, char **argv, Hstr *hstr)
}
}
int main(int argc, char *argv[])
int hstrMain(int argc, char *argv[])
{
setlocale(LC_ALL, "");

24
src/include/hstr.h Normal file
View file

@ -0,0 +1,24 @@
/*
hstr.h header file for HSTR shell history completion utility
Copyright (C) 2014-2018 Martin Dvorak <martin.dvorak@mindforger.com>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#ifndef HSTR_H_
#define HSTR_H_
int hstrMain(int argc, char *argv[]);
#endif

24
src/main.c Normal file
View file

@ -0,0 +1,24 @@
/*
main.c HSTR shell history completion utility main
Copyright (C) 2014-2018 Martin Dvorak <martin.dvorak@mindforger.com>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#include "include/hstr.h"
int main(int argc, char *argv[])
{
return hstrMain(argc, argv);
}

50
test/hstr-unit-tests.pro Normal file
View file

@ -0,0 +1,50 @@
# hstr-unit-tests.pro Qt project file of UNIT tests for HSTR
#
# Copyright (C) 2014-2018 Martin Dvorak <martin.dvorak@mindforger.com>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
TEMPLATE = app
CONFIG += console
CONFIG -= app_bundle
CONFIG -= qt
# -L for where to look for library, -l for linking the library
LIBS += -lm -lreadline -lncursesw
SOURCES += \
../src/hashset.c \
../src/hstr_blacklist.c \
../src/hstr_curses.c \
../src/hstr_favorites.c \
../src/hstr_history.c \
../src/hstr_regexp.c \
../src/hstr_utils.c \
../src/hstr.c \
../src/radixsort.c \
../test/src/test.c
HEADERS += \
../src/include/hashset.h \
../src/include/hstr_blacklist.h \
../src/include/hstr_curses.h \
../src/include/hstr_favorites.h \
../src/include/hstr_history.h \
../src/include/hstr_regexp.h \
../src/include/hstr_utils.h \
../src/include/radixsort.h \
../src/include/hstr.h
# compiler and linker
QMAKE_CC = ccache gcc
QMAKE_LINK = gcc

24
test/src/test.c Normal file
View file

@ -0,0 +1,24 @@
/*
main.c UNIT tests main for HSTR shell history completion utility
Copyright (C) 2014-2018 Martin Dvorak <martin.dvorak@mindforger.com>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#include "../../src/include/hstr.h"
int main(int argc, char *argv[])
{
return hstrMain(argc, argv);
}