Skip to content
Merged
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
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
- Fix echo does not break test execution results
- Add bashunit facade to enable custom assertions
- Document how to verify the `sha256sum` of the final executable
- Enable display execution time on MacOS with `SHOW_EXECUTION_TIME`
- Enable display execution time on macOS with `SHOW_EXECUTION_TIME`
- Support for displaying the clock without `perl` (for non-macOS)
- Add `-l|--log-junit <log.xml>` option
- Add `-r|--report-html <report.html>` option

Expand Down
15 changes: 13 additions & 2 deletions src/clock.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
#!/bin/bash

function clock::now() {
perl -MTime::HiRes -e 'printf("%.0f\n",Time::HiRes::time()*1000)'
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
}

_START_TIME=$(clock::now)

function clock::runtime_in_milliseconds() {
echo $(( $(clock::now) - _START_TIME ))
end_time=$(clock::now)
if [[ -n $end_time ]]; then
echo $(( end_time - _START_TIME ))
else
echo ""
fi
}
56 changes: 56 additions & 0 deletions tests/unit/clock_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/bin/bash

__ORIGINAL_OS=""

function set_up_before_script() {
__ORIGINAL_OS=$_OS
}

function tear_down_after_script() {
export _OS=$__ORIGINAL_OS
}

function mock_non_existing_fn() {
return 127;
}

function test_now_with_perl() {
mock perl echo "1720705883457"

assert_equals "1720705883457" "$(clock::now)"
}

function test_now_on_linux_without_perl() {
export _OS="Linux"
mock perl mock_non_existing_fn
mock date echo "1720705883457"

assert_equals "1720705883457" "$(clock::now)"
}
function test_now_on_windows_without_perl() {
export _OS="Windows"
mock perl mock_non_existing_fn
mock date echo "1720705883457"

assert_equals "1720705883457" "$(clock::now)"
}

function test_now_on_osx_without_perl() {
export _OS="OSX"
mock perl mock_non_existing_fn

assert_equals "" "$(clock::now)"
}

function test_runtime_in_milliseconds_when_not_empty_time() {
mock perl echo "1720705883457"

assert_not_empty "$(clock::runtime_in_milliseconds)"
}

function test_runtime_in_milliseconds_when_empty_time() {
export _OS="OSX"
mock perl mock_non_existing_fn

assert_empty "$(clock::runtime_in_milliseconds)"
}
10 changes: 0 additions & 10 deletions tests/unit/console_results_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -266,11 +266,6 @@ function test_total_asserts_is_the_sum_of_passed_skipped_incomplete_snapshot_and
}

function test_render_execution_time() {
if [[ $_OS == "OSX" ]]; then
skip "Skipping in OSX"
return
fi

local render_result
render_result=$(
# shellcheck disable=SC2034
Expand All @@ -282,11 +277,6 @@ function test_render_execution_time() {
}

function test_not_render_execution_time() {
if [[ $_OS == "OSX" ]]; then
skip "Skipping in OSX"
return
fi

local render_result
render_result=$(
# shellcheck disable=SC2034
Expand Down