File: 24-note.t

package info (click to toggle)
libgit-raw-perl 0.79-7
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 1,448 kB
  • sloc: perl: 5,267; ansic: 182; makefile: 6
file content (70 lines) | stat: -rw-r--r-- 2,428 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!perl

use Test::More;

use Git::Raw;
use File::Spec::Functions qw(catfile rel2abs);

my $path = rel2abs(catfile('t', 'test_repo'));
my $repo = Git::Raw::Repository -> open($path);

my $git_default_notes_ref = 'refs/notes/commits';
my $notes_ref = $repo -> config -> str('core.notesRef') || $git_default_notes_ref;

my $ref = Git::Raw::Note -> default_ref($repo);
is $ref, undef;

my $note = Git::Raw::Note -> create($repo, $repo -> head -> target, 'Some content');
isa_ok $note, 'Git::Raw::Note';
is length($note -> id), 40;
is $note -> message, 'Some content';

$note = eval { Git::Raw::Note -> create($repo, $repo -> head -> target, 'Some content') };
is $note, undef;

$note = Git::Raw::Note -> create($repo, $repo -> head -> target, 'Some content2!', undef, 1);

my $default_sig = Git::Raw::Signature -> default($repo);
my $author = $note -> author;
is $author -> name, $default_sig -> name;
is $author -> email, $default_sig -> email;

my $committer = $note -> committer;
is $committer -> name, $default_sig -> name;
is $committer -> email, $default_sig -> email;

diag "repo notes ref is: $notes_ref"
    if $git_default_notes_ref ne $notes_ref;
$ref = Git::Raw::Note -> default_ref($repo);
isa_ok $ref, 'Git::Raw::Reference';
is $ref -> name, $notes_ref;
is $ref -> is_note, 1;

my $note2 = Git::Raw::Note -> read($repo, $repo -> head -> target);
isa_ok $note2, 'Git::Raw::Note';
is $note2 -> id, $note -> id;
is $note2 -> message, $note -> message;

$note = eval { Git::Raw::Note -> create($repo, $repo -> head -> target, 'Some content', 'invalidref') };
is $note, undef;

$note = Git::Raw::Note -> create($repo, $repo -> head -> target, 'Some content', 'refs/notes/commits2');
isa_ok $note, 'Git::Raw::Note';

$note2 = Git::Raw::Note -> read($repo, $repo -> head -> target, 'refs/notes/commits2');
isa_ok $note2, 'Git::Raw::Note';

Git::Raw::Note -> remove($repo, $repo -> head -> target, 'refs/notes/commits2');
my $note3 = Git::Raw::Note -> read($repo, $repo -> head -> target, 'refs/notes/commits2');
is $note3, undef;
Git::Raw::Note -> remove($repo, $repo -> head -> target, 'refs/notes/commits2');

$note2 = Git::Raw::Note -> read($repo, $repo -> head -> target);
isa_ok $note2, 'Git::Raw::Note';

Git::Raw::Note -> remove($repo, $repo -> head -> target);
$note3 = Git::Raw::Note -> read($repo, $repo -> head -> target);
is $note3, undef;
Git::Raw::Note -> remove($repo, $repo -> head -> target);

done_testing;