Skip to content

Commit

Permalink
Only test what matters: error codes are unique (apart from success)
Browse files Browse the repository at this point in the history
The tests failed when the upstream library rearranged its constants; but
the value is not an API feature, so we shouldn't depend on it but instead
test that error conditions return the right constant by triggering those
errors.
  • Loading branch information
samv committed Jul 23, 2011
1 parent daef5c4 commit d558e49
Showing 1 changed file with 19 additions and 31 deletions.
50 changes: 19 additions & 31 deletions t/git.t
Original file line number Diff line number Diff line change
Expand Up @@ -163,37 +163,25 @@ sub test_version {


sub test_constants {
my $code = 0;
is(Git2::GIT_SUCCESS, $code--, "GIT_SUCCESS is ok");
is(Git2::GIT_ERROR, $code--, "GIT_ERROR is ok");
is(Git2::GIT_ENOTOID, $code--, "GIT_ENOTOID is ok");
is(Git2::GIT_ENOTFOUND, $code--, "GIT_ENOTFOUND is ok");
is(Git2::GIT_ENOMEM, $code--, "GIT_ENOMEM is ok");
is(Git2::GIT_EOSERR, $code--, "GIT_EOSERR is ok");
is(Git2::GIT_EOBJTYPE, $code--, "GIT_EOBJTYPE is ok");
is(Git2::GIT_EOBJCORRUPTED, $code--, "GIT_EOBJCORRUPTED is ok");
is(Git2::GIT_ENOTAREPO, $code--, "GIT_ENOTAREPO is ok");
is(Git2::GIT_EINVALIDTYPE, $code--, "GIT_EINVALIDTYPE is ok");
is(Git2::GIT_EMISSINGOBJDATA, $code--, "GIT_EMISSINGOBJDATA is ok");
is(Git2::GIT_EPACKCORRUPTED, $code--, "GIT_EPACKCORRUPTED is ok");
is(Git2::GIT_EFLOCKFAIL, $code--, "GIT_EFLOCKFAIL is ok");
is(Git2::GIT_EZLIB, $code--, "GIT_EZLIB is ok");
is(Git2::GIT_EBUSY, $code--, "GIT_EBUSY is ok");
is(Git2::GIT_EBAREINDEX, $code--, "GIT_EBAREINDEX is ok");
is(Git2::GIT_EINVALIDREFNAME, $code--, "GIT_EINVALIDREFNAME is ok");
is(Git2::GIT_EREFCORRUPTED , $code--, "GIT_EREFCORRUPTED is ok");
is(Git2::GIT_ETOONESTEDSYMREF, $code--, "GIT_ETOONESTEDSYMREF is ok");
is(Git2::GIT_EPACKEDREFSCORRUPTED, $code--, "GIT_EPACKEDREFSCORRUPTED is ok");
is(Git2::GIT_EINVALIDPATH, $code--, "GIT_EINVALIDPATH is ok");
is(Git2::GIT_EREVWALKOVER, $code--, "GIT_EREVWALKOVER is ok");
is(Git2::GIT_EINVALIDREFSTATE, $code--, "GIT_EINVALIDREFSTATE is ok");
is(Git2::GIT_ENOTIMPLEMENTED, $code--, "GIT_ENOTIMPLEMENTED is ok");
is(Git2::GIT_EEXISTS, $code--, "GIT_EEXISTS is ok");
is(Git2::GIT_EOVERFLOW, $code--, "GIT_EOVERFLOW is ok");
is(Git2::GIT_ENOTNUM, $code--, "GIT_ENOTNUM is ok");


$code = -2;

my @constants =
qw( ERROR ENOTOID ENOTFOUND ENOMEM EOSERR EOBJTYPE
EOBJCORRUPTED ENOTAREPO EINVALIDTYPE EMISSINGOBJDATA
EPACKCORRUPTED EFLOCKFAIL EZLIB EBUSY EBAREINDEX
EINVALIDREFNAME EREFCORRUPTED ETOONESTEDSYMREF
EPACKEDREFSCORRUPTED EINVALIDPATH EREVWALKOVER
EINVALIDREFSTATE ENOTIMPLEMENTED EEXISTS EOVERFLOW ENOTNUM
);

is(Git2::GIT_SUCCESS, 0, "GIT_SUCCESS (0) is OK");
no strict 'refs';
my %seen;
for my $constant ( @constants ) {
my $val = &{"Git2::GIT_$constant"};
ok(($val<0) && !$seen{$val}++, "$constant is <0 and unique");
}

my $code = -2;
is(Git2::GIT_OBJ_ANY, $code++, "GIT_OBJ_ANY is ok");
is(Git2::GIT_OBJ_BAD, $code++, "GIT_OBJ_BAD is ok");
is(Git2::GIT_OBJ__EXT1, $code++, "GIT_OBJ__EXT1 is ok");
Expand Down

0 comments on commit d558e49

Please sign in to comment.