Skip to content

ShellSpec で半角英数字(alphanumeric)をパターンマッチさせたい #54

Answered by yoshi389111
KEINOS asked this question in Q&A
Discussion options

You must be logged in to vote

わかりにくいですが grep を使えばできないわけではないと思います。

もっと良い方法もありそうですが。

#shellcheck shell=sh

sampleFunc() {
    printf "%s" 'abcdef1234567890' # 16 桁のハッシュ
}

isStdoutHex16() {
    # $1: stdout, $2: stderr, $3: status
    echo "$1" | grep -Eq '^[0-9a-f]{16}$'
    # ↑echo で改行コードがあっても大丈夫みたい
}

Describe 'sampleFunc'
    It 'should return the version number of OpenSSH'
        When call sampleFunc

        The result of "isStdoutHex16()" should be successful
        The stdout should not include "\n"
    End
End

Replies: 2 comments 2 replies

Comment options

KEINOS
Jun 10, 2021
Maintainer Author

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
2 replies
@KEINOS
Comment options

KEINOS Jun 11, 2021
Maintainer Author

@KEINOS
Comment options

KEINOS Jun 11, 2021
Maintainer Author

Answer selected by KEINOS
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants