test-compare-versions: basic test for systemd-analyze compare-versions

This commit is contained in:
Zbigniew Jędrzejewski-Szmek 2022-05-18 10:40:54 +02:00
parent bc012a3e91
commit 4e8295f42d
3 changed files with 50 additions and 1 deletions

View File

@ -2162,7 +2162,7 @@ meson.add_install_script(meson_make_symlink,
rootlibexecdir / 'systemd',
rootsbindir / 'init')
public_programs += executable(
exe = executable(
'systemd-analyze',
systemd_analyze_sources,
include_directories : core_includes,
@ -2172,6 +2172,13 @@ public_programs += executable(
libseccomp],
install_rpath : rootlibexecdir,
install : conf.get('ENABLE_ANALYZE'))
public_programs += exe
if want_tests != 'false'
test('test-compare-versions',
test_compare_versions_sh,
args : exe.full_path())
endif
executable(
'systemd-journald',

View File

@ -108,6 +108,14 @@ endif
############################################################
test_compare_versions_sh = files('test-compare-versions.sh')
if install_tests
install_data(test_compare_versions_sh,
install_dir : testsdir)
endif
############################################################
rule_syntax_check_py = find_program('rule-syntax-check.py')
if want_tests != 'false'
test('rule-syntax-check',

34
test/test-compare-versions.sh Executable file
View File

@ -0,0 +1,34 @@
#!/usr/bin/env bash
# SPDX-License-Identifier: LGPL-2.1-or-later
set -e
ANALYZE="${1:-systemd-analyze}"
$ANALYZE compare-versions 1 lt 2
$ANALYZE compare-versions 1 '<' 2
$ANALYZE compare-versions 1 le 2
$ANALYZE compare-versions 1 '<=' 2
$ANALYZE compare-versions 1 ne 2
$ANALYZE compare-versions 1 '!=' 2
( ! $ANALYZE compare-versions 1 ge 2 )
( ! $ANALYZE compare-versions 1 '>=' 2 )
( ! $ANALYZE compare-versions 1 eq 2 )
( ! $ANALYZE compare-versions 1 '==' 2 )
( ! $ANALYZE compare-versions 1 gt 2 )
( ! $ANALYZE compare-versions 1 '>' 2 )
$ANALYZE compare-versions 1 2 | grep ' < '
$ANALYZE compare-versions 2 2 | grep ' == '
$ANALYZE compare-versions 2 1 | grep ' > '
set +e
$ANALYZE compare-versions 1 2; ret1=$?
$ANALYZE compare-versions 2 2; ret2=$?
$ANALYZE compare-versions 2 1; ret3=$?
set -e
test $ret1 == 12
test $ret2 == 0
test $ret3 == 11