From fbc029b1b1f72f61b0d21d1083786de8e4dbeff1 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Fri, 18 May 2018 14:03:22 +1000 Subject: [PATCH 1/4] general: Added tests --- neofetch | 2 +- tests/test_misc.sh | 37 +++++++++++++++++++++++++++++++++++++ tests/test_util.sh | 10 ++++++++++ 3 files changed, 48 insertions(+), 1 deletion(-) create mode 100755 tests/test_misc.sh create mode 100644 tests/test_util.sh diff --git a/neofetch b/neofetch index d0bc8a95..cfc64e08 100755 --- a/neofetch +++ b/neofetch @@ -8724,4 +8724,4 @@ main() { return 0 } -main "$@" +[[ "$0" == "${BASH_SOURCE[0]}" ]] && main "$@" diff --git a/tests/test_misc.sh b/tests/test_misc.sh new file mode 100755 index 00000000..d5536516 --- /dev/null +++ b/tests/test_misc.sh @@ -0,0 +1,37 @@ +#!/usr/bin/env bash +# +# Test misc functions. + +source test_util.sh +source ../neofetch + +# Tests only work on Linux for now. +os="Linux" + + +test_convert_time() { + # 24 hour time. + result="$(convert_time "2016" "04" "14" "23:50")" + assert_equals "$result" "Thu 14 Apr 2016 23:50" + + # 12 hour time. + install_time_format="12h" + result="$(convert_time "2016" "04" "14" "23:50")" + assert_equals "$result" "Thu 14 Apr 2016 11:50 PM" +} + +test_get_ppid() { + result="$(trim "$(get_ppid "1")")" + assert_equals "$result" "0" +} + +test_get_process_name() { + result="$(get_process_name "1")" + assert_equals "$result" "systemd" +} + + +printf "%s\\n" "Test MISC functions." +test_convert_time +test_get_ppid +test_get_process_name diff --git a/tests/test_util.sh b/tests/test_util.sh new file mode 100644 index 00000000..1eecc998 --- /dev/null +++ b/tests/test_util.sh @@ -0,0 +1,10 @@ +#!/usr/bin/env bash +# +# Test util functions. + +assert_equals() { + # Test equality. + local status + [[ "$1" == "$2" ]] && status="✔" + printf "%s\\n" " ${status:-✖} : ${FUNCNAME[1]}" +} From 3b571049975966567189e1f69f7bfad84984b718 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Fri, 18 May 2018 14:04:20 +1000 Subject: [PATCH 2/4] travis: Run initial tests. --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index aac1b2fc..6d9587e8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -20,3 +20,4 @@ script: # Check for lines longer than 100 chars. # There are 3 lines that must be longer than 100 chars. - if (("$(grep '.\{101\}' neofetch | wc -l)" > 3)); then (exit 1); else (exit 0); fi + - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then cd tests; ./test_misc.sh; fi From 5fb3ab6ee39022b0866e7285af808736e586f119 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Fri, 18 May 2018 14:28:56 +1000 Subject: [PATCH 3/4] tests: properly set exit code. --- tests/test_misc.sh | 3 +++ tests/test_util.sh | 1 + 2 files changed, 4 insertions(+) diff --git a/tests/test_misc.sh b/tests/test_misc.sh index d5536516..6f1dd405 100755 --- a/tests/test_misc.sh +++ b/tests/test_misc.sh @@ -32,6 +32,9 @@ test_get_process_name() { printf "%s\\n" "Test MISC functions." + test_convert_time test_get_ppid test_get_process_name + +[[ -f /tmp/err ]] || exit 0 && { rm /tmp/err; exit 1; } diff --git a/tests/test_util.sh b/tests/test_util.sh index 1eecc998..32657f9a 100644 --- a/tests/test_util.sh +++ b/tests/test_util.sh @@ -7,4 +7,5 @@ assert_equals() { local status [[ "$1" == "$2" ]] && status="✔" printf "%s\\n" " ${status:-✖} : ${FUNCNAME[1]}" + [[ "$1" == "$2" ]] || { :>/tmp/err; return 1; } && return 0 } From 92bf7da15a1616e03092e478d4ae1ecc6e8d3f9e Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Fri, 18 May 2018 14:35:31 +1000 Subject: [PATCH 4/4] tests: Add main test file --- .travis.yml | 2 +- tests/test.sh | 7 +++++++ tests/test_misc.sh | 8 -------- tests/test_util.sh | 0 4 files changed, 8 insertions(+), 9 deletions(-) create mode 100755 tests/test.sh mode change 100644 => 100755 tests/test_util.sh diff --git a/.travis.yml b/.travis.yml index 6d9587e8..03e24fb0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -20,4 +20,4 @@ script: # Check for lines longer than 100 chars. # There are 3 lines that must be longer than 100 chars. - if (("$(grep '.\{101\}' neofetch | wc -l)" > 3)); then (exit 1); else (exit 0); fi - - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then cd tests; ./test_misc.sh; fi + - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then cd tests && ./test.sh; fi diff --git a/tests/test.sh b/tests/test.sh new file mode 100755 index 00000000..07b71e99 --- /dev/null +++ b/tests/test.sh @@ -0,0 +1,7 @@ +#!/usr/bin/env bash +# +# Run all tests. + +./test_misc.sh + +[[ -f /tmp/err ]] || exit 0 && { rm /tmp/err; exit 1; } diff --git a/tests/test_misc.sh b/tests/test_misc.sh index 6f1dd405..65f626a2 100755 --- a/tests/test_misc.sh +++ b/tests/test_misc.sh @@ -25,16 +25,8 @@ test_get_ppid() { assert_equals "$result" "0" } -test_get_process_name() { - result="$(get_process_name "1")" - assert_equals "$result" "systemd" -} - printf "%s\\n" "Test MISC functions." test_convert_time test_get_ppid -test_get_process_name - -[[ -f /tmp/err ]] || exit 0 && { rm /tmp/err; exit 1; } diff --git a/tests/test_util.sh b/tests/test_util.sh old mode 100644 new mode 100755