aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--t/001-setup.t21
-rw-r--r--t/999-teardown.t14
-rw-r--r--t/Ideas.txt1
-rw-r--r--t/bin.pm13
-rw-r--r--t/data/git-sugdiff.rs82
5 files changed, 131 insertions, 0 deletions
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 <https://www.gnu.org/licenses/>.
+
+
+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] <suggestion>...",
+ ) {
+ 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);
+ },
+ _ => (),
+ };
+ },
+ );
+}