Compare commits

...

4 commits

Author SHA1 Message Date
Dylan Araps
92bf7da15a tests: Add main test file 2018-05-18 14:35:31 +10:00
Dylan Araps
5fb3ab6ee3 tests: properly set exit code. 2018-05-18 14:28:56 +10:00
Dylan Araps
3b57104997 travis: Run initial tests. 2018-05-18 14:04:20 +10:00
Dylan Araps
fbc029b1b1 general: Added tests 2018-05-18 14:03:22 +10:00
5 changed files with 52 additions and 1 deletions

View file

@ -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.sh; fi

View file

@ -8724,4 +8724,4 @@ main() {
return 0
}
main "$@"
[[ "$0" == "${BASH_SOURCE[0]}" ]] && main "$@"

7
tests/test.sh Executable file
View file

@ -0,0 +1,7 @@
#!/usr/bin/env bash
#
# Run all tests.
./test_misc.sh
[[ -f /tmp/err ]] || exit 0 && { rm /tmp/err; exit 1; }

32
tests/test_misc.sh Executable file
View file

@ -0,0 +1,32 @@
#!/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"
}
printf "%s\\n" "Test MISC functions."
test_convert_time
test_get_ppid

11
tests/test_util.sh Executable file
View file

@ -0,0 +1,11 @@
#!/usr/bin/env bash
#
# Test util functions.
assert_equals() {
# Test equality.
local status
[[ "$1" == "$2" ]] && status="✔"
printf "%s\\n" " ${status:-} : ${FUNCNAME[1]}"
[[ "$1" == "$2" ]] || { :>/tmp/err; return 1; } && return 0
}