diff --git a/.travis.yml b/.travis.yml index 2895a95..b915fbf 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,5 +6,10 @@ before_install: - sudo apt-get install -qq bats - sudo apt-get install -qq vlc - sudo apt-get install -qq openssl + - cpanm Sparrow --sudo --notest -q + - sparrow index update + - sparrow plg install bash-snippets-interactive-test + script: -- bats tests + - sparrow plg run bash-snippets-interactive-test --param dir=$PWD + - bats tests diff --git a/bash-snippets-interactive-test/README.md b/bash-snippets-interactive-test/README.md new file mode 100644 index 0000000..6e02eb5 --- /dev/null +++ b/bash-snippets-interactive-test/README.md @@ -0,0 +1,21 @@ +# SYNOPSIS + +Run tests against BashSnippets tools with interactive prompt. + +# INSTALL + + $ sparrow plg install bash-snippets-interactive-test + +# USAGE + + $ sparrow plg run bash-snippets-interactive-test --param dir=/path/to/bash-snippets/tools/directory + + +![report](https://raw.githubusercontent.com/melezhik/images/master/report.png) + +# Authors + +* The plugin maintainer is [Alexey Melezhik](https://github.com/melezhik/) + + + diff --git a/bash-snippets-interactive-test/cpanfile b/bash-snippets-interactive-test/cpanfile new file mode 100644 index 0000000..e8a089f --- /dev/null +++ b/bash-snippets-interactive-test/cpanfile @@ -0,0 +1 @@ +requires "Expect"; diff --git a/bash-snippets-interactive-test/hook.bash b/bash-snippets-interactive-test/hook.bash new file mode 100644 index 0000000..841982e --- /dev/null +++ b/bash-snippets-interactive-test/hook.bash @@ -0,0 +1,4 @@ +#!/usr/bin/env bash + +run_story 'currency/example1' +run_story 'currency/example2' diff --git a/bash-snippets-interactive-test/modules/currency/example1/story.check b/bash-snippets-interactive-test/modules/currency/example1/story.check new file mode 100644 index 0000000..3bdcf3f --- /dev/null +++ b/bash-snippets-interactive-test/modules/currency/example1/story.check @@ -0,0 +1,15 @@ +begin: +What is the base currency: USD +What currency to exchange to: RUB +What is the amount being exchanged: 0 +end: + +begin: +========================= +| USD to RUB +regexp: ^\|\s+Rate:\s+\d+\.\d+\s*$ +| USD: 0 +| RUB: 0 +========================= +end: + diff --git a/bash-snippets-interactive-test/modules/currency/example1/story.pl b/bash-snippets-interactive-test/modules/currency/example1/story.pl new file mode 100644 index 0000000..f4fd5c4 --- /dev/null +++ b/bash-snippets-interactive-test/modules/currency/example1/story.pl @@ -0,0 +1,44 @@ +#!/usr/bin/env perl + +use Expect; + +use strict; + +my $tools_dir = config()->{dir}; + + + +my $exp = Expect->new; + +$exp->spawn("$tools_dir/currency/currency") + or die "Cannot spawn command: bash $tools_dir/currency/currency: $!\n"; + + +$exp->expect(120, + [ + qr/What is the base currency/ => sub { + my $exp = shift; + $exp->send("USD\n"); + exp_continue; + } + ], + [ + qr/What currency to exchange to/ => sub { + my $exp = shift; + $exp->send("RUB\n"); + exp_continue; + } + ], + [ + qr/What is the amount being exchanged/ => sub { + my $exp = shift; + $exp->send("0\n"); + exp_continue; + } + ], + ); + + +$exp->hard_close(); + + diff --git a/bash-snippets-interactive-test/modules/currency/example2/story.check b/bash-snippets-interactive-test/modules/currency/example2/story.check new file mode 100644 index 0000000..d62051f --- /dev/null +++ b/bash-snippets-interactive-test/modules/currency/example2/story.check @@ -0,0 +1,15 @@ +begin: +What is the base currency: USD +What currency to exchange to: RUB +What is the amount being exchanged: 100 +end: + +begin: +========================= +| USD to RUB +regexp: ^\|\s+Rate:\s+\d+\.\d+\s*$ +| USD: 100 +regexp: ^\|\s+RUB:\s+\d+\.\d+\s*$ +========================= +end: + diff --git a/bash-snippets-interactive-test/modules/currency/example2/story.pl b/bash-snippets-interactive-test/modules/currency/example2/story.pl new file mode 100644 index 0000000..e1179d7 --- /dev/null +++ b/bash-snippets-interactive-test/modules/currency/example2/story.pl @@ -0,0 +1,44 @@ +#!/usr/bin/env perl + +use Expect; + +use strict; + +my $tools_dir = config()->{dir}; + + + +my $exp = Expect->new; + +$exp->spawn("$tools_dir/currency/currency") + or die "Cannot spawn command: bash $tools_dir/currency/currency: $!\n"; + + +$exp->expect(120, + [ + qr/What is the base currency/ => sub { + my $exp = shift; + $exp->send("USD\n"); + exp_continue; + } + ], + [ + qr/What currency to exchange to/ => sub { + my $exp = shift; + $exp->send("RUB\n"); + exp_continue; + } + ], + [ + qr/What is the amount being exchanged/ => sub { + my $exp = shift; + $exp->send("100\n"); + exp_continue; + } + ], + ); + + +$exp->hard_close(); + + diff --git a/bash-snippets-interactive-test/report.png b/bash-snippets-interactive-test/report.png new file mode 100644 index 0000000..7eb91b0 Binary files /dev/null and b/bash-snippets-interactive-test/report.png differ diff --git a/bash-snippets-interactive-test/sparrow.json b/bash-snippets-interactive-test/sparrow.json new file mode 100644 index 0000000..9979680 --- /dev/null +++ b/bash-snippets-interactive-test/sparrow.json @@ -0,0 +1,9 @@ +{ + "name" : "bash-snippets-interactive-test", + "description" : "Run tests against BashSnippets tools with interactive prompt", + "version" : "0.0.2", + "url" : "https://github.com/alexanderepstein/Bash-Snippets", + "category": "utilities", + "sparrow_version" : "0.2.48", + "doc" : "README.md" +} diff --git a/bash-snippets-interactive-test/suite.yaml b/bash-snippets-interactive-test/suite.yaml new file mode 100644 index 0000000..7e01964 --- /dev/null +++ b/bash-snippets-interactive-test/suite.yaml @@ -0,0 +1 @@ +dir: "../"