Skip to content

Per-test rpad and per-file clock reads still go through $( ) instead of a return slot #1348

Description

@Chemaclass

Summary

Two spots still capture a return value through $( ) where the house return-slot pattern already exists next door.

Current behavior

Per passing test. src/console/test_line.sh:33-37:

full_line="$(bashunit::str::rpad "$line" "$_BASHUNIT_CONSOLE_DURATION_OUT")"

bashunit::str::rpad (src/util/str.sh:92) is already fork-free inside. The subshell around it is the whole cost. Its neighbours already have slot variants: strip_ansi_to_slot (src/util/str.sh:23) and format_duration_to_slot (src/console/duration.sh:11).

This one fires on Bash 5, not on 3.2, because auto disables per-test timing when the clock is a perl fork (src/config/env.sh:524-529, src/util/clock.sh:95).

The failure renderers have the same shape at src/console/test_line.sh:71, :123, :192, :207, :223 and :256, on the failure path only.

Per file with a file hook. src/runner/hooks.sh:172, :189, :423, :440:

local start_time
start_time=$(bashunit::clock::now)

bashunit::clock::now_to_slot (src/util/clock.sh:111) is the fork-free variant, and run_test was already converted to it (src/runner/exec.sh:542, :599). These four were missed. On Bash 3.2 each one is a subshell wrapping a perl fork, twice per set_up_before_script and twice per tear_down_after_script. This suite has 115 files with the former.

bashunit::clock::init (src/util/clock.sh:234) captures $(bashunit::clock::now) the same way, once per run.

Expected behavior

Add bashunit::str::rpad_to_slot and use it. Switch the four hook clock reads and clock::init to now_to_slot.

Small next to #1 and #2, and grouped here because it is the same one-line change four times over. Unit-test rpad_to_slot against rpad on the same inputs, including an ANSI-coloured string and one over 1024 chars, since that is where strip_ansi_to_slot changes strategy (src/util/str.sh:82).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

  • Status
    Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions