Commit 010497cb authored by Timo Teräs's avatar Timo Teräs

add separate vertest applet for version string testing

start adding meson based tests
parent 6d71f49c
......@@ -3,7 +3,7 @@ project(
['c'],
default_options : ['c_std=gnu99', 'optimization=2'],
version: '3.0.0_pre0',
meson_version: '>=0.51'
meson_version: '>=0.52'
)
pkgc = import('pkgconfig')
......@@ -32,3 +32,4 @@ subproject = meson.is_subproject()
subdir('doc')
subdir('libfetch')
subdir('src')
subdir('tests')
......@@ -23,7 +23,8 @@
#define APK_DEPMASK_CHECKSUM (APK_VERSION_LESS|APK_VERSION_GREATER)
const char *apk_version_op_string(int result_mask);
int apk_version_result_mask(const char *str);
int apk_version_result_mask(const char *op);
int apk_version_result_mask_blob(apk_blob_t op);
int apk_version_validate(apk_blob_t ver);
int apk_version_compare_blob_fuzzy(apk_blob_t a, apk_blob_t b, int fuzzy);
int apk_version_compare_blob(apk_blob_t a, apk_blob_t b);
......
/* app_vertest.c - Alpine Package Keeper (APK)
*
* Copyright (C) 2005-2008 Natanael Copa <n@tanael.org>
* Copyright (C) 2008-2011 Timo Teräs <timo.teras@iki.fi>
* All rights reserved.
*
* SPDX-License-Identifier: GPL-2.0-only
*/
#include <stdio.h>
#include "apk_defines.h"
#include "apk_applet.h"
#include "apk_database.h"
#include "apk_version.h"
#include "apk_print.h"
static int vertest_main(void *pctx, struct apk_database *db, struct apk_string_array *args)
{
apk_blob_t arg, ver, op, space = APK_BLOB_STRLIT(" ");
char **parg;
int errors = 0;
foreach_array_item(parg, args) {
int ok = 0;
// arguments are either:
// "version" -> check validty
// "ver1 op ver2" -> check if that the comparison is true
arg = APK_BLOB_STR(*parg);
if (apk_blob_split(arg, space, &ver, &arg) &&
apk_blob_split(arg, space, &op, &arg)) {
if (apk_version_compare_blob(ver, arg) & apk_version_result_mask_blob(op))
ok = 1;
} else {
ok = apk_version_validate(arg);
}
if (!ok) {
if (apk_verbosity > 0)
printf("%s\n", *parg);
errors++;
}
}
return errors ? 1 : 0;
}
static struct apk_applet apk_vertest = {
.open_flags = APK_OPENF_READ | APK_OPENF_NO_STATE | APK_OPENF_NO_REPOS,
.name = "vertest",
.main = vertest_main,
};
APK_DEFINE_APPLET(apk_vertest);
......@@ -62,6 +62,7 @@ apk_src = [
'app_stats.c',
'app_verify.c',
'app_version.c',
'app_vertest.c',
'help.c',
]
......
......@@ -161,24 +161,32 @@ const char *apk_version_op_string(int mask)
}
}
int apk_version_result_mask(const char *str)
int apk_version_result_mask_blob(apk_blob_t op)
{
int r = 0;
switch (*str) {
case '<':
r = APK_VERSION_LESS;
str++;
break;
case '>':
r = APK_VERSION_GREATER;
str++;
break;
int i, r = 0;
for (i = 0; i < op.len; i++) {
switch (op.ptr[i]) {
case '<':
r |= APK_VERSION_LESS;
break;
case '>':
r |= APK_VERSION_GREATER;
break;
case '=':
r |= APK_VERSION_EQUAL;
break;
default:
return 0;
}
}
if (*str == '=')
r |= APK_VERSION_EQUAL;
return r;
}
int apk_version_result_mask(const char *op)
{
return apk_version_result_mask_blob(APK_BLOB_STR(op));
}
int apk_version_validate(apk_blob_t ver)
{
int t = TOKEN_DIGIT;
......
env = environment()
env.set('APK', apk_exe.full_path())
env.set('SRC', meson.current_source_dir())
test_program = find_program('test-basic.sh')
test_list = run_command(test_program, '--list').stdout().split('\n')
foreach test : test_list
test = test.strip()
if test != ''
test(test, test_program, args: ['--test', test], env: env)
endif
endforeach
#!/bin/sh
source ${SRC:-.}/test-lib.sh
t_case "help" && {
help_normal=$($APK version --help 2>/dev/null) || true
[ "${#help_normal}" -gt 2000 ]
help_invalid=$($APK version --invalid-option 2>/dev/null) || true
[ "$help_normal" = "$help_invalid" ]
}
t_case "version" && {
sed 's/[[:blank:]]*#.*//g' < $SRC/version.data | tr '\n' '\0' | xargs -0 $APK vertest
}
t_end
#!/bin/sh
: ${APK=apk} ${SRC=.}
T_MODE="$1"
shift 1
case "$T_MODE" in
--all)
t_case() { true; }
t_end() { exit 0; }
set -e -o pipefail
;;
--list)
t_case() { echo "$@"; false; }
t_end() { exit 0; }
;;
--test)
T_WANTED_CASE="$1"
shift
t_case() { [ "$@" = "$T_WANTED_CASE" ]; }
t_end() { exit 0; }
set -e -o pipefail
;;
*)
echo "invalid mode"
exit 1
;;
esac
2.34 > 0.1.0_alpha
23_foo > 4_beta
1.0 < 1.0bc # invalid. do string sort
0.1.0_alpha = 0.1.0_alpha
0.1.0_alpha < 0.1.3_alpha
0.1.3_alpha > 0.1.0_alpha
0.1.0_alpha2 > 0.1.0_alpha
0.1.0_alpha < 2.2.39-r1
2.2.39-r1 > 1.0.4-r3
1.0.4-r3 < 1.0.4-r4
1.0.4-r4 < 1.6
1.6 > 1.0.2
1.0.2 > 0.7-r1
0.7-r1 < 1.0.0
1.0.0 < 1.0.1
1.0.1 < 1.1
1.1 > 1.1_alpha1
1.1_alpha1 < 1.2.1
1.2.1 > 1.2
1.2 < 1.3_alpha
1.3_alpha < 1.3_alpha2
1.3_alpha2 < 1.3_alpha3
1.3_alpha8 > 0.6.0
0.6.0 < 0.6.1
0.6.1 < 0.7.0
0.7.0 < 0.8_beta1
0.8_beta1 < 0.8_beta2
0.8_beta4 < 4.8-r1
4.8-r1 > 3.10.18-r1
3.10.18-r1 > 2.3.0b-r1
2.3.0b-r1 < 2.3.0b-r2
2.3.0b-r2 < 2.3.0b-r3
2.3.0b-r3 < 2.3.0b-r4
2.3.0b-r4 > 0.12.1
0.12.1 < 0.12.2
0.12.2 < 0.12.3
0.12.3 > 0.12
0.12 < 0.13_beta1
0.13_beta1 < 0.13_beta2
0.13_beta2 < 0.13_beta3
0.13_beta3 < 0.13_beta4
0.13_beta4 < 0.13_beta5
0.13_beta5 > 0.9.12
0.9.12 < 0.9.13
0.9.13 > 0.9.12
0.9.12 < 0.9.13
0.9.13 > 0.0.16
0.0.16 < 0.6
0.6 < 2.1.13-r3
2.1.13-r3 < 2.1.15-r2
2.1.15-r2 < 2.1.15-r3
2.1.15-r3 > 1.2.11
1.2.11 < 1.2.12.1
1.2.12.1 < 1.2.13
1.2.13 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3.2-r1
2.3.2-r1 < 2.4.2
2.4.2 < 20060720
20060720 > 3.0.20060720
3.0.20060720 < 20060720
20060720 > 1.1
1.1 = 1.1
1.1 < 1.1.1-r1
1.1.1-r1 < 1.1.3-r1
1.1.3-r1 < 1.1.3-r2
1.1.3-r2 < 2.1.10-r2
2.1.10-r2 > 0.7.18-r2
0.7.18-r2 < 0.17-r6
0.17-r6 < 2.6.1
2.6.1 < 2.6.3
2.6.3 < 3.1.5-r2
3.1.5-r2 < 3.4.6-r1
3.4.6-r1 < 3.4.6-r2
3.4.6-r2 = 3.4.6-r2
3.4.6-r2 > 2.0.33
2.0.33 < 2.0.34
2.0.34 > 1.8.3-r2
1.8.3-r2 < 1.8.3-r3
1.8.3-r3 < 4.1
4.1 < 8.54
8.54 > 4.1.4
4.1.4 > 1.2.10-r5
1.2.10-r5 < 4.1.4-r3
4.1.4-r3 = 4.1.4-r3
4.1.4-r3 < 4.2.1
4.2.1 > 4.1.0
4.1.0 < 8.11
8.11 > 1.4.4-r1
1.4.4-r1 < 2.1.9.200602141850
2.1.9.200602141850 > 1.6
1.6 < 2.5.1-r8
2.5.1-r8 < 2.5.1a-r1
2.5.1a-r1 > 1.19.2-r1
1.19.2-r1 > 0.97-r2
0.97-r2 < 0.97-r3
0.97-r3 < 1.3.5-r10
1.3.5-r10 > 1.3.5-r8
1.3.5-r8 < 1.3.5-r9
1.3.5-r9 > 1.0
1.0 < 1.1
1.1 > 0.9.11
0.9.11 < 0.9.12
0.9.12 < 0.9.13
0.9.13 < 0.9.14
0.9.14 < 0.9.15
0.9.15 < 0.9.16
0.9.16 > 0.3-r2
0.3-r2 < 6.3
6.3 < 6.6
6.6 < 6.9
6.9 > 0.7.2-r3
0.7.2-r3 < 1.2.10
1.2.10 < 20040923-r2
20040923-r2 > 20040401
20040401 > 2.0.0_rc3-r1
2.0.0_rc3-r1 > 1.5
1.5 < 4.4
4.4 > 1.0.1
1.0.1 < 2.2.0
2.2.0 > 1.1.0-r2
1.1.0-r2 > 0.3
0.3 < 20020207-r2
20020207-r2 > 1.31-r2
1.31-r2 < 3.7
3.7 > 2.0.1
2.0.1 < 2.0.2
2.0.2 > 0.99.163
0.99.163 < 2.6.15.20060110
2.6.15.20060110 < 2.6.16.20060323
2.6.16.20060323 < 2.6.19.20061214
2.6.19.20061214 > 0.6.2-r1
0.6.2-r1 < 0.6.3
0.6.3 < 0.6.5
0.6.5 < 1.3.5-r1
1.3.5-r1 < 1.3.5-r4
1.3.5-r4 < 3.0.0-r2
3.0.0-r2 < 021109-r3
021109-r3 < 20060512
20060512 > 1.24
1.24 > 0.9.16-r1
0.9.16-r1 < 3.9_pre20060124
3.9_pre20060124 > 0.01
0.01 < 0.06
0.06 < 1.1.7
1.1.7 < 6b-r7
6b-r7 > 1.12-r7
1.12-r7 < 1.12-r8
1.12-r8 > 1.1.12
1.1.12 < 1.1.13
1.1.13 > 0.3
0.3 < 0.5
0.5 < 3.96.1
3.96.1 < 3.97
3.97 > 0.10.0-r1
0.10.0-r1 > 0.10.0
0.10.0 < 0.10.1_rc1
0.10.1_rc1 > 0.9.11
0.9.11 < 394
394 > 2.31
2.31 > 1.0.1
1.0.1 = 1.0.1
1.0.1 < 1.0.3
1.0.3 > 1.0.2
1.0.2 = 1.0.2
1.0.2 > 1.0.1
1.0.1 = 1.0.1
1.0.1 < 1.2.2
1.2.2 < 2.1.10
2.1.10 > 1.0.1
1.0.1 < 1.0.2
1.0.2 < 3.5.5
3.5.5 > 1.1.1
1.1.1 > 0.9.1
0.9.1 < 1.0.2
1.0.2 > 1.0.1
1.0.1 < 1.0.2
1.0.2 > 1.0.1
1.0.1 = 1.0.1
1.0.1 < 1.0.5
1.0.5 > 0.8.5
0.8.5 < 0.8.6-r3
0.8.6-r3 < 2.3.17
2.3.17 > 1.10-r5
1.10-r5 < 1.10-r9
1.10-r9 < 2.0.2
2.0.2 > 1.1a
1.1a < 1.3a
1.3a > 1.0.2
1.0.2 < 1.2.2-r1
1.2.2-r1 > 1.0-r1
1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1
1.5.0-r1 > 1.5.0
1.5.0 > 0.9.2
0.9.2 < 8.1.2.20040524-r1
8.1.2.20040524-r1 < 8.1.2.20050715-r1
8.1.2.20050715-r1 < 20030215
20030215 > 3.80-r4
3.80-r4 < 3.81
3.81 > 1.6d
1.6d > 1.2.07.8
1.2.07.8 < 1.2.12.04
1.2.12.04 < 1.2.12.05
1.2.12.05 < 1.3.3
1.3.3 < 2.6.4
2.6.4 > 2.5.2
2.5.2 < 2.6.1
2.6.1 > 2.6
2.6 < 6.5.1-r1
6.5.1-r1 > 1.1.35-r1
1.1.35-r1 < 1.1.35-r2
1.1.35-r2 > 0.9.2
0.9.2 < 1.07-r1
1.07-r1 < 1.07.5
1.07.5 > 1.07
1.07 < 1.19
1.19 < 2.1-r2
2.1-r2 < 2.2
2.2 > 1.0.4
1.0.4 < 20060811
20060811 < 20061003
20061003 > 0.1_pre20060810
0.1_pre20060810 < 0.1_pre20060817
0.1_pre20060817 < 1.0.3
1.0.3 > 1.0.2
1.0.2 > 1.0.1
1.0.1 < 3.2.2-r1
3.2.2-r1 < 3.2.2-r2
3.2.2-r2 < 3.3.17
3.3.17 > 0.59s-r11
0.59s-r11 < 0.65
0.65 > 0.2.10-r2
0.2.10-r2 < 2.01
2.01 < 3.9.10
3.9.10 > 1.2.18
1.2.18 < 1.5.11-r2
1.5.11-r2 < 1.5.13-r1
1.5.13-r1 > 1.3.12-r1
1.3.12-r1 < 2.0.1
2.0.1 < 2.0.2
2.0.2 < 2.0.3
2.0.3 > 0.2.0
0.2.0 < 5.5-r2
5.5-r2 < 5.5-r3
5.5-r3 > 0.25.3
0.25.3 < 0.26.1-r1
0.26.1-r1 < 5.2.1.2-r1
5.2.1.2-r1 < 5.4
5.4 > 1.60-r11
1.60-r11 < 1.60-r12
1.60-r12 < 110-r8
110-r8 > 0.17-r2
0.17-r2 < 1.05-r4
1.05-r4 < 5.28.0
5.28.0 > 0.51.6-r1
0.51.6-r1 < 1.0.6-r6
1.0.6-r6 > 0.8.3
0.8.3 < 1.42
1.42 < 20030719
20030719 > 4.01
4.01 < 4.20
4.20 > 0.20070118