|
| 1 | +#!/usr/bin/env sh |
| 2 | + |
| 3 | +### File: opensearch-contact_spec.sh |
| 4 | +## |
| 5 | +## opensearch の contact テスト。 |
| 6 | +## |
| 7 | +## Usage: |
| 8 | +## |
| 9 | +## ------ Text ------ |
| 10 | +## shellspec opensearch-contact_spec.sh |
| 11 | +## ------------------ |
| 12 | +## |
| 13 | +## Metadata: |
| 14 | +## |
| 15 | +## author - qq542vev <https://purl.org/meta/me/> |
| 16 | +## version - 1.0.0 |
| 17 | +## date - 2022-11-23 |
| 18 | +## since - 2022-11-23 |
| 19 | +## copyright - Copyright (C) 2022 qq542vev. Some rights reserved. |
| 20 | +## license - CC-BY <https://creativecommons.org/licenses/by/4.0/> |
| 21 | +## package - shell-opensearch |
| 22 | +## |
| 23 | +## See Also: |
| 24 | +## |
| 25 | +## * Project homepage - <https://github.com/qq542vev/shell-opensearch> |
| 26 | +## * Bag report - <https://github.com/qq542vev/shell-opensearch/issues> |
| 27 | + |
| 28 | +eval "$(shellspec - -c) exit 1" |
| 29 | + |
| 30 | +Describe 'opensearch contact test' |
| 31 | + email_check() { |
| 32 | + eval "set -- ${1}" |
| 33 | + |
| 34 | + printf '%s' "${email_check}" | awk -- "$( |
| 35 | + cat <<-'__EOF__' |
| 36 | + BEGIN { |
| 37 | + split("", arguments) |
| 38 | +
|
| 39 | + for(i = 1; i < ARGC; i++) { |
| 40 | + arguments[i] = ARGV[i] |
| 41 | + delete ARGV[i] |
| 42 | + } |
| 43 | + } |
| 44 | +
|
| 45 | + !(NR in arguments) || $0 != arguments[NR] { |
| 46 | + exit 1 |
| 47 | + } |
| 48 | + __EOF__ |
| 49 | + )" ${@+"${@}"} |
| 50 | + } |
| 51 | + |
| 52 | + setup() { |
| 53 | + configDir="${PWD}/spec/.shell-opensearch" |
| 54 | + |
| 55 | + } |
| 56 | + |
| 57 | + BeforeAll 'setup' |
| 58 | + |
| 59 | + Example 'Option: -h' |
| 60 | + When call ./opensearch contact -h |
| 61 | + The length of stdout should not eq 0 |
| 62 | + The length of stderr should eq 0 |
| 63 | + The status should eq 0 |
| 64 | + End |
| 65 | + |
| 66 | + Example 'Option: --nil' |
| 67 | + When call ./opensearch contact --nil |
| 68 | + The length of stdout should eq 0 |
| 69 | + The length of stderr should not eq 0 |
| 70 | + The status should eq 64 |
| 71 | + End |
| 72 | + |
| 73 | + Example '2個以上の引数' |
| 74 | + When call ./opensearch contact simple detailed |
| 75 | + The length of stdout should eq 0 |
| 76 | + The length of stderr should not eq 0 |
| 77 | + The status should eq 64 |
| 78 | + End |
| 79 | + |
| 80 | + Describe '基本となるテスト' |
| 81 | + Parameters:block |
| 82 | + 'minimum' '' '1' '65' |
| 83 | + 'simple' "${email}" '' '0' |
| 84 | + 'empty' '' '1' '65' |
| 85 | + 'draft2' '' '1' '65' |
| 86 | + 'nil' '' '1' '65' |
| 87 | + 'success/' "${email} ${email}" '' '0' |
| 88 | + 'failure/' '' '1' '65' |
| 89 | + 'empty/' '' '' '0' |
| 90 | + 'nil/' '' '' '0' |
| 91 | + 'simple,detailed' "${email} ${email}" '' '0' |
| 92 | + 'simple,minimum' '' '1' '65' |
| 93 | + 'simple,nil' '' '1' '65' |
| 94 | + 'draft2,nil' '' '1' '65' |
| 95 | + './spec/.shell-opensearch/simple.xml' "${email}" '' '0' |
| 96 | + './spec/.shell-opensearch/minimul.xml' '' '1' '65' |
| 97 | + './spec/.shell-opensearch/empty.xml' '' '1' '65' |
| 98 | + './spec/.shell-opensearch/nil.xml' '' '1' '65' |
| 99 | + End |
| 100 | + |
| 101 | + Example "オプションなしのテスト: '${1}'" |
| 102 | + When call ./opensearch -c "${configDir}" contact "${1}" |
| 103 | + The lines of stdout should eq "$(eval "set -- ${2}"; printf '%d' "${#}")" |
| 104 | + The stdout should satisfy email_check "${2}" |
| 105 | + The length of stderr should ${3:+'not'} eq 0 |
| 106 | + The status should eq "${4}" |
| 107 | + End |
| 108 | + |
| 109 | + Example "--extarnal のテスト: '${1}'" |
| 110 | + When call env 'MAILER=echo' ./opensearch -c "${configDir}" contact -e "${1}" |
| 111 | + The lines of stdout should eq "$(eval "set -- ${2}"; printf '%d' "$((1 <= ${#}))")" |
| 112 | + The length of stderr should ${3:+'not'} eq 0 |
| 113 | + The status should eq "${4}" |
| 114 | + End |
| 115 | + |
| 116 | + Example "--extarnal のテスト: '${1}'" |
| 117 | + When call ./opensearch -c "${configDir}" contact -e'awk "BEGIN { for(i = 1; i < ARGC; i++) { printf(\"Email: %s\\n\", ARGV[i]) } }"' "${1}" |
| 118 | + The lines of stdout should eq "$(eval "set -- ${2}"; printf '%d' "${#}")" |
| 119 | + The length of stderr should ${3:+'not'} eq 0 |
| 120 | + The status should eq "${4}" |
| 121 | + End |
| 122 | + End |
| 123 | + |
| 124 | + Describe '--skip-error を有効にする' |
| 125 | + |
| 126 | + Parameters:block |
| 127 | + 'success/' "${email} ${email}" '' '0' |
| 128 | + 'failure/' '' '1' '65' |
| 129 | + 'empty/' '' '' '0' |
| 130 | + 'nil/' '' '' '0' |
| 131 | + 'simple,detailed' "${email} ${email}" '' '0' |
| 132 | + 'simple,minimum' "${email}" '1' '65' |
| 133 | + 'simple,nil' "${email}" '1' '65' |
| 134 | + 'draft2,nil' '' '1' '65' |
| 135 | + End |
| 136 | + |
| 137 | + Example "--skip-error のテスト: '${1}'" |
| 138 | + When call ./opensearch -c "${configDir}" contact -s "${1}" |
| 139 | + The lines of stdout should eq "$(eval "set -- ${2}"; printf '%d' "${#}")" |
| 140 | + The stdout should satisfy email_check "${2}" |
| 141 | + The length of stderr should ${3:+'not'} eq 0 |
| 142 | + The status should eq "${4}" |
| 143 | + End |
| 144 | + End |
| 145 | +End |
0 commit comments