From 6f078aecf87d39882c0fce1cc61b6220add43208 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Fri, 22 Apr 2016 21:24:56 -0400 Subject: test.sh: Initial stab at an integration test Would like to modify the program to take a `--file` attribute so that we can supply a file on the command line to do an integration test with. The idea is that we pipe an email to the program and check that the right alias was added to our aliases file. --- test.sh | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 test.sh diff --git a/test.sh b/test.sh new file mode 100644 index 0000000..d23a1b9 --- /dev/null +++ b/test.sh @@ -0,0 +1,18 @@ +#!/bin/sh + +cargo build + +function test_creates_a_new_alias_for_a_contact_with_an_existing_name() { + cp testdata/aliases testdata/tmp + # echo 'alias paris-numa NUMA Paris ' >> testdata/tmp + # echo 'alias paris-numa NUMA Paris ' >> ./testaliases + + cat testdata/email | ./target/debug/alias-auto-add + + + + # rm testdata/tmp +} + + +test_creates_a_new_alias_for_a_contact_with_an_existing_name -- cgit v1.2.3 From ec4541af5c81d7692ab3e1b858e24b35c60b3de5 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Fri, 22 Apr 2016 21:27:46 -0400 Subject: Revert "test.sh: Initial stab at an integration test" This reverts commit 6f078aecf87d39882c0fce1cc61b6220add43208. Decided that I'd rather use TAP/prove to do this integration test. It feels more comfortable to be able to rely on a test harness. Removing this file but keeping it in the log for posterity. --- test.sh | 18 ------------------ 1 file changed, 18 deletions(-) delete mode 100644 test.sh diff --git a/test.sh b/test.sh deleted file mode 100644 index d23a1b9..0000000 --- a/test.sh +++ /dev/null @@ -1,18 +0,0 @@ -#!/bin/sh - -cargo build - -function test_creates_a_new_alias_for_a_contact_with_an_existing_name() { - cp testdata/aliases testdata/tmp - # echo 'alias paris-numa NUMA Paris ' >> testdata/tmp - # echo 'alias paris-numa NUMA Paris ' >> ./testaliases - - cat testdata/email | ./target/debug/alias-auto-add - - - - # rm testdata/tmp -} - - -test_creates_a_new_alias_for_a_contact_with_an_existing_name -- cgit v1.2.3 From 9b967f55333c82d333d88bfda41dd576b9ff5b46 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Fri, 22 Apr 2016 22:18:36 -0400 Subject: 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. --- ...new-alias-for-a-contact-with-an-existing-name.t | 48 ++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 t/001-creates-a-new-alias-for-a-contact-with-an-existing-name.t 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 '; +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 ' . "\n"; + + close $fh; +} + + +# Teardown + + +done_testing; -- cgit v1.2.3 From c4302101fd44747e33e0d3b311e659f9467e3e18 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Fri, 22 Apr 2016 22:20:46 -0400 Subject: Add Makefile Give us a task to run integration tests. This provides us with an explicit definition of how these should be run, rather than me just knowing that you have to run `prove` in order to execute them. --- Makefile | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 Makefile diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..3204ff4 --- /dev/null +++ b/Makefile @@ -0,0 +1,2 @@ +test-integration: + prove -v -- cgit v1.2.3