Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
KEINOS opened this issue May 31, 2021 · 2 comments
Closed

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

KEINOS opened this issue May 31, 2021 · 2 comments
Labels
bug Something isn't working

Comments

@KEINOS
Copy link
Member

KEINOS commented May 31, 2021

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

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

  • GNU Bash v5.1.0 (Alpine 3.13), v3.2.57 (macOS Catalina, 10.15) で再現しました。
#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 KEINOS added the bug Something isn't working label May 31, 2021
@KEINOS
Copy link
Member Author

KEINOS commented May 31, 2021

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

This was referenced May 31, 2021
emadurandal pushed a commit to guncys/QiiCipher that referenced this issue Jun 1, 2021
KEINOS pushed a commit that referenced this issue Jun 1, 2021
* Add checkkeylength command
* Add links of checkkeylength's code to README.md
* Fix the md5s function for Mac
  - See #25
* Add the 'checkkeylength' script
@KEINOS
Copy link
Member Author

KEINOS commented Jun 2, 2021

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

@KEINOS KEINOS closed this as completed Jun 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant