TypedDevs / bashunit

A simple testing library for bash scripts. Test your bash scripts in the fastest and simplest way.
https://bashunit.typeddevs.com
MIT License
323 stars 28 forks source link

Can't locate Time/HiRes.pm #318

Closed nawawi closed 1 month ago

nawawi commented 1 month ago
Q A
OS Linux
Shell bash
bashunit version 0.15.0

Summary

bashunit will throw an error when Perl Time::Hires is not available. This requires a minor fix to the clock::now() function.

Current:

function clock::now() {
  if perl --version > /dev/null 2>&1; then
    perl -MTime::HiRes -e 'printf("%.0f\n",Time::HiRes::time()*1000)'
  elif [[ "$_OS" != "OSX" ]]; then
    date +%s%N
  else
    echo ""
  fi
}

Fix:

function clock::now() {
  if perl -MTime::HiRes -e "" > /dev/null 2>&1; then
    perl -MTime::HiRes -e 'printf("%.0f\n",Time::HiRes::time()*1000)'
  elif [[ "$_OS" != "OSX" ]]; then
    date +%s%N
  else
    echo ""
  fi
}

Current behavior

Can't locate Time/HiRes.pm in @INC (you may need to install the Time::HiRes module) (@INC contains: /etc/perl /usr/local/lib/x86_64-linux-gnu/perl/5.30.0 /usr/local/share/perl/5.30.0 /usr/lib/x86_64-linux-gnu/perl5/5.30 /usr/share/perl5 /usr/lib/x86_64-linux-gnu/perl/5.30 /usr/share/perl/5.30 /usr/local/lib/site_perl /usr/lib/x86_64-linux-gnu/perl-base). BEGIN failed--compilation aborted.

How to reproduce

Expected behavior

Chemaclass commented 1 month ago

Hi! Thanks for creating this issue. If you already got a fixing proposal, consider submitting your own PR so we can merge it, and you'll appear as contributor as well 🍻

nawawi commented 1 month ago

Hi! Thanks for creating this issue. If you already got a fixing proposal, consider submitting your own PR so we can merge it, and you'll appear as contributor as well 🍻

Alright then, already submitted. Thanks.

Chemaclass commented 1 month ago

Fix merged, @nawawi! Thanks again! You can get the fix using the beta version (a build using main branch)

curl -s https://bashunit.typeddevs.com/install.sh | bash -s lib beta

docs: https://bashunit.typeddevs.com/installation#define-custom-tag-and-folder