/[gentoo-x86]/eclass/versionator.eclass
Gentoo

Diff of /eclass/versionator.eclass

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.20 Revision 1.22
1# Copyright 1999-2008 Gentoo Foundation 1# Copyright 1999-2008 Gentoo Foundation
2# Distributed under the terms of the GNU General Public License v2 2# Distributed under the terms of the GNU General Public License v2
3# $Header: /var/cvsroot/gentoo-x86/eclass/versionator.eclass,v 1.20 2011/11/22 18:42:10 vapier Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/versionator.eclass,v 1.22 2011/12/15 05:10:25 vapier Exp $
4 4
5# @ECLASS: versionator.eclass 5# @ECLASS: versionator.eclass
6# @MAINTAINER: 6# @MAINTAINER:
7# Jonathan Callen <abcd@gentoo.org> 7# Jonathan Callen <abcd@gentoo.org>
8# base-system@gentoo.org 8# base-system@gentoo.org
23# selected. 23# selected.
24# 24#
25# There's also: 25# There's also:
26# version_is_at_least want have 26# version_is_at_least want have
27# which may be buggy, so use with caution. 27# which may be buggy, so use with caution.
28
29if [[ ${___ECLASS_ONCE_VERSIONATOR} != "recur -_+^+_- spank" ]] ; then
30___ECLASS_ONCE_VERSIONATOR="recur -_+^+_- spank"
28 31
29inherit eutils 32inherit eutils
30 33
31# @FUNCTION: get_all_version_components 34# @FUNCTION: get_all_version_components
32# @USAGE: [version] 35# @USAGE: [version]
502 shift 505 shift
503 set -- $(get_version_components "$@") 506 set -- $(get_version_components "$@")
504 eval echo "${fstr}" 507 eval echo "${fstr}"
505} 508}
506 509
507__versionator__test_version_compare() { 510fi
508 eshopts_push -s extglob
509 local lt=1 eq=2 gt=3 p q
510
511 __versionator__test_version_compare_t() {
512 version_compare "${1}" "${3}"
513 local r=$?
514 [[ ${r} -eq ${2} ]] || echo "FAIL: ${@} (got ${r} exp ${2})"
515 }
516
517 echo "
518 0 $lt 1
519 1 $lt 2
520 2 $gt 1
521 2 $eq 2
522 0 $eq 0
523 10 $lt 20
524 68 $eq 068
525 068 $gt 67
526 068 $lt 69
527
528 1.0 $lt 2.0
529 2.0 $eq 2.0
530 2.0 $gt 1.0
531
532 1.0 $gt 0.0
533 0.0 $eq 0.0
534 0.0 $lt 1.0
535
536 0.1 $lt 0.2
537 0.2 $eq 0.2
538 0.3 $gt 0.2
539
540 1.2 $lt 2.1
541 2.1 $gt 1.2
542
543 1.2.3 $lt 1.2.4
544 1.2.4 $gt 1.2.3
545
546 1.2.0 $gt 1.2
547 1.2.1 $gt 1.2
548 1.2 $lt 1.2.1
549
550 1.2b $eq 1.2b
551 1.2b $lt 1.2c
552 1.2b $gt 1.2a
553 1.2b $gt 1.2
554 1.2 $lt 1.2a
555
556 1.3 $gt 1.2a
557 1.3 $lt 1.3a
558
559 1.0_alpha7 $lt 1.0_beta7
560 1.0_beta $lt 1.0_pre
561 1.0_pre5 $lt 1.0_rc2
562 1.0_rc2 $lt 1.0
563
564 1.0_p1 $gt 1.0
565 1.0_p1-r1 $gt 1.0_p1
566
567 1.0_alpha6-r1 $gt 1.0_alpha6
568 1.0_beta6-r1 $gt 1.0_alpha6-r2
569
570 1.0_pre1 $lt 1.0_p1
571
572 1.0p $gt 1.0_p1
573 1.0r $gt 1.0-r1
574 1.6.15 $gt 1.6.10-r2
575 1.6.10-r2 $lt 1.6.15
576
577 " | while read a b c ; do
578 [[ -z "${a}${b}${c}" ]] && continue;
579 __versionator__test_version_compare_t "${a}" "${b}" "${c}"
580 done
581
582
583 for q in "alpha beta pre rc=${lt};${gt}" "p=${gt};${lt}" ; do
584 for p in ${q%%=*} ; do
585 local c=${q##*=}
586 local alt=${c%%;*} agt=${c##*;}
587 __versionator__test_version_compare_t "1.0" $agt "1.0_${p}"
588 __versionator__test_version_compare_t "1.0" $agt "1.0_${p}1"
589 __versionator__test_version_compare_t "1.0" $agt "1.0_${p}068"
590
591 __versionator__test_version_compare_t "2.0_${p}" $alt "2.0"
592 __versionator__test_version_compare_t "2.0_${p}1" $alt "2.0"
593 __versionator__test_version_compare_t "2.0_${p}068" $alt "2.0"
594
595 __versionator__test_version_compare_t "1.0_${p}" $eq "1.0_${p}"
596 __versionator__test_version_compare_t "0.0_${p}" $lt "0.0_${p}1"
597 __versionator__test_version_compare_t "666_${p}3" $gt "666_${p}"
598
599 __versionator__test_version_compare_t "1_${p}7" $lt "1_${p}8"
600 __versionator__test_version_compare_t "1_${p}7" $eq "1_${p}7"
601 __versionator__test_version_compare_t "1_${p}7" $gt "1_${p}6"
602 __versionator__test_version_compare_t "1_${p}09" $eq "1_${p}9"
603
604 __versionator__test_version_compare_t "1_${p}7-r0" $eq "1_${p}7"
605 __versionator__test_version_compare_t "1_${p}7-r0" $lt "1_${p}7-r1"
606 __versionator__test_version_compare_t "1_${p}7-r0" $lt "1_${p}7-r01"
607 __versionator__test_version_compare_t "1_${p}7-r01" $eq "1_${p}7-r1"
608 __versionator__test_version_compare_t "1_${p}8-r1" $gt "1_${p}7-r100"
609
610 __versionator__test_version_compare_t "1_${p}_alpha" $lt "1_${p}_beta"
611 done
612 done
613
614 for p in "-r" "_p" ; do
615 __versionator__test_version_compare_t "7.2${p}1" $lt "7.2${p}2"
616 __versionator__test_version_compare_t "7.2${p}2" $gt "7.2${p}1"
617 __versionator__test_version_compare_t "7.2${p}3" $gt "7.2${p}2"
618 __versionator__test_version_compare_t "7.2${p}2" $lt "7.2${p}3"
619 done
620
621 # The following tests all come from portage's test cases:
622 __versionator__test_version_compare_t "6.0" $gt "5.0"
623 __versionator__test_version_compare_t "5.0" $gt "5"
624 __versionator__test_version_compare_t "1.0-r1" $gt "1.0-r0"
625 __versionator__test_version_compare_t "1.0-r1" $gt "1.0"
626 __versionator__test_version_compare_t "999999999999999999999999999999" $gt "999999999999999999999999999998"
627 __versionator__test_version_compare_t "1.0.0" $gt "1.0"
628 __versionator__test_version_compare_t "1.0.0" $gt "1.0b"
629 __versionator__test_version_compare_t "1b" $gt "1"
630 __versionator__test_version_compare_t "1b_p1" $gt "1_p1"
631 __versionator__test_version_compare_t "1.1b" $gt "1.1"
632 __versionator__test_version_compare_t "12.2.5" $gt "12.2b"
633
634 __versionator__test_version_compare_t "4.0" $lt "5.0"
635 __versionator__test_version_compare_t "5" $lt "5.0"
636 __versionator__test_version_compare_t "1.0_pre2" $lt "1.0_p2"
637 __versionator__test_version_compare_t "1.0_alpha2" $lt "1.0_p2"
638 __versionator__test_version_compare_t "1.0_alpha1" $lt "1.0_beta1"
639 __versionator__test_version_compare_t "1.0_beta3" $lt "1.0_rc3"
640 __versionator__test_version_compare_t "1.001000000000000000001" $lt "1.001000000000000000002"
641 __versionator__test_version_compare_t "1.00100000000" $lt "1.0010000000000000001"
642 __versionator__test_version_compare_t "999999999999999999999999999998" $lt "999999999999999999999999999999"
643 __versionator__test_version_compare_t "1.01" $lt "1.1"
644 __versionator__test_version_compare_t "1.0-r0" $lt "1.0-r1"
645 __versionator__test_version_compare_t "1.0" $lt "1.0-r1"
646 __versionator__test_version_compare_t "1.0" $lt "1.0.0"
647 __versionator__test_version_compare_t "1.0b" $lt "1.0.0"
648 __versionator__test_version_compare_t "1_p1" $lt "1b_p1"
649 __versionator__test_version_compare_t "1" $lt "1b"
650 __versionator__test_version_compare_t "1.1" $lt "1.1b"
651 __versionator__test_version_compare_t "12.2b" $lt "12.2.5"
652
653 __versionator__test_version_compare_t "4.0" $eq "4.0"
654 __versionator__test_version_compare_t "1.0" $eq "1.0"
655 __versionator__test_version_compare_t "1.0-r0" $eq "1.0"
656 __versionator__test_version_compare_t "1.0" $eq "1.0-r0"
657 __versionator__test_version_compare_t "1.0-r0" $eq "1.0-r0"
658 __versionator__test_version_compare_t "1.0-r1" $eq "1.0-r1"
659
660 # The following were just tests for != in portage, we need something a bit
661 # more precise
662 __versionator__test_version_compare_t "1" $lt "2"
663 __versionator__test_version_compare_t "1.0_alpha" $lt "1.0_pre"
664 __versionator__test_version_compare_t "1.0_beta" $gt "1.0_alpha"
665 __versionator__test_version_compare_t "0" $lt "0.0"
666 __versionator__test_version_compare_t "1.0-r0" $lt "1.0-r1"
667 __versionator__test_version_compare_t "1.0-r1" $gt "1.0-r0"
668 __versionator__test_version_compare_t "1.0" $lt "1.0-r1"
669 __versionator__test_version_compare_t "1.0-r1" $gt "1.0"
670 __versionator__test_version_compare_t "1_p1" $lt "1b_p1"
671 __versionator__test_version_compare_t "1b" $gt "1"
672 __versionator__test_version_compare_t "1.1b" $gt "1.1"
673 __versionator__test_version_compare_t "12.2b" $gt "12.2"
674
675 # The following tests all come from paludis's test cases:
676 __versionator__test_version_compare_t "1.0" $gt "1"
677 __versionator__test_version_compare_t "1" $lt "1.0"
678 __versionator__test_version_compare_t "1.0_alpha" $gt "1_alpha"
679 __versionator__test_version_compare_t "1.0_alpha" $gt "1"
680 __versionator__test_version_compare_t "1.0_alpha" $lt "1.0"
681 __versionator__test_version_compare_t "1.2.0.0_alpha7-r4" $gt "1.2_alpha7-r4"
682
683 __versionator__test_version_compare_t "0001" $eq "1"
684 __versionator__test_version_compare_t "01" $eq "001"
685 __versionator__test_version_compare_t "0001.1" $eq "1.1"
686 __versionator__test_version_compare_t "01.01" $eq "1.01"
687 __versionator__test_version_compare_t "1.010" $eq "1.01"
688 __versionator__test_version_compare_t "1.00" $eq "1.0"
689 __versionator__test_version_compare_t "1.0100" $eq "1.010"
690 __versionator__test_version_compare_t "1" $eq "1-r0"
691 __versionator__test_version_compare_t "1-r00" $eq "1-r0"
692
693 eshopts_pop
694}

Legend:
Removed from v.1.20  
changed lines
  Added in v.1.22

  ViewVC Help
Powered by ViewVC 1.1.20