Qithub-BOT / QiiCipher

✅ GitHub の SSH 公開鍵でファイルを暗号化およびローカルの秘密鍵で復号・署名・検証するスクリプトのリポジトリです。
https://qiita.com/KEINOS/items/2abce1e5b15d799ac6d7
Creative Commons Attribution Share Alike 4.0 International
4 stars 3 forks source link

Alpine/macOS で md5s が動かない #25

Closed KEINOS closed 3 years ago

KEINOS commented 3 years ago

PR #5 の md5sum/md5 のラッパー関数が空の値を返します。

if [ -e md5sum ] でコマンドの検知に失敗しているようです。

#shellcheck shell=bash
# This file: tests/md5s_test.sh

# md5s は md5sum/md5 のラッパー関数です.
md5s() {
    if [ -e md5sum ]; then
        echo "$1" | md5sum
    elif [ -e md5 ]; then
        md5 -q -s "$1"
    fi
}

# md5s のユニットテスト
Describe 'md5s'
    It 'should return MD5 hash of the arg 1'
        When call md5s 'hoge'

        The output should equal 'c59548c3c576228486a1f0037eb16a1b'
        The status should be success
    End
End
$ # 期待するハッシュ値の確認
$ echo 'hoge' | md5sum | awk '{ print $1 }'
c59548c3c576228486a1f0037eb16a1b
$ # テスト実行と結果
$ shellspec --shell '/bin/bash' ./tests/md5s_test.sh
Running: /bin/bash [bash 5.1.0(1)-release]
F

Examples:
  1) md5s should return MD5 hash of the arg 1
     When call md5s hoge

     1.1) The output should equal c59548c3c576228486a1f0037eb16a1b

            expected: "c59548c3c576228486a1f0037eb16a1b"
                 got: ""

          # tests/md5s_test.sh:16

Finished in 0.34 seconds (user 0.17 seconds, sys 0.06 seconds)
1 example, 1 failure

Failure examples / Errors: (Listed here affect your suite's status)

shellspec tests/md5s_test.sh:13 # 1) md5s should return MD5 hash of the arg 1 FAILED
KEINOS commented 3 years ago

which でコマンドのパスを返したら動きました。

#shellcheck shell=bash

# md5s は md5sum/md5 のラッパー関数です.
md5s() {
-   if [ -e md5sum ]; then
-       echo "$1" | md5sum
-   elif [ -e md5 ]; then
+   if [ -e "$(which md5sum)" ]; then
+       echo "$1" | md5sum | awk '{ print $1 }'
+   elif [ -e "$(which md5)" ]; then
        md5 -q -s "$1"
    fi
}

Describe 'md5s'
    It 'should return MD5 hash of the arg 1'
        When call md5s 'hoge'

        The output should equal 'c59548c3c576228486a1f0037eb16a1b'
        The status should be success
    End
End
$ shellspec --shell '/bin/bash' ./tests/md5s_test.sh
Running: /bin/bash [bash 5.1.0(1)-release]
.

Finished in 0.48 seconds (user 0.21 seconds, sys 0.08 seconds)
1 example, 0 failures
KEINOS commented 3 years ago

PR #25 で修正されているので Close します。何かあったら、再オープンよろです。