Skip to content

Commit e0777e1

Browse files
committed
tests/nut-driver-enumerator-test.sh: add testcase_semver_compare() [networkupstools#3055]
Signed-off-by: Jim Klimov <jimklimov+nut@gmail.com>
1 parent bc305d6 commit e0777e1

File tree

1 file changed

+128
-0
lines changed

1 file changed

+128
-0
lines changed

tests/nut-driver-enumerator-test.sh

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,12 @@ callG2V() (
108108
$USE_SHELL "${SRCDIR}/../tools/gitlog2version.sh" 2>&1
109109
)
110110

111+
callSEMVERCMP() {
112+
# All options to that helper can be passed via command line
113+
# so no hassle with exports
114+
callSHELL "${SRCDIR}/../tools/semver-compare.sh" "$@"
115+
}
116+
111117
run_testcase_generic() {
112118
# First 4 args are required as defined below; the rest are
113119
# CLI arg(s) to nut-driver-enumerator.sh
@@ -510,6 +516,127 @@ testcase_gitlog2version() {
510516
000003.000014.000159.002653.000005-002658+gdeadbeef+v04.005.0006+rc001"
511517
}
512518

519+
testcase_semver_compare() {
520+
# Note: first 4 args of run_testcase_generic are fixed, the rest are passed into called command
521+
run_testcase_generic callSEMVERCMP \
522+
"SEMVER comparison helper: expand triplet into pentuplet (by default)" 0 \
523+
"000001.000003.000002.000000.000000" \
524+
--expand 1.3.2
525+
526+
run_testcase_generic callSEMVERCMP \
527+
"SEMVER comparison helper: expand triplet into quadruplet with specified width and component count" 0 \
528+
"00000001.00000003.00000002.00000000" \
529+
--width 8 --min-components 4 --expand 1.3.2
530+
531+
# Note: forced min width is 6, smaller args ignored:
532+
run_testcase_generic callSEMVERCMP \
533+
"SEMVER comparison helper: expand triplet without adding component count" 0 \
534+
"000001.000003.000002" \
535+
--width 3 --min-components 0 --expand 1.3.2
536+
537+
run_testcase_generic callSEMVERCMP \
538+
"SEMVER comparison helper: sorting (results are printed in original form, even if with leading zeroes)" 0 \
539+
"001.1.038
540+
01.02.03
541+
1.002.0003
542+
1.002.0006
543+
1.002.00030
544+
4.5.6" \
545+
sort 01.02.03 1.002.00030 1.002.0003 4.5.6 1.002.0006 001.1.038
546+
547+
run_testcase_generic callSEMVERCMP \
548+
"SEMVER comparison helper: sorting of realistic iteration IDs" 0 \
549+
"2.8.4.326.80-406+g285c532d9
550+
2.8.4.753-753+gc1c3d7f4d
551+
2.8.4.754
552+
2.8.4.903.3-906+g62b0e39b2
553+
2.8.4.3829
554+
2.8.4.3829.0
555+
2.8.4.3829.9
556+
2.8.4.3829.10
557+
2.8.4.3829.22" \
558+
sort 2.8.4.754 2.8.4.3829 2.8.4.903.3-906+g62b0e39b2 2.8.4.326.80-406+g285c532d9 2.8.4.753-753+gc1c3d7f4d 2.8.4.3829.0 2.8.4.3829.22 2.8.4.3829.10 2.8.4.3829.9
559+
560+
run_testcase_generic callSEMVERCMP \
561+
"SEMVER comparison helper: reverse sorting of realistic iteration IDs" 0 \
562+
"2.8.4.3829.22
563+
2.8.4.3829.10
564+
2.8.4.3829.9
565+
2.8.4.3829.0
566+
2.8.4.3829
567+
2.8.4.903.3-906+g62b0e39b2
568+
2.8.4.754
569+
2.8.4.753-753+gc1c3d7f4d
570+
2.8.4.326.80-406+g285c532d9" \
571+
sort -r 2.8.4.754 2.8.4.3829 2.8.4.903.3-906+g62b0e39b2 2.8.4.326.80-406+g285c532d9 2.8.4.753-753+gc1c3d7f4d 2.8.4.3829.0 2.8.4.3829.22 2.8.4.3829.10 2.8.4.3829.9
572+
573+
run_testcase_generic callSEMVERCMP \
574+
"SEMVER comparison helper: shell-style maths: -gt" 1 "" \
575+
test 01.02.03 -gt 4.5.6
576+
577+
run_testcase_generic callSEMVERCMP \
578+
"SEMVER comparison helper: shell-style maths: >" 1 "" \
579+
[ 01.02.03 '>' 4.5.6 ]
580+
581+
# Note: here a trailing ] is not required for [ test alias
582+
run_testcase_generic callSEMVERCMP \
583+
"SEMVER comparison helper: shell-style maths: >=" 1 "" \
584+
[ 01.02.03 '>=' 4.5.6
585+
586+
# Note: here a trailing ]] is not required for [[ test alias
587+
run_testcase_generic callSEMVERCMP \
588+
"SEMVER comparison helper: shell-style maths: -ge" 1 "" \
589+
[[ 01.02.03 -ge 4.5.6
590+
591+
run_testcase_generic callSEMVERCMP \
592+
"SEMVER comparison helper: shell-style maths: -eq" 1 "" \
593+
test 01.02.03 -eq 4.5.6
594+
595+
run_testcase_generic callSEMVERCMP \
596+
"SEMVER comparison helper: shell-style maths: -lt" 0 "" \
597+
test 01.02.03 -lt 4.5.6
598+
599+
run_testcase_generic callSEMVERCMP \
600+
"SEMVER comparison helper: shell-style maths: <" 0 "" \
601+
[[ 01.02.03 '<' 4.5.6
602+
603+
run_testcase_generic callSEMVERCMP \
604+
"SEMVER comparison helper: shell-style maths: <=" 0 "" \
605+
test 01.02.03.0 '<=' 4.5.6
606+
607+
run_testcase_generic callSEMVERCMP \
608+
"SEMVER comparison helper: shell-style maths: -le" 0 "" \
609+
test 01.02.03 -le 4.5.6.0.0
610+
611+
run_testcase_generic callSEMVERCMP \
612+
"SEMVER comparison helper: shell-style maths: equality with added trailing zeroed components (and different leading zero pads)" 0 "" \
613+
test 01.02.03 = 1.002.0003.0
614+
615+
run_testcase_generic callSEMVERCMP \
616+
"SEMVER comparison helper: shell-style maths: (non-)equality with added trailing zero value e.g. 3 vs 30" 1 "" \
617+
test 01.02.03 == 1.002.00030
618+
619+
run_testcase_generic callSEMVERCMP \
620+
"SEMVER comparison helper: shell-style maths: non-equality with added trailing zeroed components (and different leading zero pads)" 1 "" \
621+
test 01.02.03 != 1.002.0003.0
622+
623+
run_testcase_generic callSEMVERCMP \
624+
"SEMVER comparison helper: shell-style maths: non-equality with added trailing zero value e.g. 3 vs 30" 0 "" \
625+
test 01.02.03 -ne 1.002.00030
626+
627+
run_testcase_generic callSEMVERCMP \
628+
"SEMVER comparison helper: shell-style maths: unknown operation" 2 "" \
629+
test 01.02.03 foo 1.002.00030
630+
631+
run_testcase_generic callSEMVERCMP \
632+
"SEMVER comparison helper: unknown action" 2 "" \
633+
bogustest 01.02.03 foo 1.002.00030
634+
635+
run_testcase_generic callSEMVERCMP \
636+
"SEMVER comparison helper: unknown option" 2 "" \
637+
--with-foo bar --expand 01.02.03
638+
}
639+
513640
# Combine the cases above into a stack
514641
testsuite() {
515642
testcase_bogus_args
@@ -522,6 +649,7 @@ testsuite() {
522649
# Something very different
523650
testcase_backticks
524651
testcase_gitlog2version
652+
testcase_semver_compare
525653
}
526654

527655
# If no args...

0 commit comments

Comments
 (0)