Skip to content

Commit

Permalink
Fixing tests and adding GitHub Actions build which resolves #472
Browse files Browse the repository at this point in the history
  • Loading branch information
dvorka committed Dec 11, 2022
1 parent f945c7f commit 9913d7a
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 1 deletion.
31 changes: 31 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
* text=auto

# These files are text and should be normalized (convert crlf to lf)
*.rb text
*.test text
*.c text
*.cpp text
*.h text
*.txt text
*.yml text
*.s79 text
*.bat text
*.xcl text
*.inc text
*.info text
*.md text
makefile text
rakefile text
meson.build text


#These files are binary and should not be normalized
*.doc binary
*.odt binary
*.pdf binary
*.ewd binary
*.eww binary
*.dni binary
*.wsdt binary
*.dbgdt binary
*.mac binary
17 changes: 17 additions & 0 deletions .github/workflows/build_ubuntu.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Ubuntu unit tests

on: [push]

jobs:
build:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
with:
submodules: recursive

- name: Install packages
run: sudo apt-get update && sudo apt install -y build-essential qttools5-dev-tools ccache libncursesw5-dev libreadline-dev

- name: Build lib and run unit tests using Unity test framework
run: cd test && qmake hstr-unit-tests.pro && make clean all && ./hstr-unit-tests
2 changes: 2 additions & 0 deletions src/hstr_history.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,11 @@ char* parse_history_line(char *l)
}
}

#ifndef HSTR_TESTS_UNIT
if (isZsh) {
l = zsh_unmetafy(l, NULL);
}
#endif

return l;
}
Expand Down
29 changes: 28 additions & 1 deletion test/src/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,26 +35,31 @@

/*
* IMPORTANT: make sure to run TEST RUNNER GENERATOR script after any change to this file!
*
*/

void setUp(void)
{
// code to be run before this test suite
}

void tearDown(void)
{
// code to be after this test suite
}

void test_args(void)
{
printf("\n= %s ========================================\n", __FUNCTION__);

// GIVEN
const unsigned LINELNG = 500;
int argc = 3;
char* argv[argc];
argv[0] = "hstr";
argv[1] = "-o";
argv[2] = "_args";

// WHEN
if(argc>0) {
int i;
char line[LINELNG];
Expand All @@ -72,6 +77,7 @@ void test_args(void)
strcat(line, " ");
}

// THEN
printf("#%s#\n", line);
TEST_ASSERT_EQUAL_STRING("hstr -o _args ", line);
} else {
Expand All @@ -81,6 +87,9 @@ void test_args(void)

void test_getopt(void)
{
printf("\n= %s ========================================\n", __FUNCTION__);

// GIVEN
int argc = 3;
char* argv[argc];
argv[0] = "hstr";
Expand Down Expand Up @@ -164,6 +173,8 @@ void test_getopt(void)

void test_locate_char_in_string_overflow(void)
{
printf("\n= %s ========================================\n", __FUNCTION__);

TEST_ASSERT_EQUAL_STRING(0, strchr("a\nb",1));

printf("%s\n",strchr("a\nb",98));
Expand All @@ -175,6 +186,8 @@ void test_locate_char_in_string_overflow(void)

void test_favorites(void)
{
printf("\n= %s ========================================\n", __FUNCTION__);

FavoriteItems favoriteItems;

favorites_init(&favoriteItems);
Expand All @@ -199,6 +212,8 @@ void test_favorites(void)

void test_hashset_blacklist()
{
printf("\n= %s ========================================\n", __FUNCTION__);

const char* commandBlacklist[] = { "a","b","c","d","e" };
HashSet blacklist;
int i;
Expand All @@ -214,6 +229,8 @@ void test_hashset_blacklist()

void test_hashset_get_keys()
{
printf("\n= %s ========================================\n", __FUNCTION__);

const char* commandBlacklist[] = { "a","b","c","d","e" };
HashSet blacklist;
int i;
Expand All @@ -235,6 +252,8 @@ void test_hashset_get_keys()

void test_regexp(void)
{
printf("\n= %s ========================================\n", __FUNCTION__);

unsigned REGEXP_MATCH_BUFFER_SIZE = 10;

bool caseSensitive=false;
Expand Down Expand Up @@ -275,6 +294,8 @@ void test_regexp(void)

void test_help_long(void)
{
printf("\n= %s ========================================\n", __FUNCTION__);

TEST_IGNORE_MESSAGE("Tests exits the program");

char* ARG_HSTR = "hstr";
Expand All @@ -291,6 +312,8 @@ void test_help_long(void)

void test_help_short(void)
{
printf("\n= %s ========================================\n", __FUNCTION__);

TEST_IGNORE_MESSAGE("Tests exits the program");

char* ARG_HSTR = "hstr";
Expand All @@ -307,6 +330,8 @@ void test_help_short(void)

void test_string_elide()
{
printf("\n= %s ========================================\n", __FUNCTION__);

char buffer[1000];

// do nothing - string fits to screen
Expand Down Expand Up @@ -339,6 +364,8 @@ void test_string_elide()

void test_parse_history_line()
{
printf("\n= %s ========================================\n", __FUNCTION__);

TEST_ASSERT_EQUAL(NULL, parse_history_line(NULL));

TEST_ASSERT_EQUAL_STRING("ls", parse_history_line("ls"));
Expand Down

0 comments on commit 9913d7a

Please sign in to comment.