aboutsummaryrefslogtreecommitdiff
path: root/tests.c
diff options
context:
space:
mode:
authorJoseph Hunkeler <jhunkeler@gmail.com>2023-07-05 10:42:17 -0400
committerJoseph Hunkeler <jhunkeler@gmail.com>2023-07-05 10:42:21 -0400
commit6b0ddba545ca578903fe856af6d820883121bb1e (patch)
tree7e8a485e89bc23075e084fe16c44e5e280c5855c /tests.c
parenta70733d9a64320eac8038d733df67467cd97976c (diff)
downloadversion_compare-master.tar.gz
Bug fix:HEADmaster
* Pad first element of a version to avoid small versions being detected as greater than larger versions * before: 1.0.3 > 2.0.0 == TRUE * after: 1.0.3 > 2.0.0 == FALSE
Diffstat (limited to 'tests.c')
-rw-r--r--tests.c45
1 files changed, 39 insertions, 6 deletions
diff --git a/tests.c b/tests.c
index 0eb56ef..f91f072 100644
--- a/tests.c
+++ b/tests.c
@@ -77,6 +77,13 @@ static struct TestCase_version_compare test_cases_version_compare[] = {
{"1.0a", ">=", "1.0.0", 1},
{"1.0a", "!=", "1.0.0", 1},
+ {"1.0.3", "=", "2.0.0", 0},
+ {"1.0.3", "<", "2.0.0", 1},
+ {"1.0.3", "<=", "2.0.0", 1},
+ {"1.0.3", ">", "2.0.0", 0},
+ {"1.0.3", ">=", "2.0.0", 0},
+ {"1.0.3", "!=", "2.0.0", 1},
+
{"2022.1", "=", "2022.4", 0},
{"2022.1", "<", "2022.4", 1},
{"2022.1", "<=", "2022.4", 1},
@@ -84,6 +91,34 @@ static struct TestCase_version_compare test_cases_version_compare[] = {
{"2022.1", ">=", "2022.4", 0},
{"2022.1", "!=", "2022.4", 1},
+ {"1:2022.1", "=", "2022.4", 0},
+ {"1:2022.1", "<", "2022.4", 1},
+ {"1:2022.1", "<=", "2022.4", 1},
+ {"1:2022.1", ">", "2022.4", 0},
+ {"1:2022.1", ">=", "2022.4", 0},
+ {"1:2022.1", "!=", "2022.4", 1},
+
+ {"1:2022.1", "=", "2:2022.4", 0},
+ {"1:2022.1", "<", "2:2022.4", 1},
+ {"1:2022.1", "<=", "2:2022.4", 1},
+ {"1:2022.1", ">", "2:2022.4", 0},
+ {"1:2022.1", ">=", "2:2022.4", 0},
+ {"1:2022.1", "!=", "2:2022.4", 1},
+
+ {"2:2022.4", "=", "1:2022.1", 0},
+ {"2:2022.4", "<", "1:2022.1", 0},
+ {"2:2022.4", "<=", "1:2022.1", 0},
+ {"2:2022.4", ">", "1:2022.1", 1},
+ {"2:2022.4", ">=", "1:2022.1", 1},
+ {"2:2022.4", "!=", "1:2022.1", 1},
+
+ {"2022.1", "=", "2:2022.1", 0},
+ {"2022.1", "<", "2:2022.1", 1},
+ {"2022.1", "<=", "2:2022.1", 1},
+ {"2022.1", ">", "2:2022.1", 0},
+ {"2022.1", ">=", "2:2022.1", 0},
+ {"2022.1", "!=", "2:2022.1", 1},
+
{"2022.4", "=", "2022.1", 0},
{"2022.4", "<", "2022.1", 0},
{"2022.4", "<=", "2022.1", 0},
@@ -109,7 +144,7 @@ static int run_cases_version_compare(struct TestCase_version_compare tests[], si
int op = version_parse_operator(test->op);
result = version_compare(op, test->a, test->b);
- printf("%s %s %s is %s", test->a, test->op, test->b, result ? "TRUE" : "FALSE" );
+ printf("%s %s %s is %s (%d)", test->a, test->op, test->b, result ? "TRUE" : "FALSE" , result);
if (test->result != result) {
printf(" [FAILED: got %d, expected %d]\n", result, test->result);
failed++;
@@ -132,7 +167,7 @@ static int run_cases_string(struct TestCase_strings tests[], size_t size, strfn
fn(&s);
result = strcmp(test->result, s);
- printf("'%s' is %s", s, !result ? "CORRECT" : "INCORRECT" );
+ printf("'%s' is %s (%d)", s, !result ? "CORRECT" : "INCORRECT", !result );
if (result) {
printf(" [FAILED: got '%s', expected '%s']\n", s, test->result);
failed++;
@@ -144,7 +179,6 @@ static int run_cases_string(struct TestCase_strings tests[], size_t size, strfn
return failed;
}
-
char **make_argv(int *argc, char *argv[]) {
char **args;
*argc = 0;
@@ -153,7 +187,6 @@ char **make_argv(int *argc, char *argv[]) {
*argc = *argc + 1;
}
- //char **args = calloc(*argc + 1, sizeof(*argv));
args = calloc(*argc + 1, sizeof(*argv));
if (!args) {
perror("unable to allocate args array");
@@ -279,7 +312,7 @@ static int run_cases_program_split(struct TestCase_version_compare tests[], size
struct TestCase_version_compare *test = &tests[i];
result = run_program((char *[]){test->a, test->op, test->b, NULL});
- printf("%s %s %s is %s", test->a, test->op, test->b, result ? "TRUE" : "FALSE" );
+ printf("%s %s %s is %s (%d)", test->a, test->op, test->b, result ? "TRUE" : "FALSE", result);
if (test->result != result) {
printf(" [FAILED: got %d, expected %d]\n", result, test->result);
failed++;
@@ -300,7 +333,7 @@ static int run_cases_program_standalone(struct TestCase_version_compare tests[],
snprintf(data, sizeof(data) - 1, "%s %s %s", test->a, test->op, test->b);
result = run_program((char *[]){data, NULL});
- printf("%s %s %s is %s", test->a, test->op, test->b, result ? "TRUE" : "FALSE" );
+ printf("%s %s %s is %s (%d)", test->a, test->op, test->b, result ? "TRUE" : "FALSE", result);
if (test->result != result) {
printf(" [FAILED: got %d, expected %d]\n", result, test->result);
failed++;