From fbc029b1b1f72f61b0d21d1083786de8e4dbeff1 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Fri, 18 May 2018 14:03:22 +1000 Subject: [PATCH] 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]}" +}