Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

- Fix typo "to has been called"
- Add weekly downloads to the docs
- Improve clock performance

## [0.20.0](https://github.com/TypedDevs/bashunit/compare/0.19.1...0.20.0) - 2025-06-01

Expand Down
19 changes: 13 additions & 6 deletions src/clock.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,18 @@ function clock::now() {
shell_time="$(clock::shell_time)"
has_shell_time="$?"
if [[ "$has_shell_time" -eq 0 ]]; then
local seconds microseconds
seconds=$(echo "$shell_time" | cut -f 1 -d '.')
microseconds=$(echo "$shell_time" | cut -f 2 -d '.')
local seconds microseconds
if [[ "$shell_time" == *.* ]]; then
seconds="${shell_time%%.*}"
microseconds="${shell_time#*.}"
microseconds="$(echo "$microseconds" | sed 's/^0*//')"
microseconds="${microseconds:-0}"
else
seconds="$shell_time"
microseconds=0
fi

math::calculate "($seconds * 1000000000) + ($microseconds * 1000)"
echo $((seconds * 1000000000 + microseconds * 1000))
return 0
fi

Expand All @@ -52,7 +59,7 @@ function clock::shell_time() {
function clock::total_runtime_in_milliseconds() {
end_time=$(clock::now)
if [[ -n $end_time ]]; then
math::calculate "($end_time-$_START_TIME)/1000000"
echo $(((end_time - _START_TIME)/1000000))
else
echo ""
fi
Expand All @@ -61,7 +68,7 @@ function clock::total_runtime_in_milliseconds() {
function clock::total_runtime_in_nanoseconds() {
end_time=$(clock::now)
if [[ -n $end_time ]]; then
math::calculate "($end_time-$_START_TIME)"
echo $((end_time - _START_TIME))
else
echo ""
fi
Expand Down
4 changes: 2 additions & 2 deletions src/env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,10 @@ function env::active_internet_connection() {
function env::find_terminal_width() {
local cols=""

if [[ -z "$cols" ]] && command -v stty > /dev/null; then
if command -v tput > /dev/null; then
cols=$(tput cols 2>/dev/null)
fi
if [[ -n "$TERM" ]] && command -v tput > /dev/null; then
if [[ -z "$cols" ]] && command -v stty > /dev/null; then
cols=$(stty size 2>/dev/null | cut -d' ' -f2)
fi

Expand Down
18 changes: 12 additions & 6 deletions tests/unit/directory_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ function test_unsuccessful_assert_is_directory_readable_when_a_file_is_given() {
}

function test_unsuccessful_assert_is_directory_readable_without_execution_permission() {
if [[ "$_OS" == "Windows" || $_DISTRO = "Alpine" ]]; then
if [[ "$_OS" == "Windows" || $_DISTRO = "Alpine" || $(id -u) -eq 0 ]]; then
skip "permission checks unreliable as root"
return
fi

Expand All @@ -126,7 +127,8 @@ function test_unsuccessful_assert_is_directory_readable_without_execution_permis
}

function test_unsuccessful_assert_is_directory_readable_without_read_permission() {
if [[ "$_OS" == "Windows" || $_DISTRO = "Alpine" ]]; then
if [[ "$_OS" == "Windows" || $_DISTRO = "Alpine" || $(id -u) -eq 0 ]]; then
skip "permission checks unreliable as root"
return
fi

Expand All @@ -141,7 +143,8 @@ function test_unsuccessful_assert_is_directory_readable_without_read_permission(
}

function test_successful_assert_is_directory_not_readable_without_read_permission() {
if [[ "$_OS" == "Windows" || $_DISTRO = "Alpine" ]]; then
if [[ "$_OS" == "Windows" || $_DISTRO = "Alpine" || $(id -u) -eq 0 ]]; then
skip "permission checks unreliable as root"
return
fi

Expand All @@ -152,7 +155,8 @@ function test_successful_assert_is_directory_not_readable_without_read_permissio
}

function test_successful_assert_is_directory_not_readable_without_execution_permission() {
if [[ "$_OS" == "Windows" || $_DISTRO = "Alpine" ]]; then
if [[ "$_OS" == "Windows" || $_DISTRO = "Alpine" || $(id -u) -eq 0 ]]; then
skip "permission checks unreliable as root"
return
fi

Expand All @@ -178,7 +182,8 @@ function test_successful_assert_is_directory_writable() {
}

function test_unsuccessful_assert_is_directory_writable() {
if [[ "$_OS" == "Windows" || $_DISTRO = "Alpine" ]]; then
if [[ "$_OS" == "Windows" || $_DISTRO = "Alpine" || $(id -u) -eq 0 ]]; then
skip "permission checks unreliable as root"
return
fi

Expand All @@ -202,7 +207,8 @@ function test_unsuccessful_assert_is_directory_writable_when_a_file_is_given() {
}

function test_successful_assert_is_directory_not_writable() {
if [[ "$_OS" == "Windows" || $_DISTRO = "Alpine" ]]; then
if [[ "$_OS" == "Windows" || $_DISTRO = "Alpine" || $(id -u) -eq 0 ]]; then
skip "permission checks unreliable as root"
return
fi

Expand Down
Loading