aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeddy Wing2016-04-22 22:18:36 -0400
committerTeddy Wing2016-04-22 22:18:36 -0400
commit9b967f55333c82d333d88bfda41dd576b9ff5b46 (patch)
tree3b459422579ce72860b1e16681022675cd7e5989
parentec4541af5c81d7692ab3e1b858e24b35c60b3de5 (diff)
downloadmutt-alias-auto-add-9b967f55333c82d333d88bfda41dd576b9ff5b46.tar.bz2
Add integration test
Use the TAP harness with `prove` to give ourselves an integration test of the executable. This checks that when passing an email to it over STDIN, the proper alias gets added to the aliases file. For the moment, we're using the temporary `./testaliases` file. In the future we'll want to update our program and test code to use something like `./testdata/tmp` or something like that.
-rw-r--r--t/001-creates-a-new-alias-for-a-contact-with-an-existing-name.t48
1 files changed, 48 insertions, 0 deletions
diff --git a/t/001-creates-a-new-alias-for-a-contact-with-an-existing-name.t b/t/001-creates-a-new-alias-for-a-contact-with-an-existing-name.t
new file mode 100644
index 0000000..2ab2fa3
--- /dev/null
+++ b/t/001-creates-a-new-alias-for-a-contact-with-an-existing-name.t
@@ -0,0 +1,48 @@
+#!/usr/bin/env perl
+
+use strict;
+use warnings;
+
+use Test::More;
+
+use feature qw(say);
+
+# Append test alias to alises file
+open(my $fh, '>>', './testaliases') or die;
+say $fh 'alias paris-numa NUMA Paris <communique@numa.co>';
+close $fh;
+
+
+my $output = `cat ./testdata/email | ./target/debug/alias-auto-add`;
+ok !$?;
+
+# Check that the program outputs the full email coming from STDIN
+{
+ open(my $fh, '<', './testdata/email') or die;
+ local $/ = undef;
+ my $email = <$fh>;
+
+ is $output, $email;
+
+ close $fh;
+}
+
+# Check that the aliases file includes an alias for the address from the input email
+{
+ open(my $fh, '<', './testaliases') or die;
+
+ my $last_line;
+ while (my $line = readline $fh) {
+ $last_line = $line;
+ }
+
+ is $last_line, 'alias paris-numa-2 NUMA Paris <communication@numa.co>' . "\n";
+
+ close $fh;
+}
+
+
+# Teardown
+
+
+done_testing;