Skip to content

Commit

Permalink
Merge pull request #27 from pine613/fix/semver
Browse files Browse the repository at this point in the history
Fix not install bugs
  • Loading branch information
pine committed Oct 19, 2015
2 parents ee9196b + fce2e5e commit 6aec576
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 364 deletions.
10 changes: 0 additions & 10 deletions LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,6 @@ under the same terms as Perl itself.

-----------------------------------------------------------

| SemVer
| http://search.cpan.org/~dwheeler/SemVer-v0.6.0/lib/SemVer.pm

Copyright (c) 2010-2015 David E. Wheeler. Some Rights Reserved.

This module is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.

-----------------------------------------------------------

| crystal-build

(The MIT license)
Expand Down
8 changes: 2 additions & 6 deletions lib/Crenv.pm
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@ use strict;
use warnings;
use utf8;
use feature qw/say/;
our $VERSION = '1.10';
our $VERSION = '1.1.1';

use File::Path qw/rmtree mkpath/;
use JSON::PP;
use SemVer;

use Crenv::Utils;
use Crenv::GitHub;
Expand Down Expand Up @@ -50,10 +49,7 @@ sub install {
rename $target_dir, $self->get_install_dir or die "Error: $!";

# shards
my $sember = SemVer->declare($version);
my $v077 = SemVer->new('0.7.7');

if ($v077 <= $sember) {
if (Crenv::Utils::cmp_version($version, '0.7.7') >= 0) { # >= v0.7.7
$self->install_shards($version);
}

Expand Down
9 changes: 9 additions & 0 deletions lib/Crenv/Utils.pm
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@ sub sort_version {
} @$version];
}

sub cmp_version {
my ($lhs, $rhs) = @_;

my ($a1, $a2, $a3) = ($lhs =~ m/(\d+)\.(\d+)\.(\d+)/);
my ($b1, $b2, $b3) = ($rhs =~ m/(\d+)\.(\d+)\.(\d+)/);

return $a1 <=> $b1 || $a2 <=> $b2 || $a3 <=> $b3
}

sub system_info {
my $arch;
my ($sysname, $machine) = (POSIX::uname)[0, 4];
Expand Down
20 changes: 20 additions & 0 deletions t/crenv/utils/cmp_version.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
use strict;
use warnings;
use utf8;

use t::Util;
use Crenv::Utils;

sub cmp_version { Crenv::Utils::cmp_version(@_) }

subtest basic => sub {
cmp_ok cmp_version('0.8.0', '0.7.0'), '>', 0;
cmp_ok cmp_version('0.10.0', '0.7.0'), '>', 0;
cmp_ok cmp_version('0.12.0', '0.10.0'), '>', 0;

cmp_ok cmp_version('0.7.1', '0.7.0'), '>', 0;
cmp_ok cmp_version('0.7.0', '0.7.1'), '<', 0;
cmp_ok cmp_version('0.7.0', '0.7.0'), '==', 0;
};

done_testing;
Loading

0 comments on commit 6aec576

Please sign in to comment.