git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [RFC/PATCH] test suite for Git.pm
@ 2008-06-01  3:51 Lea Wiemann
  2008-06-01  5:03 ` Lea Wiemann
  2008-06-01 22:41 ` [RFC/PATCH v2] " Lea Wiemann
  0 siblings, 2 replies; 4+ messages in thread
From: Lea Wiemann @ 2008-06-01  3:51 UTC (permalink / raw)
  To: git; +Cc: pasky, Lea Wiemann

Added a shell script (t/t9700-perl-git.sh) that sets up a git
repository and a perl script (t/t9700/test.pl) that runs the actual
tests.

Signed-off-by: Lea Wiemann <LeWiemann@gmail.com>
---
Hi everyone!

Here's my first draft for a test suite for Git.pm.  It doesn't test
all of Git.pm yet, but I'll add more tests later.  Comments are
appreciated!

My test-fu didn't suffice for testing the command methods (which are
responsible for calling git), and I'm not currently planning to.  I'm
hoping to add more coverage to the constructor (Git->repository)
though.

Something I'm not sure about yet is how to test failure cases -- for
instance, there are a couple of methods in Git.pm that return undef
for $E->value (i.e. exit code) == 1, but die for $E->value > 1.  The
latter case I can't currently test.  Ideas how to test those cases
cleanly (i.e. how to simulate/mock an exit code > 1) are very welcome.

(Petr:) There's some serious strangeness going on where calling
wc_chdir causes all subsequent commands to fail (marked as TODO at the
end).  I've spent half an hour unsuccessfully trying to track down the
error.  It would be great if you (or anyone else with more Git
experience than me) could have a look at this.

-- Lea


 t/t9700-perl-git.sh |   40 +++++++++++++++++++++++++++++
 t/t9700/test.pl     |   70 +++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 110 insertions(+), 0 deletions(-)
 create mode 100755 t/t9700-perl-git.sh
 create mode 100755 t/t9700/test.pl

diff --git a/t/t9700-perl-git.sh b/t/t9700-perl-git.sh
new file mode 100755
index 0000000..735ada1
--- /dev/null
+++ b/t/t9700-perl-git.sh
@@ -0,0 +1,40 @@
+#!/bin/sh
+#
+# Copyright (c) 2008 Lea Wiemann
+#
+
+test_description='perl interface (Git.pm)'
+. ./test-lib.sh
+
+# set up test repository
+
+test_expect_success \
+    'set up test repository' \
+    'echo "*.test" > .gitignore &&
+
+     echo "test file 1" > file1 &&
+     echo "test file 2" > file2 &&
+     mkdir directory1 &&
+     echo "in directory1" >> directory1/file &&
+     mkdir directory2 &&
+     echo "in directory2" >> directory2/file &&
+     git add . &&
+     git commit -m "first commit" &&
+     git rev-parse HEAD > revisions.test &&
+
+     git tag -- --silly-name &&
+
+     echo "changed file 1" > file1 &&
+     git add . &&
+     git commit -m "second commit" &&
+     git rev-parse HEAD >> revisions.test &&
+
+     git-config --add color.test.slot1 green &&
+     (git-config --get-color color.test.slot1 red; echo foo) > x
+     '
+
+test_external_without_stderr \
+    'Perl API' \
+    perl ../t9700/test.pl
+
+test_done
diff --git a/t/t9700/test.pl b/t/t9700/test.pl
new file mode 100755
index 0000000..c8d5c64
--- /dev/null
+++ b/t/t9700/test.pl
@@ -0,0 +1,70 @@
+#!/usr/bin/perl
+
+use warnings;
+use strict;
+
+use Test::More qw(no_plan);
+use Cwd;
+use File::Basename;
+
+BEGIN { use_ok('Git') }
+require_ok('Git');
+
+# set up
+#our $repo_dir = "trash directory";
+our $abs_repo_dir = Cwd->cwd;
+ok(our $r = Git->repository(Directory => "."), "open repository");
+ok((open REVISIONS, 'revisions.test' and chomp(our @revisions = <REVISIONS>)),
+   "(read revisions)");
+
+# ident
+like($r->ident("aUthor"), qr/^A U Thor <author\@example.com> [0-9]+ \+0000$/,
+     "ident scalar: author (type)");
+like($r->ident("cOmmitter"), qr/^C O Mitter <committer\@example.com> [0-9]+ \+0000$/,
+     "ident scalar: committer (type)");
+is($r->ident("invalid"), "invalid", "ident scalar: invalid ident string (no parsing)");
+my ($name, $email, $time_tz) = $r->ident('author');
+is_deeply([$name, $email], ["A U Thor", "author\@example.com"],
+	 "ident array: author");
+like($time_tz, qr/[0-9]+ \+0000/, "ident array: author");
+is_deeply([$r->ident("Name <email> 123 +0000")], ["Name", "email", "123 +0000"],
+	  "ident array: ident string");
+is_deeply([$r->ident("invalid")], [], "ident array: invalid ident string");
+# ident_person
+is($r->ident_person("aUthor"), "A U Thor <author\@example.com>",
+   "ident_person: author (type)");
+is($r->ident_person("Name <email> 123 +0000"), "Name <email>",
+   "ident_person: ident string");
+is($r->ident_person("Name", "email", "123 +0000"), "Name <email>",
+   "ident_person: array");
+
+# parse_rev
+is($r->parse_rev("HEAD"), $revisions[-1], "parse_rev: 'HEAD'");
+is($r->parse_rev("HEAD^"), $revisions[-2], "parse_rev: 'HEAD^'");
+is($r->parse_rev($revisions[0]), $revisions[0], "parse_rev: SHA1");
+is($r->parse_rev("--silly-name"), $revisions[0], "parse_rev: tag");
+is($r->parse_rev("nonexistent"), undef, "parse_rev: nonexistent name");
+is($r->parse_rev("0" x 40), "0" x 40, "parse_rev: nonexistent SHA1");
+
+# colors
+our $ansi_green = "\x1b[32m";
+# Cannot test $r->get_colorbool("color.foo")) since our stdout is not
+# a terminal.
+
+# paths
+is($r->get_color("color.test.slot1", "red"), $ansi_green, "get_color");
+is($r->repo_path, "./.git", "repo_path");
+is($r->wc_path, $abs_repo_dir . "/", "wc_path");
+is($r->wc_subdir, "", "wc_subdir initial");
+$r->wc_chdir("directory1");
+is($r->wc_subdir, "directory1", "wc_subdir after wc_chdir");
+TODO: {
+	local $TODO = "commands do not work after wc_chdir";
+	# Failure output is active even when in non-verbose mode and
+	# thus annoying, and the ANSI codes mess up the output on top
+	# of that.  Thus we simply skip these tests while they fail.
+	todo_skip 'get_color after wc_chdir', 2;
+	is($r->get_color("color.test.slot1", "red"), $ansi_green, "get_color after wc_chdir");
+	is($r->parse_rev("HEAD"), $revisions[-1], "parse_rev after wc_chdir");
+}
+
-- 
1.5.5.GIT

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [RFC/PATCH] test suite for Git.pm
  2008-06-01  3:51 [RFC/PATCH] test suite for Git.pm Lea Wiemann
@ 2008-06-01  5:03 ` Lea Wiemann
  2008-06-01 22:41 ` [RFC/PATCH v2] " Lea Wiemann
  1 sibling, 0 replies; 4+ messages in thread
From: Lea Wiemann @ 2008-06-01  5:03 UTC (permalink / raw)
  To: Lea Wiemann; +Cc: git, pasky

Lea Wiemann wrote:
> Added a shell script (t/t9700-perl-git.sh) that sets up a git
> repository and a perl script (t/t9700/test.pl) that runs the actual
> tests.

I just realized that it's a little hard to run this test suite since it 
depends on previous patches I sent.  So if you want to test it without 
applying those patches, please clone my repository: 
http://repo.or.cz/w/git/gitweb-caching.git

(Note that I may be rebasing the master branch and pushing new versions 
of my latest commit(s).  Hence, I believe that you will have to use 
git-pull --rebase to keep your clone up-to-date.)

-- Lea

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [RFC/PATCH v2] test suite for Git.pm
  2008-06-01  3:51 [RFC/PATCH] test suite for Git.pm Lea Wiemann
  2008-06-01  5:03 ` Lea Wiemann
@ 2008-06-01 22:41 ` Lea Wiemann
  2008-06-01 23:30   ` [RFC/PATCH v3] " Lea Wiemann
  1 sibling, 1 reply; 4+ messages in thread
From: Lea Wiemann @ 2008-06-01 22:41 UTC (permalink / raw)
  To: git; +Cc: pasky, gitster, Lea Wiemann

Added a shell script (t/t9700-perl-git.sh) that sets up a git
repository and a perl script (t/t9700/test.pl) that runs the actual
tests.

Signed-off-by: Lea Wiemann <LeWiemann@gmail.com>
---
Hi!

Here's my second version of the test suite.  The most important
additions since v1 are the following test sections: "config", "failure
cases for config", and "objects and hashes".

Everybody, if you have Unix (or Cygwin perhaps?) and 5 minutes to
spare, would you mind cloning my branch from
<http://repo.or.cz/w/git/gitweb-caching.git> [1], run
"make && cd t && ./t9700-perl-git.sh -v", and email me your platform
and whether the test succeeded or failed, plus error messages if any?

The remaining untested methods are:

repository: Should get more testing in the future.  (I'm planning to
  refactor it, so at that point I will automatically have to add
  tests.)

command*, exec_path, version, get_colorbool: These interact with the
  system, and I don't see how to easily test those right now.  At
  least command* and exec_path get tested indirectly through other
  methods.

Also, there is an outstanding issue (might be a bug, but I'm not sure)
in the .TODO section at the bottom.  It's an issue with Git.pm, so it
shouldn't prevent this test suite from being merged.  (I probably
won't have time to fix it since I don't understand the methods
involved well enough, but perhaps Petr has an idea or can at least
confirm whether this is a bug.)

-- Lea

Footnotes:

[1] Again, note that I will be rebasing/resetting the master branch
    and pushing new versions of my latest commits.  Hence, I believe
    that you will have to use git-pull --rebase to keep your clone
    up-to-date.

 t/t9700-perl-git.sh |   46 +++++++++++++++++++++
 t/t9700/test.pl     |  111 +++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 157 insertions(+), 0 deletions(-)
 create mode 100755 t/t9700-perl-git.sh
 create mode 100755 t/t9700/test.pl

diff --git a/t/t9700-perl-git.sh b/t/t9700-perl-git.sh
new file mode 100755
index 0000000..71c49bd
--- /dev/null
+++ b/t/t9700-perl-git.sh
@@ -0,0 +1,46 @@
+#!/bin/sh
+#
+# Copyright (c) 2008 Lea Wiemann
+#
+
+test_description='perl interface (Git.pm)'
+. ./test-lib.sh
+
+# set up test repository
+
+test_expect_success \
+    'set up test repository' \
+    'echo "*.test" > .gitignore &&
+
+     echo "test file 1" > file1 &&
+     echo "test file 2" > file2 &&
+     mkdir directory1 &&
+     echo "in directory1" >> directory1/file &&
+     mkdir directory2 &&
+     echo "in directory2" >> directory2/file &&
+     git add . &&
+     git commit -m "first commit" &&
+     git rev-parse HEAD > revisions.test &&
+
+     git tag -- --silly-name &&
+
+     echo "changed file 1" > file1 &&
+     git add . &&
+     git commit -m "second commit" &&
+     git rev-parse HEAD >> revisions.test &&
+
+     git-config --add color.test.slot1 green &&
+     git-config --add test.string value &&
+     git-config --add test.dupstring value1 &&
+     git-config --add test.dupstring value2 &
+     git-config --add test.booltrue true &&
+     git-config --add test.boolfalse no &&
+     git-config --add test.boolother other &&
+     git-config --add test.int 2k
+     '
+
+test_external_without_stderr \
+    'Perl API' \
+    perl ../t9700/test.pl
+
+test_done
diff --git a/t/t9700/test.pl b/t/t9700/test.pl
new file mode 100755
index 0000000..91dd8da
--- /dev/null
+++ b/t/t9700/test.pl
@@ -0,0 +1,111 @@
+#!/usr/bin/perl
+
+use warnings;
+use strict;
+
+use Test::More qw(no_plan);
+
+use Cwd;
+use File::Basename;
+use File::Temp;
+use IO::String;
+
+BEGIN { use_ok('Git') }
+require_ok('Git');
+
+# set up
+our $repo_dir = "trash directory";
+our $abs_repo_dir = Cwd->cwd;
+die "this must be run by calling the t/t97* shell script(s)\n"
+    if basename(Cwd->cwd) ne $repo_dir;
+ok(our $r = Git->repository(Directory => "."), "open repository");
+ok((open REVISIONS, 'revisions.test' and chomp(our @revisions = <REVISIONS>)),
+   "(read revisions)");
+
+# config
+is($r->config("test.string"), "value", "config scalar: string");
+is_deeply([$r->config("test.dupstring")], ["value1", "value2"],
+	  "config array: string");
+is($r->config("test.nonexistent"), undef, "config scalar: nonexistent");
+is_deeply([$r->config("test.nonexistent")], [], "config array: nonexistent");
+is($r->config_int("test.int"), 2048, "config_int: integer");
+is($r->config_int("test.nonexistent"), undef, "config_int: nonexistent");
+ok($r->config_bool("test.booltrue"), "config_bool: true");
+ok(!$r->config_bool("test.boolfalse"), "config_bool: false");
+our $ansi_green = "\x1b[32m";
+is($r->get_color("color.test.slot1", "red"), $ansi_green, "get_color");
+# Cannot test $r->get_colorbool("color.foo")) because we do not
+# control whether our STDOUT is a terminal.
+
+# Failure cases for config:
+# Save and restore STDERR; we will probably extract this into a
+# "dies_ok" method and possibly move the STDERR handling to Git.pm.
+open our $tmpstderr, ">&", STDERR or die "cannot save STDERR"; close STDERR;
+eval { $r->config("test.dupstring") };
+ok($@, "config: duplicate entry in scalar context fails");
+eval { $r->config_bool("test.boolother") };
+ok($@, "config_bool: non-boolean values fail");
+open STDERR, ">&", $tmpstderr or die "cannot restore STDERR";
+
+# ident
+like($r->ident("aUthor"), qr/^A U Thor <author\@example.com> [0-9]+ \+0000$/,
+     "ident scalar: author (type)");
+like($r->ident("cOmmitter"), qr/^C O Mitter <committer\@example.com> [0-9]+ \+0000$/,
+     "ident scalar: committer (type)");
+is($r->ident("invalid"), "invalid", "ident scalar: invalid ident string (no parsing)");
+my ($name, $email, $time_tz) = $r->ident('author');
+is_deeply([$name, $email], ["A U Thor", "author\@example.com"],
+	 "ident array: author");
+like($time_tz, qr/[0-9]+ \+0000/, "ident array: author");
+is_deeply([$r->ident("Name <email> 123 +0000")], ["Name", "email", "123 +0000"],
+	  "ident array: ident string");
+is_deeply([$r->ident("invalid")], [], "ident array: invalid ident string");
+
+# ident_person
+is($r->ident_person("aUthor"), "A U Thor <author\@example.com>",
+   "ident_person: author (type)");
+is($r->ident_person("Name <email> 123 +0000"), "Name <email>",
+   "ident_person: ident string");
+is($r->ident_person("Name", "email", "123 +0000"), "Name <email>",
+   "ident_person: array");
+
+# parse_rev
+is($r->parse_rev("HEAD"), $revisions[-1], "parse_rev: 'HEAD'");
+is($r->parse_rev("HEAD^"), $revisions[-2], "parse_rev: 'HEAD^'");
+is($r->parse_rev($revisions[0]), $revisions[0], "parse_rev: SHA1");
+is($r->parse_rev("--silly-name"), $revisions[0], "parse_rev: tag");
+is($r->parse_rev("nonexistent"), undef, "parse_rev: nonexistent name");
+is($r->parse_rev("0" x 40), "0" x 40, "parse_rev: nonexistent SHA1");
+
+# objects and hashes
+ok(our $file1hash = $r->parse_rev("$revisions[1]:file1"), "(get file hash)");
+our $iostring = IO::String->new;
+is($r->cat_blob($file1hash, $iostring), 15, "cat_blob: size");
+is(${$iostring->string_ref}, "changed file 1\n", "cat_blob: data");
+our $tmpfile = File::Temp->new();
+print $tmpfile ${$iostring->string_ref};
+is(Git::hash_object("blob", $tmpfile), $file1hash, "hash_object: roundtrip");
+$tmpfile = File::Temp->new();
+print $tmpfile my $test_text = "test blob, to be inserted\n";
+$tmpfile->close;
+like(our $newhash = $r->hash_and_insert_object($tmpfile), qr/[0-9a-fA-F]{40}/,
+     "hash_and_insert_object: returns hash");
+$iostring = IO::String->new;
+is($r->cat_blob($newhash, $iostring), length $test_text, "cat_blob: roundtrip size");
+is(${$iostring->string_ref}, $test_text, "cat_blob: roundtrip data");
+
+# paths
+is($r->repo_path, "./.git", "repo_path");
+is($r->wc_path, $abs_repo_dir . "/", "wc_path");
+is($r->wc_subdir, "", "wc_subdir initial");
+$r->wc_chdir("directory1");
+is($r->wc_subdir, "directory1", "wc_subdir after wc_chdir");
+TODO: {
+	local $TODO = "commands do not work after wc_chdir";
+	# Failure output is active even in non-verbose mode and thus
+	# annoying, and parse_rev even dies.  Hence we skip these
+	# tests as long as they fail.
+	todo_skip 'config and parse_rev after wc_chdir', 2;
+	is($r->config("color.string"), "value", "config after wc_chdir");
+	is($r->parse_rev("HEAD"), $revisions[-1], "parse_rev after wc_chdir");
+}
-- 
1.5.5.GIT

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [RFC/PATCH v3] test suite for Git.pm
  2008-06-01 22:41 ` [RFC/PATCH v2] " Lea Wiemann
@ 2008-06-01 23:30   ` Lea Wiemann
  0 siblings, 0 replies; 4+ messages in thread
From: Lea Wiemann @ 2008-06-01 23:30 UTC (permalink / raw)
  To: git; +Cc: Lea Wiemann

Added a shell script (t/t9700-perl-git.sh) that sets up a git
repository and a perl script (t/t9700/test.pl) that runs the actual
tests.

Signed-off-by: Lea Wiemann <LeWiemann@gmail.com>
---
Shouldn't have sent v2 so early. ;-)  Changed since v2:

Call get_hash instead of parse_rev, as necessitated by the recent
rename at
http://mid.gmane.org/1212361784-20409-1-git-send-email-LeWiemann@gmail.com

 t/t9700-perl-git.sh |   46 +++++++++++++++++++++
 t/t9700/test.pl     |  111 +++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 157 insertions(+), 0 deletions(-)
 create mode 100755 t/t9700-perl-git.sh
 create mode 100755 t/t9700/test.pl

diff --git a/t/t9700-perl-git.sh b/t/t9700-perl-git.sh
new file mode 100755
index 0000000..71c49bd
--- /dev/null
+++ b/t/t9700-perl-git.sh
@@ -0,0 +1,46 @@
+#!/bin/sh
+#
+# Copyright (c) 2008 Lea Wiemann
+#
+
+test_description='perl interface (Git.pm)'
+. ./test-lib.sh
+
+# set up test repository
+
+test_expect_success \
+    'set up test repository' \
+    'echo "*.test" > .gitignore &&
+
+     echo "test file 1" > file1 &&
+     echo "test file 2" > file2 &&
+     mkdir directory1 &&
+     echo "in directory1" >> directory1/file &&
+     mkdir directory2 &&
+     echo "in directory2" >> directory2/file &&
+     git add . &&
+     git commit -m "first commit" &&
+     git rev-parse HEAD > revisions.test &&
+
+     git tag -- --silly-name &&
+
+     echo "changed file 1" > file1 &&
+     git add . &&
+     git commit -m "second commit" &&
+     git rev-parse HEAD >> revisions.test &&
+
+     git-config --add color.test.slot1 green &&
+     git-config --add test.string value &&
+     git-config --add test.dupstring value1 &&
+     git-config --add test.dupstring value2 &
+     git-config --add test.booltrue true &&
+     git-config --add test.boolfalse no &&
+     git-config --add test.boolother other &&
+     git-config --add test.int 2k
+     '
+
+test_external_without_stderr \
+    'Perl API' \
+    perl ../t9700/test.pl
+
+test_done
diff --git a/t/t9700/test.pl b/t/t9700/test.pl
new file mode 100755
index 0000000..c76e6ac
--- /dev/null
+++ b/t/t9700/test.pl
@@ -0,0 +1,111 @@
+#!/usr/bin/perl
+
+use warnings;
+use strict;
+
+use Test::More qw(no_plan);
+
+use Cwd;
+use File::Basename;
+use File::Temp;
+use IO::String;
+
+BEGIN { use_ok('Git') }
+require_ok('Git');
+
+# set up
+our $repo_dir = "trash directory";
+our $abs_repo_dir = Cwd->cwd;
+die "this must be run by calling the t/t97* shell script(s)\n"
+    if basename(Cwd->cwd) ne $repo_dir;
+ok(our $r = Git->repository(Directory => "."), "open repository");
+ok((open REVISIONS, 'revisions.test' and chomp(our @revisions = <REVISIONS>)),
+   "(read revisions)");
+
+# config
+is($r->config("test.string"), "value", "config scalar: string");
+is_deeply([$r->config("test.dupstring")], ["value1", "value2"],
+	  "config array: string");
+is($r->config("test.nonexistent"), undef, "config scalar: nonexistent");
+is_deeply([$r->config("test.nonexistent")], [], "config array: nonexistent");
+is($r->config_int("test.int"), 2048, "config_int: integer");
+is($r->config_int("test.nonexistent"), undef, "config_int: nonexistent");
+ok($r->config_bool("test.booltrue"), "config_bool: true");
+ok(!$r->config_bool("test.boolfalse"), "config_bool: false");
+our $ansi_green = "\x1b[32m";
+is($r->get_color("color.test.slot1", "red"), $ansi_green, "get_color");
+# Cannot test $r->get_colorbool("color.foo")) because we do not
+# control whether our STDOUT is a terminal.
+
+# Failure cases for config:
+# Save and restore STDERR; we will probably extract this into a
+# "dies_ok" method and possibly move the STDERR handling to Git.pm.
+open our $tmpstderr, ">&", STDERR or die "cannot save STDERR"; close STDERR;
+eval { $r->config("test.dupstring") };
+ok($@, "config: duplicate entry in scalar context fails");
+eval { $r->config_bool("test.boolother") };
+ok($@, "config_bool: non-boolean values fail");
+open STDERR, ">&", $tmpstderr or die "cannot restore STDERR";
+
+# ident
+like($r->ident("aUthor"), qr/^A U Thor <author\@example.com> [0-9]+ \+0000$/,
+     "ident scalar: author (type)");
+like($r->ident("cOmmitter"), qr/^C O Mitter <committer\@example.com> [0-9]+ \+0000$/,
+     "ident scalar: committer (type)");
+is($r->ident("invalid"), "invalid", "ident scalar: invalid ident string (no parsing)");
+my ($name, $email, $time_tz) = $r->ident('author');
+is_deeply([$name, $email], ["A U Thor", "author\@example.com"],
+	 "ident array: author");
+like($time_tz, qr/[0-9]+ \+0000/, "ident array: author");
+is_deeply([$r->ident("Name <email> 123 +0000")], ["Name", "email", "123 +0000"],
+	  "ident array: ident string");
+is_deeply([$r->ident("invalid")], [], "ident array: invalid ident string");
+
+# ident_person
+is($r->ident_person("aUthor"), "A U Thor <author\@example.com>",
+   "ident_person: author (type)");
+is($r->ident_person("Name <email> 123 +0000"), "Name <email>",
+   "ident_person: ident string");
+is($r->ident_person("Name", "email", "123 +0000"), "Name <email>",
+   "ident_person: array");
+
+# get_hash
+is($r->get_hash("HEAD"), $revisions[-1], "get_hash: 'HEAD'");
+is($r->get_hash("HEAD^"), $revisions[-2], "get_hash: 'HEAD^'");
+is($r->get_hash($revisions[0]), $revisions[0], "get_hash: SHA1");
+is($r->get_hash("--silly-name"), $revisions[0], "get_hash: tag");
+is($r->get_hash("nonexistent"), undef, "get_hash: nonexistent name");
+is($r->get_hash("0" x 40), "0" x 40, "get_hash: nonexistent SHA1");
+
+# objects and hashes
+ok(our $file1hash = $r->get_hash("$revisions[1]:file1"), "(get file hash)");
+our $iostring = IO::String->new;
+is($r->cat_blob($file1hash, $iostring), 15, "cat_blob: size");
+is(${$iostring->string_ref}, "changed file 1\n", "cat_blob: data");
+our $tmpfile = File::Temp->new();
+print $tmpfile ${$iostring->string_ref};
+is(Git::hash_object("blob", $tmpfile), $file1hash, "hash_object: roundtrip");
+$tmpfile = File::Temp->new();
+print $tmpfile my $test_text = "test blob, to be inserted\n";
+$tmpfile->close;
+like(our $newhash = $r->hash_and_insert_object($tmpfile), qr/[0-9a-fA-F]{40}/,
+     "hash_and_insert_object: returns hash");
+$iostring = IO::String->new;
+is($r->cat_blob($newhash, $iostring), length $test_text, "cat_blob: roundtrip size");
+is(${$iostring->string_ref}, $test_text, "cat_blob: roundtrip data");
+
+# paths
+is($r->repo_path, "./.git", "repo_path");
+is($r->wc_path, $abs_repo_dir . "/", "wc_path");
+is($r->wc_subdir, "", "wc_subdir initial");
+$r->wc_chdir("directory1");
+is($r->wc_subdir, "directory1", "wc_subdir after wc_chdir");
+TODO: {
+	local $TODO = "commands do not work after wc_chdir";
+	# Failure output is active even in non-verbose mode and thus
+	# annoying, and get_hash even dies.  Hence we skip these tests
+	# as long as they fail.
+	todo_skip 'config and get_hash after wc_chdir', 2;
+	is($r->config("color.string"), "value", "config after wc_chdir");
+	is($r->get_hash("HEAD"), $revisions[-1], "get_hash after wc_chdir");
+}
-- 
1.5.5.GIT

^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2008-06-01 23:31 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-06-01  3:51 [RFC/PATCH] test suite for Git.pm Lea Wiemann
2008-06-01  5:03 ` Lea Wiemann
2008-06-01 22:41 ` [RFC/PATCH v2] " Lea Wiemann
2008-06-01 23:30   ` [RFC/PATCH v3] " Lea Wiemann

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).