Skip to content

Commit 0f5d917

Browse files
authored
Merge pull request #19 from HRio/unit
apk: add some unit tests, called via "make check"
2 parents 77ee079 + 77f70cd commit 0f5d917

File tree

3 files changed

+46
-3
lines changed

3 files changed

+46
-3
lines changed

apk/Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
clean:
22

3+
check:
4+
./test-apt-dater-host
5+
36
install:
47
install -D -m0755 apt-dater-host \
58
$(DESTDIR)/usr/bin/apt-dater-host

apk/apt-dater-host

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
# Henrik Riomar <[email protected]>
1111
#
1212
# Copyright Holder:
13-
# 2016 (C) Henrik Riomar
13+
# 2016, 2017 (C) Henrik Riomar
1414
#
1515
# License:
1616
# This program is free software; you can redistribute it and/or modify
@@ -52,7 +52,7 @@ get_prl()
5252
# check if a pkg is held back
5353
is_held()
5454
{
55-
grep -E -q ^$1\= /etc/apk/world
55+
grep -E -q -e ^$1\= -e ^$1\< /etc/apk/world
5656
}
5757

5858
# check if $1 > $2
@@ -71,7 +71,7 @@ get_pkg_stat()
7171
$APK_CMD info | while read -r pkg
7272
do
7373
line=$(grep -E "^${pkg}-[0-9]" $tmp)
74-
new_ver=$(echo $line | awk '{print $NF}')
74+
new_ver=$(echo $line | sed 's/ @.\+$//' | awk '{print $NF}')
7575
cur_ver=$(echo $line | awk '{print $1}' | sed "s/$pkg-//")
7676
if [ x"$new_ver" = x"$cur_ver" ]; then
7777
echo "STATUS: $pkg|$cur_ver|i"
@@ -212,6 +212,10 @@ case "$1" in
212212
get_kern
213213
;;
214214

215+
source-only)
216+
# do nothing (used for unit testing)
217+
;;
218+
215219
*)
216220
echo Invalid command \'$1\'\!
217221
exit $err

apk/test-apt-dater-host

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/usr/bin/env bats
2+
3+
source ./apt-dater-host source-only
4+
5+
check_tag()
6+
{
7+
TAG=$1
8+
STR=$2
9+
[ $(echo $STR | grep -E -v -c "^$TAG:") -eq 0 ]
10+
}
11+
12+
@test "say_hi()" {
13+
result="$(say_hi)"
14+
check_tag ADPROTO $result
15+
[ "$result" = "ADPROTO: 0.6" ]
16+
}
17+
18+
@test "get_lsbrel()" {
19+
result="$(get_lsbrel)"
20+
check_tag LSBREL $result
21+
}
22+
23+
@test "get_pkg_stat()" {
24+
result="$(get_pkg_stat)"
25+
check_tag STATUS $result
26+
}
27+
28+
@test "get_virt()" {
29+
result="$(get_virt)"
30+
check_tag VIRT $result
31+
}
32+
33+
@test "get_kern()" {
34+
result="$(get_kern)"
35+
check_tag KERNELINFO $result
36+
}

0 commit comments

Comments
 (0)