From: Lea Wiemann <lewiemann@gmail.com>
To: git@vger.kernel.org
Cc: Lea Wiemann <LeWiemann@gmail.com>
Subject: [PATCH 2/2 v4] Git.pm: add test suite
Date: Tue, 17 Jun 2008 08:59:51 +0200 [thread overview]
Message-ID: <4db23d5b625de1aa026cf4630d49b57fd3a09d07.1213685306.git.LeWiemann@gmail.com> (raw)
In-Reply-To: <d94c2a62edfdec22c32ef5d9649078430b30ecfd.1213685306.git.LeWiemann@gmail.com>
In-Reply-To: <d94c2a62edfdec22c32ef5d9649078430b30ecfd.1213685306.git.LeWiemann@gmail.com>
Add 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>
---
Changed since v3
<http://thread.gmane.org/gmane.comp.version-control.git/83425/focus=83480>:
Only test the vanilla Git.pm, as I'm not intending to extend it right
now. So no Git::get_hash (or Git::rev_parse) method there.
I also simplified the test repository setup code a bit.
t/t9700-perl-git.sh | 39 ++++++++++++++++++++
t/t9700/test.pl | 99 +++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 138 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..592d79a
--- /dev/null
+++ b/t/t9700-perl-git.sh
@@ -0,0 +1,39 @@
+#!/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 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" &&
+
+ echo "changed file 1" > file1 &&
+ git commit -a -m "second commit" &&
+
+ 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..8318fec
--- /dev/null
+++ b/t/t9700/test.pl
@@ -0,0 +1,99 @@
+#!/usr/bin/perl
+use lib (split(/:/, $ENV{GITPERLLIB}));
+
+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') }
+
+# 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");
+
+# 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");
+
+# objects and hashes
+ok(our $file1hash = $r->command_oneline('rev-parse', "HEAD: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. Hence we skip these tests as long as they fail.
+ todo_skip 'config after wc_chdir', 1;
+ is($r->config("color.string"), "value", "config after wc_chdir");
+}
--
1.5.6.rc3.7.ged9620
next prev parent reply other threads:[~2008-06-17 7:01 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-06-17 6:59 [PATCH 1/2 v2] t/test-lib.sh: add test_external and test_external_without_stderr Lea Wiemann
2008-06-17 6:59 ` Lea Wiemann [this message]
2008-06-18 3:16 ` [PATCH 2/2 v4] Git.pm: add test suite Junio C Hamano
2008-06-18 18:04 ` Lea Wiemann
2008-06-18 19:40 ` Junio C Hamano
2008-06-18 20:32 ` Olivier Marin
2008-06-18 20:24 ` [PATCH 1/2 v2] t/test-lib.sh: add test_external and test_external_without_stderr Olivier Marin
2008-06-19 18:18 ` [PATCH 1/2 v3] " Lea Wiemann
2008-06-19 18:18 ` [PATCH 2/2 v5] Git.pm: add test suite Lea Wiemann
2008-06-19 20:32 ` Lea Wiemann
2008-06-19 20:53 ` Jakub Narebski
2008-06-19 20:55 ` Lea Wiemann
2008-06-19 23:55 ` Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4db23d5b625de1aa026cf4630d49b57fd3a09d07.1213685306.git.LeWiemann@gmail.com \
--to=lewiemann@gmail.com \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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 NNTP newsgroup(s).