Skip to content

Commit fdfa6db

Browse files
authored
rewrite tests (#515)
* rewrite tests to work with meson This ports our tests to meson and makes them able to be run in parallel. * add tests to ci * rewrite test/check-trailing-newlines in bash This test was using a GNU sed command which does not work on Alpine Linux.
1 parent 0b3f875 commit fdfa6db

15 files changed

+141
-112
lines changed

.github/workflows/ci-alpine-linux.yml

+4-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ jobs:
2323
- run: meson setup builddir/
2424
env:
2525
CC: gcc
26-
- run: ninja -C builddir
26+
- run: meson compile -C builddir
27+
env:
28+
CC: gcc
29+
- run: meson test --verbose -C builddir
2730
env:
2831
CC: gcc

.github/workflows/ci-ubuntu.yml

+6
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ jobs:
1616
- run: ninja -C builddir
1717
env:
1818
CC: gcc
19+
- run: ninja test --verbose -C builddir
20+
env:
21+
CC: gcc
1922

2023

2124
clang-glibc:
@@ -30,3 +33,6 @@ jobs:
3033
- run: ninja -C builddir
3134
env:
3235
CC: clang
36+
- run: ninja test --verbose -C builddir
37+
env:
38+
CC: clang

ci/cirrus.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ set -x
1818

1919
meson build
2020
meson compile -C build
21-
# gmake test
21+
meson test --verbose -C build

meson.build

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ project('OpenRC', 'c',
66
'prefix=/usr',
77
'warning_level=3',
88
],
9-
meson_version : '>=0.53.0')
9+
meson_version : '>=0.53.2')
1010

1111
cc = meson.get_compiler('c')
1212
fs = import('fs')
@@ -205,6 +205,7 @@ subdir('sh')
205205
subdir('src')
206206
subdir('support')
207207
subdir('sysctl.d')
208+
subdir('test')
208209
subdir('zsh-completion')
209210

210211
meson.add_install_script('tools/meson_runlevels.sh',

test/check-obsolete-functions.sh

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/sh
2+
3+
top_srcdir=${SOURCE_ROOT:-..}
4+
. ${top_srcdir}/test/setup_env.sh
5+
6+
ebegin "Checking for obsolete functions"
7+
out=$(cd ${top_srcdir}; find src -name '*.[ch]' \
8+
! -name queue.h \
9+
-exec grep -n -E '\<(malloc|memory|sys/(errno|fcntl|signal|stropts|termios|unistd))\.h\>' {} +)
10+
[ -z "${out}" ]
11+
eend $? "Avoid these obsolete functions:"$'\n'"${out}"

test/check-spacing-style.sh

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/sh
2+
3+
top_srcdir=${SOURCE_ROOT:-..}
4+
. ${top_srcdir}/test/setup_env.sh
5+
6+
ebegin "Checking spacing style"
7+
out=$(cd ${top_srcdir}; find src -name '*.[ch]' \
8+
! -name queue.h \
9+
-exec grep -n -E \
10+
-e '\<(for|if|switch|while)\(' \
11+
-e '\<(for|if|switch|while) \( ' \
12+
-e ' ;' \
13+
-e '[[:space:]]$' \
14+
-e '\){' \
15+
-e '(^|[^:])//' \
16+
{} +)
17+
[ -z "${out}" ]
18+
eend $? "These lines violate style rules:"$'\n'"${out}"

test/check-trailing-newlines.sh

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/sh
2+
3+
top_srcdir=${SOURCE_ROOT:-..}
4+
. ${top_srcdir}/test/setup_env.sh
5+
6+
ebegin "Checking trailing newlines in code"
7+
out=$(cd ${top_srcdir};
8+
for f in $(find */ -name '*.[ch]') ; do
9+
while read -r line; do
10+
if [ -n "${line}" ]; then
11+
blankline=
12+
else
13+
blankline=1
14+
fi
15+
done < "${f}"
16+
[ -n "${blankline}" ] && printf "%s\n" "${f}"
17+
done)
18+
[ -z "${out}" ]
19+
eend $? "Trailing newlines need to be deleted:"$'\n'"${out}"

test/check-trailing-whitespace.sh

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/sh
2+
3+
top_srcdir=${SOURCE_ROOT:-..}
4+
. ${top_srcdir}/test/setup_env.sh
5+
6+
ebegin "Checking trailing whitespace in code"
7+
# XXX: Should we check man pages too ?
8+
out=$(cd ${top_srcdir}; find */ \
9+
'(' -name '*.[ch]' -o -name '*.in' -o -name '*.sh' ')' \
10+
-exec grep -n -E '[[:space:]]+$' {} +)
11+
[ -z "${out}" ]
12+
eend $? "Trailing whitespace needs to be deleted:"$'\n'"${out}"

test/check-xfunc-usage.sh

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/sh
2+
3+
top_srcdir=${SOURCE_ROOT:-..}
4+
. ${top_srcdir}/test/setup_env.sh
5+
6+
ebegin "Checking for x* func usage"
7+
out=$(cd ${top_srcdir}; find src -name '*.[ch]' \
8+
! -name queue.h \
9+
-exec grep -n -E '\<(malloc|strdup)[[:space:]]*\(' {} + \
10+
| grep -v \
11+
-e src/shared/helpers.h \
12+
-e src/libeinfo/libeinfo.c)
13+
14+
[ -z "${out}" ]
15+
eend $? "These need to be using the x* variant:"$'\n'"${out}"

test/meson.build

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
if meson.version().version_compare('>=0.56.0')
2+
build_root = meson.project_build_root()
3+
source_root = meson.project_source_root()
4+
else
5+
build_root = meson.build_root()
6+
source_root = meson.source_root()
7+
endif
8+
9+
test_env = [
10+
'BUILD_ROOT=' + build_root,
11+
'SOURCE_ROOT=' + source_root
12+
]
13+
14+
check_obsolete_functions = find_program('check-obsolete-functions.sh')
15+
check_spacing_style = find_program('check-spacing-style.sh')
16+
check_trailing_newlines = find_program('check-trailing-newlines.sh')
17+
check_trailing_whitespace = find_program('check-trailing-whitespace.sh')
18+
check_xfunc_usage = find_program('check-xfunc-usage.sh')
19+
20+
test('check for obsolete functions', check_obsolete_functions, env : test_env)
21+
test('check spacing style', check_spacing_style, env : test_env)
22+
test('check trailing newlines', check_trailing_newlines, env : test_env)
23+
test('check trailing whitespace', check_trailing_whitespace, env : test_env)
24+
test('check xfunc usage', check_xfunc_usage, env : test_env)
25+
26+
subdir('units')

test/runtests.sh

-92
This file was deleted.

test/setup_env.sh

+11-13
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,21 @@
11
#!/bin/sh
22

3-
if [ -z "${top_srcdir}" ] ; then
4-
echo "You must set top_srcdir before sourcing this file" 1>&2
3+
if [ -z "${BUILD_ROOT}" ] ; then
4+
printf "%s\n" "You must export BUILD_ROOT before sourcing this file" >&2
55
exit 1
66
fi
77

8-
srcdir=${srcdir:-.}
9-
top_builddir=${top_builddir:-${top_srcdir}}
10-
builddir=${builddir:-${srcdir}}
11-
12-
LD_LIBRARY_PATH=${top_builddir}/src/libeinfo:${top_builddir}/src/librc:${LD_LIBRARY_PATH}
13-
PATH=${top_builddir}/src/rc:${PATH}
14-
export LD_LIBRARY_PATH PATH
8+
if [ -z "${SOURCE_ROOT}" ] ; then
9+
printf "%s\n" "You must export SOURCE_ROOT before sourcing this file" >&2
10+
exit 1
11+
fi
1512

16-
if [ ! -f ${top_srcdir}/sh/functions.sh ] ; then
17-
echo "functions.sh not yet created !?" 1>&2
13+
if [ ! -f ${BUILD_ROOT}/sh/functions.sh ] ; then
14+
printf "%s\n" "functions.sh not yet created !?" >&2
1815
exit 1
19-
elif ! . ${top_srcdir}/sh/functions.sh; then
20-
echo "Sourcing functions.sh failed !?" 1>&2
16+
elif ! . ${BUILD_ROOT}/sh/functions.sh; then
17+
printf "%s\n" "Sourcing functions.sh failed !?" >&2
2118
exit 1
2219
fi
2320

21+
PATH="${BUILD_ROOT}"/src/einfo:${PATH}

test/units/is_older_than test/units/check-is-older-than.sh

+10-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,13 @@
22
# unit test for is_older_than code of baselayout (2008/06/19)
33
# Author: Matthias Schwarzott <zzam@gentoo.org>
44

5-
TMPDIR=tmp-"$(basename "$0")"
5+
if [ -z "${BUILD_ROOT}" ]; then
6+
printf "%s\n" "BUILD_ROOT must be defined" >&2
7+
exit 1
8+
fi
9+
PATH="${BUILD_ROOT}"/src/is_older_than:${PATH}
10+
11+
TMPDIR="${BUILD_ROOT}"/tmp-"$(basename "$0")"
612

713
# Please note that we added this unit test because the function
814
# should really be called is_newer_than as it's what it's really testing.
@@ -37,13 +43,14 @@ do_test()
3743
is_older_than "$@"
3844
r2=$?
3945

40-
[ -n "${VERBOSE}" ] && echo "reference = $r1 | OpenRC = $r2"
46+
[ -n "${VERBOSE}" ] &&
47+
printf "reference = %s | OpenRC = %s\n" "$r1" "$r2"
4148
[ $r1 = $r2 ]
4249
}
4350

4451
echo_cmd()
4552
{
46-
[ -n "${VERBOSE}" ] && echo "$@"
53+
[ -n "${VERBOSE}" ] && printf "%s\n" "$@"
4754
"$@"
4855
}
4956

test/units/sh_yesno test/units/check-sh-yesno.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
# This file may not be copied, modified, propagated, or distributed
1010
# except according to the terms contained in the LICENSE file.
1111

12-
: ${top_srcdir:=..}
12+
top_srcdir=${SOURCE_ROOT:-..}
1313
. $top_srcdir/test/setup_env.sh
1414

1515
ret=0

test/units/meson.build

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
is_older_than = find_program('check-is-older-than.sh')
2+
sh_yesno = find_program('check-sh-yesno.sh')
3+
4+
test('is_older_than', is_older_than, env : test_env)
5+
test('sh_yesno', sh_yesno, env : test_env)

0 commit comments

Comments
 (0)