From ae4ebe19b66e856758cbd3a9ed768ae146c004cd Mon Sep 17 00:00:00 2001
From: Teddy Wing
Date: Mon, 14 Sep 2020 00:33:14 +0200
Subject: Add TAP test harness
Copied with alterations from git-branch-list.
---
t/001-setup.t | 21 +++++++++++++
t/999-teardown.t | 14 +++++++++
t/Ideas.txt | 1 +
t/bin.pm | 13 ++++++++
t/data/git-sugdiff.rs | 82 +++++++++++++++++++++++++++++++++++++++++++++++++++
5 files changed, 131 insertions(+)
create mode 100644 t/001-setup.t
create mode 100644 t/999-teardown.t
create mode 100644 t/Ideas.txt
create mode 100644 t/bin.pm
create mode 100644 t/data/git-sugdiff.rs
diff --git a/t/001-setup.t b/t/001-setup.t
new file mode 100644
index 0000000..bd4b6ae
--- /dev/null
+++ b/t/001-setup.t
@@ -0,0 +1,21 @@
+#!/usr/bin/env perl -w
+
+use strict;
+
+use File::Copy;
+use Test::More;
+
+system('git init t-git-repo');
+ok !$?;
+
+copy('t/data/git-sugdiff.rs', 't-git-repo') or die $!;
+
+chdir 't-git-repo' or die $!;
+
+system('git add git-sugdiff.rs');
+ok !$?;
+
+system('git commit -m "Commit"');
+ok !$?;
+
+done_testing;
diff --git a/t/999-teardown.t b/t/999-teardown.t
new file mode 100644
index 0000000..e7e8ab2
--- /dev/null
+++ b/t/999-teardown.t
@@ -0,0 +1,14 @@
+#!/usr/bin/env perl -w
+
+use strict;
+
+use Test::More;
+
+if (!-d 't-git-repo') {
+ plan skip_all => 'Testing stage already cleaned.';
+}
+
+system('rm -rf t-git-repo');
+ok !$?;
+
+done_testing;
diff --git a/t/Ideas.txt b/t/Ideas.txt
new file mode 100644
index 0000000..69cccb7
--- /dev/null
+++ b/t/Ideas.txt
@@ -0,0 +1 @@
+TODOs from file prior to branch point
diff --git a/t/bin.pm b/t/bin.pm
new file mode 100644
index 0000000..e216c97
--- /dev/null
+++ b/t/bin.pm
@@ -0,0 +1,13 @@
+package Bin;
+
+use strict;
+use warnings;
+
+use Exporter qw(import);
+our @EXPORT = qw($BIN);
+
+use File::Spec;
+
+our $BIN = File::Spec->rel2abs('git-todo');
+
+1;
diff --git a/t/data/git-sugdiff.rs b/t/data/git-sugdiff.rs
new file mode 100644
index 0000000..df49493
--- /dev/null
+++ b/t/data/git-sugdiff.rs
@@ -0,0 +1,82 @@
+// Copyright (c) 2020 Teddy Wing
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see .
+
+
+use std::env;
+use std::process;
+use std::process::Command;
+
+use exitcode;
+
+use git_suggestion::{gseprintln, for_suggestion};
+use git_suggestion::config::Config;
+use git_suggestion::diff_options;
+
+
+// TODO: one
+fn main() {
+ let args: Vec<_> = env::args().collect();
+
+ let (args, diff_args) = diff_options::parse(&args);
+
+ let config = match Config::get(
+ &args,
+ "usage: git sugdiff [options] ...",
+ ) {
+ Ok(c) => c,
+ Err(e) => {
+ gseprintln!(e);
+
+ process::exit(exitcode::CONFIG);
+ },
+ };
+
+ // TODO two
+ for_suggestion(
+ &config,
+ |suggestion| {
+ let blob = match suggestion.blob() {
+ Ok(b) => b,
+ Err(e) => {
+ gseprintln!(e);
+ process::exit(exitcode::UNAVAILABLE);
+ },
+ };
+
+ let mut child = match Command::new("git")
+ .arg("--no-pager")
+ .arg("diff")
+ .args(&diff_args)
+ .arg(format!("{}:{}", suggestion.commit(), suggestion.path()))
+ .arg(blob.to_string())
+ .spawn()
+ {
+ Ok(c) => c,
+ Err(e) => {
+ gseprintln!(e);
+ process::exit(exitcode::UNAVAILABLE);
+ },
+ };
+
+ match child.wait() {
+ Err(e) => {
+ gseprintln!(e);
+ process::exit(exitcode::UNAVAILABLE);
+ },
+ _ => (),
+ };
+ },
+ );
+}
--
cgit v1.2.3