diff --git a/spec/integration/harness/hook.sh b/spec/integration/harness/hook.sh new file mode 100644 index 0000000..5a999b9 --- /dev/null +++ b/spec/integration/harness/hook.sh @@ -0,0 +1,20 @@ +#!/usr/bin/env bash + +source scripts/shArg.sh + +declare MESSAGE + +messageHook() { + local message=$1 + + echo "message hooked invoked with $message" + echo "Global variable is still available $MESSAGE" +} + +# register arguments +shArgs.arg "MESSAGE" -m --message PARAMETER true messageHook + +# parse inputs +shArgs.parse $@ + + diff --git a/spec/integration/harness/list.sh b/spec/integration/harness/list.sh new file mode 100644 index 0000000..4fe0b59 --- /dev/null +++ b/spec/integration/harness/list.sh @@ -0,0 +1,12 @@ +#!/usr/bin/env bash + +source scripts/shArg.sh + +declare IPS +shArgs.arg "IPS" -i --ips PARAMETER true +shArgs.parse $@ + +for ip in $IPS +do + echo "ip: $ip" +done diff --git a/spec/integration/hook_spec.sh b/spec/integration/hook_spec.sh new file mode 100644 index 0000000..2152b3c --- /dev/null +++ b/spec/integration/hook_spec.sh @@ -0,0 +1,11 @@ + Describe 'shArg' + Include spec/integration/harness/runner.sh + + Context "Simple Script Tests" + It 'should parse a csv parameter' + When call run_file "spec/integration/harness/hook.sh" "-m great123" + The output should equal "message hooked invoked with great123 Global variable is still available great123" + End + + End +End \ No newline at end of file diff --git a/spec/integration/list_spec.sh b/spec/integration/list_spec.sh new file mode 100644 index 0000000..2968262 --- /dev/null +++ b/spec/integration/list_spec.sh @@ -0,0 +1,16 @@ + Describe 'shArg' + Include spec/integration/harness/runner.sh + + Context "Simple Script Tests" + It 'should parse a csv parameter' + When call run_file "spec/integration/harness/list.sh" "-i 123,456" + The output should equal "ip: 123 ip: 456" + End + + It 'should parse a space delimited parameter' + When call run_file "spec/integration/harness/list.sh" "-i 888 777" + The output should equal "ip: 888 ip: 777" + End + + End +End \ No newline at end of file