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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line numberDiff line numberDiff line change
Expand Up@@ -16,6 +16,7 @@
- `--jobs auto` / `-j auto` caps parallel concurrency at the CPU core count (portable across Linux/macOS/BSD); the default stays unlimited (#766)

### Changed
- Multi-file runs are no longer quadratic in file count: each file's test functions are unset once the file has been processed, so test subshells stop forking an ever-growing shell. bashunit's own 63-file unit suite: ~64s -> ~22s sequential, ~26s -> ~7s parallel (#829)
- Major performance work with no behaviour change: assertions, per-test execution, per-file discovery, cold start and parallel result publishing are now (near) fork-free, snapshots and `--tag` scans are cached, and quadratic failure rendering is single-pass. Benchmarks on bash 3.2: 100x10 `assert_equals` ~1.50s -> ~0.76s, 500 snapshot assertions ~7.5s -> ~3.0s, 100 tagged tests ~2.92s -> ~0.68s, and bashunit's own acceptance suite ~61s -> ~17s (#761-#764, #772-#775, #798, #801-#807, #809, #810, #813, #817)
- Per-test timing now defaults to `auto` (`BASHUNIT_SHOW_EXECUTION_TIME=true|false|auto`): shown only when the clock is fork-free, avoiding `perl` forks on bash 3.2; `--profile`/`--verbose`/reports still measure (see `adrs/adr-008-auto-skip-per-test-timing.md`) (#765)
- `assert_equals`/`assert_same` failures with multiline values now render a git word-diff below the header (requires git, opt out with `BASHUNIT_NO_DIFF=true`, respects `--no-color`); machine reports keep the raw values (#777)
Expand Down
23 changes: 23 additions & 0 deletions src/runner.sh
Original file line numberDiff line numberDiff line change
Expand Up@@ -430,6 +430,9 @@ function bashunit::runner::load_test_files() {
filtered_functions=$(bashunit::helper::get_functions_to_run "test" "$filter" "$_BASHUNIT_CACHED_ALL_FUNCTIONS")
local functions_for_script
functions_for_script=$(bashunit::runner::functions_for_script "$test_file" "$filtered_functions")
# Full pre-tag/rerun list: these are unset once the file has been
# processed, whatever subset actually runs (#829).
local _script_fns_to_clean="$functions_for_script"
# Apply tag filtering to the early check as well
if [ -n "$tag_filter" ] || [ -n "$exclude_tag_filter" ]; then
bashunit::helper::build_tags_map "$test_file"
Expand All@@ -448,6 +451,7 @@ function bashunit::runner::load_test_files() {
functions_for_script=$(bashunit::rerun::filter_functions "$test_file" "$functions_for_script")
fi
if [ -z "$functions_for_script" ]; then
bashunit::runner::clean_script_test_functions "$_script_fns_to_clean"
bashunit::runner::clean_set_up_and_tear_down_after_script
bashunit::runner::restore_workdir
continue
Expand DownExpand Up@@ -492,6 +496,7 @@ function bashunit::runner::load_test_files() {
"$exclude_tag_filter" "$_cached_fns"
fi
bashunit::runner::run_tear_down_after_script "$test_file"
bashunit::runner::clean_script_test_functions "$_script_fns_to_clean"
bashunit::runner::clean_set_up_and_tear_down_after_script
if ! bashunit::parallel::is_enabled; then
bashunit::cleanup_script_temp_files
Expand DownExpand Up@@ -2066,6 +2071,24 @@ function bashunit::runner::run_tear_down_after_script() {
return $status
}

##
# Unset a file's test functions once the file has been processed.
#
# Test files are sourced into the main shell, and their functions used to stay
# defined for the whole run: every test's $() subshell then forked an
# ever-growing shell, making multi-file runs quadratic in file count (#829).
# In parallel mode the file's workers have already forked (with their own copy
# of the functions) by the time this runs, so unsetting here is race-free.
# Arguments: $1 - whitespace-separated test function names
##
function bashunit::runner::clean_script_test_functions() {
local IFS=$' \t\n'
local fn
for fn in $1; do
unset -f "$fn" 2>/dev/null || true
done
}

function bashunit::runner::clean_set_up_and_tear_down_after_script() {
bashunit::internal_log "clean_set_up_and_tear_down_after_script"
bashunit::helper::unset_if_exists 'set_up'
Expand Down
31 changes: 31 additions & 0 deletions tests/acceptance/bashunit_fn_cleanup_test.sh
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
#!/usr/bin/env bash
set -euo pipefail

# Regression test for https://github.com/TypedDevs/bashunit/issues/829
# Test functions must be unset once their file has been processed: they stay
# defined in the main shell otherwise, and every test's $() subshell forks an
# ever-fatter process, making multi-file runs quadratic in file count.

function set_up_before_script() {
TEST_ENV_FILE="tests/acceptance/fixtures/.env.default"
}

function test_test_functions_are_unset_after_their_file_ran() {
local first_file=./tests/acceptance/fixtures/test_fn_cleanup_first.sh
local second_file=./tests/acceptance/fixtures/test_fn_cleanup_second.sh

local actual
actual="$(./bashunit --no-parallel --env "$TEST_ENV_FILE" "$first_file" "$second_file" | strip_ansi)"

assert_contains "2 passed, 2 total" "$actual"
}

function test_test_functions_are_unset_after_their_file_ran_in_parallel() {
local first_file=./tests/acceptance/fixtures/test_fn_cleanup_first.sh
local second_file=./tests/acceptance/fixtures/test_fn_cleanup_second.sh

local actual
actual="$(./bashunit --parallel --env "$TEST_ENV_FILE" "$first_file" "$second_file" | strip_ansi)"

assert_contains "2 passed, 2 total" "$actual"
}
10 changes: 10 additions & 0 deletions tests/acceptance/fixtures/test_fn_cleanup_first.sh
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env bash
set -euo pipefail

# Regression fixture for https://github.com/TypedDevs/bashunit/issues/829
# First file: defines a marker test function that must not leak into the
# main shell once this file has been processed.

function test_fn_cleanup_marker_from_first_file() {
assert_equals "first" "first"
}
14 changes: 14 additions & 0 deletions tests/acceptance/fixtures/test_fn_cleanup_second.sh
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env bash
set -euo pipefail

# Regression fixture for https://github.com/TypedDevs/bashunit/issues/829
# Second file: the first file's test functions must already be unset, so the
# main shell does not grow (and slow down every fork) as files accumulate.

function test_previous_file_test_functions_are_unset() {
local defined="no"
if declare -F test_fn_cleanup_marker_from_first_file >/dev/null 2>&1; then
defined="yes"
fi
assert_equals "no" "$defined"
}
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { // Add copy buttons to all
 blocks
(function() {
function addCopyButtons() {
document.querySelectorAll('pre code').forEach(function(codeBlock) {
if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;
codeBlock.parentElement.setAttribute('data-copy-added', 'true');
var btn = document.createElement('button');
btn.textContent = 'Copy';
btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';
btn.onmouseover = function() { this.style.opacity = '1'; };
btn.onmouseout = function() { this.style.opacity = '0.7'; };
btn.onclick = function() {
navigator.clipboard.writeText(codeBlock.textContent).then(function() {
btn.textContent = 'Copied!';
setTimeout(function() { btn.textContent = 'Copy'; }, 1500);
});
};
codeBlock.parentElement.style.position = 'relative';
codeBlock.parentElement.appendChild(btn);
});
}
addCopyButtons();
// Re-run on dynamic content
var observer = new MutationObserver(addCopyButtons);
observer.observe(document.body, { childList: true, subtree: true });
})();
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line numberDiff line numberDiff line change
Expand Up@@ -16,6 +16,7 @@
- `--jobs auto` / `-j auto` caps parallel concurrency at the CPU core count (portable across Linux/macOS/BSD); the default stays unlimited (#766)

### Changed
- Multi-file runs are no longer quadratic in file count: each file's test functions are unset once the file has been processed, so test subshells stop forking an ever-growing shell. bashunit's own 63-file unit suite: ~64s -> ~22s sequential, ~26s -> ~7s parallel (#829)
- Major performance work with no behaviour change: assertions, per-test execution, per-file discovery, cold start and parallel result publishing are now (near) fork-free, snapshots and `--tag` scans are cached, and quadratic failure rendering is single-pass. Benchmarks on bash 3.2: 100x10 `assert_equals` ~1.50s -> ~0.76s, 500 snapshot assertions ~7.5s -> ~3.0s, 100 tagged tests ~2.92s -> ~0.68s, and bashunit's own acceptance suite ~61s -> ~17s (#761-#764, #772-#775, #798, #801-#807, #809, #810, #813, #817)
- Per-test timing now defaults to `auto` (`BASHUNIT_SHOW_EXECUTION_TIME=true|false|auto`): shown only when the clock is fork-free, avoiding `perl` forks on bash 3.2; `--profile`/`--verbose`/reports still measure (see `adrs/adr-008-auto-skip-per-test-timing.md`) (#765)
- `assert_equals`/`assert_same` failures with multiline values now render a git word-diff below the header (requires git, opt out with `BASHUNIT_NO_DIFF=true`, respects `--no-color`); machine reports keep the raw values (#777)
Expand Down
23 changes: 23 additions & 0 deletions src/runner.sh
Original file line numberDiff line numberDiff line change
Expand Up@@ -430,6 +430,9 @@ function bashunit::runner::load_test_files() {
filtered_functions=$(bashunit::helper::get_functions_to_run "test" "$filter" "$_BASHUNIT_CACHED_ALL_FUNCTIONS")
local functions_for_script
functions_for_script=$(bashunit::runner::functions_for_script "$test_file" "$filtered_functions")
# Full pre-tag/rerun list: these are unset once the file has been
# processed, whatever subset actually runs (#829).
local _script_fns_to_clean="$functions_for_script"
# Apply tag filtering to the early check as well
if [ -n "$tag_filter" ] || [ -n "$exclude_tag_filter" ]; then
bashunit::helper::build_tags_map "$test_file"
Expand All@@ -448,6 +451,7 @@ function bashunit::runner::load_test_files() {
functions_for_script=$(bashunit::rerun::filter_functions "$test_file" "$functions_for_script")
fi
if [ -z "$functions_for_script" ]; then
bashunit::runner::clean_script_test_functions "$_script_fns_to_clean"
bashunit::runner::clean_set_up_and_tear_down_after_script
bashunit::runner::restore_workdir
continue
Expand DownExpand Up@@ -492,6 +496,7 @@ function bashunit::runner::load_test_files() {
"$exclude_tag_filter" "$_cached_fns"
fi
bashunit::runner::run_tear_down_after_script "$test_file"
bashunit::runner::clean_script_test_functions "$_script_fns_to_clean"
bashunit::runner::clean_set_up_and_tear_down_after_script
if ! bashunit::parallel::is_enabled; then
bashunit::cleanup_script_temp_files
Expand DownExpand Up@@ -2066,6 +2071,24 @@ function bashunit::runner::run_tear_down_after_script() {
return $status
}

##
# Unset a file's test functions once the file has been processed.
#
# Test files are sourced into the main shell, and their functions used to stay
# defined for the whole run: every test's $() subshell then forked an
# ever-growing shell, making multi-file runs quadratic in file count (#829).
# In parallel mode the file's workers have already forked (with their own copy
# of the functions) by the time this runs, so unsetting here is race-free.
# Arguments: $1 - whitespace-separated test function names
##
function bashunit::runner::clean_script_test_functions() {
local IFS=$' \t\n'
local fn
for fn in $1; do
unset -f "$fn" 2>/dev/null || true
done
}

function bashunit::runner::clean_set_up_and_tear_down_after_script() {
bashunit::internal_log "clean_set_up_and_tear_down_after_script"
bashunit::helper::unset_if_exists 'set_up'
Expand Down
31 changes: 31 additions & 0 deletions tests/acceptance/bashunit_fn_cleanup_test.sh
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
#!/usr/bin/env bash
set -euo pipefail

# Regression test for https://github.com/TypedDevs/bashunit/issues/829
# Test functions must be unset once their file has been processed: they stay
# defined in the main shell otherwise, and every test's $() subshell forks an
# ever-fatter process, making multi-file runs quadratic in file count.

function set_up_before_script() {
TEST_ENV_FILE="tests/acceptance/fixtures/.env.default"
}

function test_test_functions_are_unset_after_their_file_ran() {
local first_file=./tests/acceptance/fixtures/test_fn_cleanup_first.sh
local second_file=./tests/acceptance/fixtures/test_fn_cleanup_second.sh

local actual
actual="$(./bashunit --no-parallel --env "$TEST_ENV_FILE" "$first_file" "$second_file" | strip_ansi)"

assert_contains "2 passed, 2 total" "$actual"
}

function test_test_functions_are_unset_after_their_file_ran_in_parallel() {
local first_file=./tests/acceptance/fixtures/test_fn_cleanup_first.sh
local second_file=./tests/acceptance/fixtures/test_fn_cleanup_second.sh

local actual
actual="$(./bashunit --parallel --env "$TEST_ENV_FILE" "$first_file" "$second_file" | strip_ansi)"

assert_contains "2 passed, 2 total" "$actual"
}
10 changes: 10 additions & 0 deletions tests/acceptance/fixtures/test_fn_cleanup_first.sh
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env bash
set -euo pipefail

# Regression fixture for https://github.com/TypedDevs/bashunit/issues/829
# First file: defines a marker test function that must not leak into the
# main shell once this file has been processed.

function test_fn_cleanup_marker_from_first_file() {
assert_equals "first" "first"
}
14 changes: 14 additions & 0 deletions tests/acceptance/fixtures/test_fn_cleanup_second.sh
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env bash
set -euo pipefail

# Regression fixture for https://github.com/TypedDevs/bashunit/issues/829
# Second file: the first file's test functions must already be unset, so the
# main shell does not grow (and slow down every fork) as files accumulate.

function test_previous_file_test_functions_are_unset() {
local defined="no"
if declare -F test_fn_cleanup_marker_from_first_file >/dev/null 2>&1; then
defined="yes"
fi
assert_equals "no" "$defined"
}
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { // Force GitHub README to respect dark mode (function() { var style = document.createElement('style'); style.textContent = ' .markdown-body { color-scheme: dark light; } .markdown-body pre { background: #161b22 !important; } .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; } .markdown-body table th, .markdown-body table td { border-color: #30363d !important; } .markdown-body img { background: #0d1117; } .markdown-body blockquote { border-left-color: #8b949e; } .markdown-body hr { border-color: #30363d; } '; document.head.appendChild(style); })(); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line numberDiff line numberDiff line change
Expand Up@@ -16,6 +16,7 @@
- `--jobs auto` / `-j auto` caps parallel concurrency at the CPU core count (portable across Linux/macOS/BSD); the default stays unlimited (#766)

### Changed
- Multi-file runs are no longer quadratic in file count: each file's test functions are unset once the file has been processed, so test subshells stop forking an ever-growing shell. bashunit's own 63-file unit suite: ~64s -> ~22s sequential, ~26s -> ~7s parallel (#829)
- Major performance work with no behaviour change: assertions, per-test execution, per-file discovery, cold start and parallel result publishing are now (near) fork-free, snapshots and `--tag` scans are cached, and quadratic failure rendering is single-pass. Benchmarks on bash 3.2: 100x10 `assert_equals` ~1.50s -> ~0.76s, 500 snapshot assertions ~7.5s -> ~3.0s, 100 tagged tests ~2.92s -> ~0.68s, and bashunit's own acceptance suite ~61s -> ~17s (#761-#764, #772-#775, #798, #801-#807, #809, #810, #813, #817)
- Per-test timing now defaults to `auto` (`BASHUNIT_SHOW_EXECUTION_TIME=true|false|auto`): shown only when the clock is fork-free, avoiding `perl` forks on bash 3.2; `--profile`/`--verbose`/reports still measure (see `adrs/adr-008-auto-skip-per-test-timing.md`) (#765)
- `assert_equals`/`assert_same` failures with multiline values now render a git word-diff below the header (requires git, opt out with `BASHUNIT_NO_DIFF=true`, respects `--no-color`); machine reports keep the raw values (#777)
Expand Down
23 changes: 23 additions & 0 deletions src/runner.sh
Original file line numberDiff line numberDiff line change
Expand Up@@ -430,6 +430,9 @@ function bashunit::runner::load_test_files() {
filtered_functions=$(bashunit::helper::get_functions_to_run "test" "$filter" "$_BASHUNIT_CACHED_ALL_FUNCTIONS")
local functions_for_script
functions_for_script=$(bashunit::runner::functions_for_script "$test_file" "$filtered_functions")
# Full pre-tag/rerun list: these are unset once the file has been
# processed, whatever subset actually runs (#829).
local _script_fns_to_clean="$functions_for_script"
# Apply tag filtering to the early check as well
if [ -n "$tag_filter" ] || [ -n "$exclude_tag_filter" ]; then
bashunit::helper::build_tags_map "$test_file"
Expand All@@ -448,6 +451,7 @@ function bashunit::runner::load_test_files() {
functions_for_script=$(bashunit::rerun::filter_functions "$test_file" "$functions_for_script")
fi
if [ -z "$functions_for_script" ]; then
bashunit::runner::clean_script_test_functions "$_script_fns_to_clean"
bashunit::runner::clean_set_up_and_tear_down_after_script
bashunit::runner::restore_workdir
continue
Expand DownExpand Up@@ -492,6 +496,7 @@ function bashunit::runner::load_test_files() {
"$exclude_tag_filter" "$_cached_fns"
fi
bashunit::runner::run_tear_down_after_script "$test_file"
bashunit::runner::clean_script_test_functions "$_script_fns_to_clean"
bashunit::runner::clean_set_up_and_tear_down_after_script
if ! bashunit::parallel::is_enabled; then
bashunit::cleanup_script_temp_files
Expand DownExpand Up@@ -2066,6 +2071,24 @@ function bashunit::runner::run_tear_down_after_script() {
return $status
}

##
# Unset a file's test functions once the file has been processed.
#
# Test files are sourced into the main shell, and their functions used to stay
# defined for the whole run: every test's $() subshell then forked an
# ever-growing shell, making multi-file runs quadratic in file count (#829).
# In parallel mode the file's workers have already forked (with their own copy
# of the functions) by the time this runs, so unsetting here is race-free.
# Arguments: $1 - whitespace-separated test function names
##
function bashunit::runner::clean_script_test_functions() {
local IFS=$' \t\n'
local fn
for fn in $1; do
unset -f "$fn" 2>/dev/null || true
done
}

function bashunit::runner::clean_set_up_and_tear_down_after_script() {
bashunit::internal_log "clean_set_up_and_tear_down_after_script"
bashunit::helper::unset_if_exists 'set_up'
Expand Down
31 changes: 31 additions & 0 deletions tests/acceptance/bashunit_fn_cleanup_test.sh
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
#!/usr/bin/env bash
set -euo pipefail

# Regression test for https://github.com/TypedDevs/bashunit/issues/829
# Test functions must be unset once their file has been processed: they stay
# defined in the main shell otherwise, and every test's $() subshell forks an
# ever-fatter process, making multi-file runs quadratic in file count.

function set_up_before_script() {
TEST_ENV_FILE="tests/acceptance/fixtures/.env.default"
}

function test_test_functions_are_unset_after_their_file_ran() {
local first_file=./tests/acceptance/fixtures/test_fn_cleanup_first.sh
local second_file=./tests/acceptance/fixtures/test_fn_cleanup_second.sh

local actual
actual="$(./bashunit --no-parallel --env "$TEST_ENV_FILE" "$first_file" "$second_file" | strip_ansi)"

assert_contains "2 passed, 2 total" "$actual"
}

function test_test_functions_are_unset_after_their_file_ran_in_parallel() {
local first_file=./tests/acceptance/fixtures/test_fn_cleanup_first.sh
local second_file=./tests/acceptance/fixtures/test_fn_cleanup_second.sh

local actual
actual="$(./bashunit --parallel --env "$TEST_ENV_FILE" "$first_file" "$second_file" | strip_ansi)"

assert_contains "2 passed, 2 total" "$actual"
}
10 changes: 10 additions & 0 deletions tests/acceptance/fixtures/test_fn_cleanup_first.sh
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env bash
set -euo pipefail

# Regression fixture for https://github.com/TypedDevs/bashunit/issues/829
# First file: defines a marker test function that must not leak into the
# main shell once this file has been processed.

function test_fn_cleanup_marker_from_first_file() {
assert_equals "first" "first"
}
14 changes: 14 additions & 0 deletions tests/acceptance/fixtures/test_fn_cleanup_second.sh
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env bash
set -euo pipefail

# Regression fixture for https://github.com/TypedDevs/bashunit/issues/829
# Second file: the first file's test functions must already be unset, so the
# main shell does not grow (and slow down every fork) as files accumulate.

function test_previous_file_test_functions_are_unset() {
local defined="no"
if declare -F test_fn_cleanup_marker_from_first_file >/dev/null 2>&1; then
defined="yes"
fi
assert_equals "no" "$defined"
}
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { // Highlight search terms from Google/DuckDuckGo/Bing referrer (function() { var ref = document.referrer; var terms = []; if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) { var url = new URL(ref); var q = url.searchParams.get('q') || url.searchParams.get('p'); if (q) { terms = q.split(/\s+/).filter(function(t) { return t.length > 2; }); } } if (terms.length === 0) return; var style = document.createElement('style'); style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }'; document.head.appendChild(style); function highlight(node) { if (node.nodeType === 3) { // text node var text = node.textContent; var found = false; terms.forEach(function(term) { var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\]\\]/g, '\\') + ')', 'gi'); if (regex.test(text)) { found = true; var frag = document.createDocumentFragment(); var parts = text.split(regex); parts.forEach(function(part, i) { if (i % 2 === 0) { frag.appendChild(document.createTextNode(part)); } else { var span = document.createElement('span'); span.className = 'userscript-highlight'; span.textContent = part; frag.appendChild(span); } }); node.parentNode.replaceChild(frag, node); } }); } else if (node.nodeType === 1 && node.childNodes) { // element var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT']; if (!skipTags.includes(node.tagName)) { Array.from(node.childNodes).forEach(highlight); } } } highlight(document.body); // Re-highlight on dynamic content var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1 || node.nodeType === 3) highlight(node); }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line numberDiff line numberDiff line change
Expand Up@@ -16,6 +16,7 @@
- `--jobs auto` / `-j auto` caps parallel concurrency at the CPU core count (portable across Linux/macOS/BSD); the default stays unlimited (#766)

### Changed
- Multi-file runs are no longer quadratic in file count: each file's test functions are unset once the file has been processed, so test subshells stop forking an ever-growing shell. bashunit's own 63-file unit suite: ~64s -> ~22s sequential, ~26s -> ~7s parallel (#829)
- Major performance work with no behaviour change: assertions, per-test execution, per-file discovery, cold start and parallel result publishing are now (near) fork-free, snapshots and `--tag` scans are cached, and quadratic failure rendering is single-pass. Benchmarks on bash 3.2: 100x10 `assert_equals` ~1.50s -> ~0.76s, 500 snapshot assertions ~7.5s -> ~3.0s, 100 tagged tests ~2.92s -> ~0.68s, and bashunit's own acceptance suite ~61s -> ~17s (#761-#764, #772-#775, #798, #801-#807, #809, #810, #813, #817)
- Per-test timing now defaults to `auto` (`BASHUNIT_SHOW_EXECUTION_TIME=true|false|auto`): shown only when the clock is fork-free, avoiding `perl` forks on bash 3.2; `--profile`/`--verbose`/reports still measure (see `adrs/adr-008-auto-skip-per-test-timing.md`) (#765)
- `assert_equals`/`assert_same` failures with multiline values now render a git word-diff below the header (requires git, opt out with `BASHUNIT_NO_DIFF=true`, respects `--no-color`); machine reports keep the raw values (#777)
Expand Down
23 changes: 23 additions & 0 deletions src/runner.sh
Original file line numberDiff line numberDiff line change
Expand Up@@ -430,6 +430,9 @@ function bashunit::runner::load_test_files() {
filtered_functions=$(bashunit::helper::get_functions_to_run "test" "$filter" "$_BASHUNIT_CACHED_ALL_FUNCTIONS")
local functions_for_script
functions_for_script=$(bashunit::runner::functions_for_script "$test_file" "$filtered_functions")
# Full pre-tag/rerun list: these are unset once the file has been
# processed, whatever subset actually runs (#829).
local _script_fns_to_clean="$functions_for_script"
# Apply tag filtering to the early check as well
if [ -n "$tag_filter" ] || [ -n "$exclude_tag_filter" ]; then
bashunit::helper::build_tags_map "$test_file"
Expand All@@ -448,6 +451,7 @@ function bashunit::runner::load_test_files() {
functions_for_script=$(bashunit::rerun::filter_functions "$test_file" "$functions_for_script")
fi
if [ -z "$functions_for_script" ]; then
bashunit::runner::clean_script_test_functions "$_script_fns_to_clean"
bashunit::runner::clean_set_up_and_tear_down_after_script
bashunit::runner::restore_workdir
continue
Expand DownExpand Up@@ -492,6 +496,7 @@ function bashunit::runner::load_test_files() {
"$exclude_tag_filter" "$_cached_fns"
fi
bashunit::runner::run_tear_down_after_script "$test_file"
bashunit::runner::clean_script_test_functions "$_script_fns_to_clean"
bashunit::runner::clean_set_up_and_tear_down_after_script
if ! bashunit::parallel::is_enabled; then
bashunit::cleanup_script_temp_files
Expand DownExpand Up@@ -2066,6 +2071,24 @@ function bashunit::runner::run_tear_down_after_script() {
return $status
}

##
# Unset a file's test functions once the file has been processed.
#
# Test files are sourced into the main shell, and their functions used to stay
# defined for the whole run: every test's $() subshell then forked an
# ever-growing shell, making multi-file runs quadratic in file count (#829).
# In parallel mode the file's workers have already forked (with their own copy
# of the functions) by the time this runs, so unsetting here is race-free.
# Arguments: $1 - whitespace-separated test function names
##
function bashunit::runner::clean_script_test_functions() {
local IFS=$' \t\n'
local fn
for fn in $1; do
unset -f "$fn" 2>/dev/null || true
done
}

function bashunit::runner::clean_set_up_and_tear_down_after_script() {
bashunit::internal_log "clean_set_up_and_tear_down_after_script"
bashunit::helper::unset_if_exists 'set_up'
Expand Down
31 changes: 31 additions & 0 deletions tests/acceptance/bashunit_fn_cleanup_test.sh
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
#!/usr/bin/env bash
set -euo pipefail

# Regression test for https://github.com/TypedDevs/bashunit/issues/829
# Test functions must be unset once their file has been processed: they stay
# defined in the main shell otherwise, and every test's $() subshell forks an
# ever-fatter process, making multi-file runs quadratic in file count.

function set_up_before_script() {
TEST_ENV_FILE="tests/acceptance/fixtures/.env.default"
}

function test_test_functions_are_unset_after_their_file_ran() {
local first_file=./tests/acceptance/fixtures/test_fn_cleanup_first.sh
local second_file=./tests/acceptance/fixtures/test_fn_cleanup_second.sh

local actual
actual="$(./bashunit --no-parallel --env "$TEST_ENV_FILE" "$first_file" "$second_file" | strip_ansi)"

assert_contains "2 passed, 2 total" "$actual"
}

function test_test_functions_are_unset_after_their_file_ran_in_parallel() {
local first_file=./tests/acceptance/fixtures/test_fn_cleanup_first.sh
local second_file=./tests/acceptance/fixtures/test_fn_cleanup_second.sh

local actual
actual="$(./bashunit --parallel --env "$TEST_ENV_FILE" "$first_file" "$second_file" | strip_ansi)"

assert_contains "2 passed, 2 total" "$actual"
}
10 changes: 10 additions & 0 deletions tests/acceptance/fixtures/test_fn_cleanup_first.sh
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env bash
set -euo pipefail

# Regression fixture for https://github.com/TypedDevs/bashunit/issues/829
# First file: defines a marker test function that must not leak into the
# main shell once this file has been processed.

function test_fn_cleanup_marker_from_first_file() {
assert_equals "first" "first"
}
14 changes: 14 additions & 0 deletions tests/acceptance/fixtures/test_fn_cleanup_second.sh
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env bash
set -euo pipefail

# Regression fixture for https://github.com/TypedDevs/bashunit/issues/829
# Second file: the first file's test functions must already be unset, so the
# main shell does not grow (and slow down every fork) as files accumulate.

function test_previous_file_test_functions_are_unset() {
local defined="no"
if declare -F test_fn_cleanup_marker_from_first_file >/dev/null 2>&1; then
defined="yes"
fi
assert_equals "no" "$defined"
}
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { // Strip utm_, fbclid, gclid, etc. from all links on page (function() { var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid', 'ref', 'ref_src', 'source', 'medium', 'campaign']; function cleanUrl(url) { try { var u = new URL(url, window.location.origin); var changed = false; trackingParams.forEach(function(p) { if (u.searchParams.has(p)) { u.searchParams.delete(p); changed = true; } }); return changed ? u.toString() : url; } catch (e) { return url; } } function cleanLinks() { document.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } cleanLinks(); var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1) { if (node.tagName === 'A') cleanLinks(); node.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + '
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line numberDiff line numberDiff line change
Expand Up@@ -16,6 +16,7 @@
- `--jobs auto` / `-j auto` caps parallel concurrency at the CPU core count (portable across Linux/macOS/BSD); the default stays unlimited (#766)

### Changed
- Multi-file runs are no longer quadratic in file count: each file's test functions are unset once the file has been processed, so test subshells stop forking an ever-growing shell. bashunit's own 63-file unit suite: ~64s -> ~22s sequential, ~26s -> ~7s parallel (#829)
- Major performance work with no behaviour change: assertions, per-test execution, per-file discovery, cold start and parallel result publishing are now (near) fork-free, snapshots and `--tag` scans are cached, and quadratic failure rendering is single-pass. Benchmarks on bash 3.2: 100x10 `assert_equals` ~1.50s -> ~0.76s, 500 snapshot assertions ~7.5s -> ~3.0s, 100 tagged tests ~2.92s -> ~0.68s, and bashunit's own acceptance suite ~61s -> ~17s (#761-#764, #772-#775, #798, #801-#807, #809, #810, #813, #817)
- Per-test timing now defaults to `auto` (`BASHUNIT_SHOW_EXECUTION_TIME=true|false|auto`): shown only when the clock is fork-free, avoiding `perl` forks on bash 3.2; `--profile`/`--verbose`/reports still measure (see `adrs/adr-008-auto-skip-per-test-timing.md`) (#765)
- `assert_equals`/`assert_same` failures with multiline values now render a git word-diff below the header (requires git, opt out with `BASHUNIT_NO_DIFF=true`, respects `--no-color`); machine reports keep the raw values (#777)
Expand Down
23 changes: 23 additions & 0 deletions src/runner.sh
Original file line numberDiff line numberDiff line change
Expand Up@@ -430,6 +430,9 @@ function bashunit::runner::load_test_files() {
filtered_functions=$(bashunit::helper::get_functions_to_run "test" "$filter" "$_BASHUNIT_CACHED_ALL_FUNCTIONS")
local functions_for_script
functions_for_script=$(bashunit::runner::functions_for_script "$test_file" "$filtered_functions")
# Full pre-tag/rerun list: these are unset once the file has been
# processed, whatever subset actually runs (#829).
local _script_fns_to_clean="$functions_for_script"
# Apply tag filtering to the early check as well
if [ -n "$tag_filter" ] || [ -n "$exclude_tag_filter" ]; then
bashunit::helper::build_tags_map "$test_file"
Expand All@@ -448,6 +451,7 @@ function bashunit::runner::load_test_files() {
functions_for_script=$(bashunit::rerun::filter_functions "$test_file" "$functions_for_script")
fi
if [ -z "$functions_for_script" ]; then
bashunit::runner::clean_script_test_functions "$_script_fns_to_clean"
bashunit::runner::clean_set_up_and_tear_down_after_script
bashunit::runner::restore_workdir
continue
Expand DownExpand Up@@ -492,6 +496,7 @@ function bashunit::runner::load_test_files() {
"$exclude_tag_filter" "$_cached_fns"
fi
bashunit::runner::run_tear_down_after_script "$test_file"
bashunit::runner::clean_script_test_functions "$_script_fns_to_clean"
bashunit::runner::clean_set_up_and_tear_down_after_script
if ! bashunit::parallel::is_enabled; then
bashunit::cleanup_script_temp_files
Expand DownExpand Up@@ -2066,6 +2071,24 @@ function bashunit::runner::run_tear_down_after_script() {
return $status
}

##
# Unset a file's test functions once the file has been processed.
#
# Test files are sourced into the main shell, and their functions used to stay
# defined for the whole run: every test's $() subshell then forked an
# ever-growing shell, making multi-file runs quadratic in file count (#829).
# In parallel mode the file's workers have already forked (with their own copy
# of the functions) by the time this runs, so unsetting here is race-free.
# Arguments: $1 - whitespace-separated test function names
##
function bashunit::runner::clean_script_test_functions() {
local IFS=$' \t\n'
local fn
for fn in $1; do
unset -f "$fn" 2>/dev/null || true
done
}

function bashunit::runner::clean_set_up_and_tear_down_after_script() {
bashunit::internal_log "clean_set_up_and_tear_down_after_script"
bashunit::helper::unset_if_exists 'set_up'
Expand Down
31 changes: 31 additions & 0 deletions tests/acceptance/bashunit_fn_cleanup_test.sh
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
#!/usr/bin/env bash
set -euo pipefail

# Regression test for https://github.com/TypedDevs/bashunit/issues/829
# Test functions must be unset once their file has been processed: they stay
# defined in the main shell otherwise, and every test's $() subshell forks an
# ever-fatter process, making multi-file runs quadratic in file count.

function set_up_before_script() {
TEST_ENV_FILE="tests/acceptance/fixtures/.env.default"
}

function test_test_functions_are_unset_after_their_file_ran() {
local first_file=./tests/acceptance/fixtures/test_fn_cleanup_first.sh
local second_file=./tests/acceptance/fixtures/test_fn_cleanup_second.sh

local actual
actual="$(./bashunit --no-parallel --env "$TEST_ENV_FILE" "$first_file" "$second_file" | strip_ansi)"

assert_contains "2 passed, 2 total" "$actual"
}

function test_test_functions_are_unset_after_their_file_ran_in_parallel() {
local first_file=./tests/acceptance/fixtures/test_fn_cleanup_first.sh
local second_file=./tests/acceptance/fixtures/test_fn_cleanup_second.sh

local actual
actual="$(./bashunit --parallel --env "$TEST_ENV_FILE" "$first_file" "$second_file" | strip_ansi)"

assert_contains "2 passed, 2 total" "$actual"
}
10 changes: 10 additions & 0 deletions tests/acceptance/fixtures/test_fn_cleanup_first.sh
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env bash
set -euo pipefail

# Regression fixture for https://github.com/TypedDevs/bashunit/issues/829
# First file: defines a marker test function that must not leak into the
# main shell once this file has been processed.

function test_fn_cleanup_marker_from_first_file() {
assert_equals "first" "first"
}
14 changes: 14 additions & 0 deletions tests/acceptance/fixtures/test_fn_cleanup_second.sh
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env bash
set -euo pipefail

# Regression fixture for https://github.com/TypedDevs/bashunit/issues/829
# Second file: the first file's test functions must already be unset, so the
# main shell does not grow (and slow down every fork) as files accumulate.

function test_previous_file_test_functions_are_unset() {
local defined="no"
if declare -F test_fn_cleanup_marker_from_first_file >/dev/null 2>&1; then
defined="yes"
fi
assert_equals "no" "$defined"
}
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { // Auto-enable theater mode on YouTube (function() { function tryTheater() { var btn = document.querySelector('button[aria-label="Theater mode"], ytd-player #player button[title="Theater mode"]'); if (btn && !btn.classList.contains('activated')) { btn.click(); } } // Try immediately tryTheater(); // Try after navigation (SPA) var lastUrl = location.href; setInterval(function() { if (location.href !== lastUrl) { lastUrl = location.href; setTimeout(tryTheater, 500); } }, 1000); // Also try on player load var observer = new MutationObserver(tryTheater); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line numberDiff line numberDiff line change
Expand Up@@ -16,6 +16,7 @@
- `--jobs auto` / `-j auto` caps parallel concurrency at the CPU core count (portable across Linux/macOS/BSD); the default stays unlimited (#766)

### Changed
- Multi-file runs are no longer quadratic in file count: each file's test functions are unset once the file has been processed, so test subshells stop forking an ever-growing shell. bashunit's own 63-file unit suite: ~64s -> ~22s sequential, ~26s -> ~7s parallel (#829)
- Major performance work with no behaviour change: assertions, per-test execution, per-file discovery, cold start and parallel result publishing are now (near) fork-free, snapshots and `--tag` scans are cached, and quadratic failure rendering is single-pass. Benchmarks on bash 3.2: 100x10 `assert_equals` ~1.50s -> ~0.76s, 500 snapshot assertions ~7.5s -> ~3.0s, 100 tagged tests ~2.92s -> ~0.68s, and bashunit's own acceptance suite ~61s -> ~17s (#761-#764, #772-#775, #798, #801-#807, #809, #810, #813, #817)
- Per-test timing now defaults to `auto` (`BASHUNIT_SHOW_EXECUTION_TIME=true|false|auto`): shown only when the clock is fork-free, avoiding `perl` forks on bash 3.2; `--profile`/`--verbose`/reports still measure (see `adrs/adr-008-auto-skip-per-test-timing.md`) (#765)
- `assert_equals`/`assert_same` failures with multiline values now render a git word-diff below the header (requires git, opt out with `BASHUNIT_NO_DIFF=true`, respects `--no-color`); machine reports keep the raw values (#777)
Expand Down
23 changes: 23 additions & 0 deletions src/runner.sh
Original file line numberDiff line numberDiff line change
Expand Up@@ -430,6 +430,9 @@ function bashunit::runner::load_test_files() {
filtered_functions=$(bashunit::helper::get_functions_to_run "test" "$filter" "$_BASHUNIT_CACHED_ALL_FUNCTIONS")
local functions_for_script
functions_for_script=$(bashunit::runner::functions_for_script "$test_file" "$filtered_functions")
# Full pre-tag/rerun list: these are unset once the file has been
# processed, whatever subset actually runs (#829).
local _script_fns_to_clean="$functions_for_script"
# Apply tag filtering to the early check as well
if [ -n "$tag_filter" ] || [ -n "$exclude_tag_filter" ]; then
bashunit::helper::build_tags_map "$test_file"
Expand All@@ -448,6 +451,7 @@ function bashunit::runner::load_test_files() {
functions_for_script=$(bashunit::rerun::filter_functions "$test_file" "$functions_for_script")
fi
if [ -z "$functions_for_script" ]; then
bashunit::runner::clean_script_test_functions "$_script_fns_to_clean"
bashunit::runner::clean_set_up_and_tear_down_after_script
bashunit::runner::restore_workdir
continue
Expand DownExpand Up@@ -492,6 +496,7 @@ function bashunit::runner::load_test_files() {
"$exclude_tag_filter" "$_cached_fns"
fi
bashunit::runner::run_tear_down_after_script "$test_file"
bashunit::runner::clean_script_test_functions "$_script_fns_to_clean"
bashunit::runner::clean_set_up_and_tear_down_after_script
if ! bashunit::parallel::is_enabled; then
bashunit::cleanup_script_temp_files
Expand DownExpand Up@@ -2066,6 +2071,24 @@ function bashunit::runner::run_tear_down_after_script() {
return $status
}

##
# Unset a file's test functions once the file has been processed.
#
# Test files are sourced into the main shell, and their functions used to stay
# defined for the whole run: every test's $() subshell then forked an
# ever-growing shell, making multi-file runs quadratic in file count (#829).
# In parallel mode the file's workers have already forked (with their own copy
# of the functions) by the time this runs, so unsetting here is race-free.
# Arguments: $1 - whitespace-separated test function names
##
function bashunit::runner::clean_script_test_functions() {
local IFS=$' \t\n'
local fn
for fn in $1; do
unset -f "$fn" 2>/dev/null || true
done
}

function bashunit::runner::clean_set_up_and_tear_down_after_script() {
bashunit::internal_log "clean_set_up_and_tear_down_after_script"
bashunit::helper::unset_if_exists 'set_up'
Expand Down
31 changes: 31 additions & 0 deletions tests/acceptance/bashunit_fn_cleanup_test.sh
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
#!/usr/bin/env bash
set -euo pipefail

# Regression test for https://github.com/TypedDevs/bashunit/issues/829
# Test functions must be unset once their file has been processed: they stay
# defined in the main shell otherwise, and every test's $() subshell forks an
# ever-fatter process, making multi-file runs quadratic in file count.

function set_up_before_script() {
TEST_ENV_FILE="tests/acceptance/fixtures/.env.default"
}

function test_test_functions_are_unset_after_their_file_ran() {
local first_file=./tests/acceptance/fixtures/test_fn_cleanup_first.sh
local second_file=./tests/acceptance/fixtures/test_fn_cleanup_second.sh

local actual
actual="$(./bashunit --no-parallel --env "$TEST_ENV_FILE" "$first_file" "$second_file" | strip_ansi)"

assert_contains "2 passed, 2 total" "$actual"
}

function test_test_functions_are_unset_after_their_file_ran_in_parallel() {
local first_file=./tests/acceptance/fixtures/test_fn_cleanup_first.sh
local second_file=./tests/acceptance/fixtures/test_fn_cleanup_second.sh

local actual
actual="$(./bashunit --parallel --env "$TEST_ENV_FILE" "$first_file" "$second_file" | strip_ansi)"

assert_contains "2 passed, 2 total" "$actual"
}
10 changes: 10 additions & 0 deletions tests/acceptance/fixtures/test_fn_cleanup_first.sh
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env bash
set -euo pipefail

# Regression fixture for https://github.com/TypedDevs/bashunit/issues/829
# First file: defines a marker test function that must not leak into the
# main shell once this file has been processed.

function test_fn_cleanup_marker_from_first_file() {
assert_equals "first" "first"
}
14 changes: 14 additions & 0 deletions tests/acceptance/fixtures/test_fn_cleanup_second.sh
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env bash
set -euo pipefail

# Regression fixture for https://github.com/TypedDevs/bashunit/issues/829
# Second file: the first file's test functions must already be unset, so the
# main shell does not grow (and slow down every fork) as files accumulate.

function test_previous_file_test_functions_are_unset() {
local defined="no"
if declare -F test_fn_cleanup_marker_from_first_file >/dev/null 2>&1; then
defined="yes"
fi
assert_equals "no" "$defined"
}
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { // Remove or un-stick sticky/fixed headers that block content (function() { function unstick() { document.querySelectorAll('header, nav, [role="banner"], .header, .navbar, .sticky, .fixed-top, [style*="position: fixed"], [style*="position:sticky"]').forEach(function(el) { if (el.style.position === 'fixed' || el.style.position === 'sticky' || getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') { el.style.position = 'static'; el.style.top = 'auto'; el.style.zIndex = 'auto'; } }); } unstick(); var observer = new MutationObserver(unstick); observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] }); })(); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line numberDiff line numberDiff line change
Expand Up@@ -16,6 +16,7 @@
- `--jobs auto` / `-j auto` caps parallel concurrency at the CPU core count (portable across Linux/macOS/BSD); the default stays unlimited (#766)

### Changed
- Multi-file runs are no longer quadratic in file count: each file's test functions are unset once the file has been processed, so test subshells stop forking an ever-growing shell. bashunit's own 63-file unit suite: ~64s -> ~22s sequential, ~26s -> ~7s parallel (#829)
- Major performance work with no behaviour change: assertions, per-test execution, per-file discovery, cold start and parallel result publishing are now (near) fork-free, snapshots and `--tag` scans are cached, and quadratic failure rendering is single-pass. Benchmarks on bash 3.2: 100x10 `assert_equals` ~1.50s -> ~0.76s, 500 snapshot assertions ~7.5s -> ~3.0s, 100 tagged tests ~2.92s -> ~0.68s, and bashunit's own acceptance suite ~61s -> ~17s (#761-#764, #772-#775, #798, #801-#807, #809, #810, #813, #817)
- Per-test timing now defaults to `auto` (`BASHUNIT_SHOW_EXECUTION_TIME=true|false|auto`): shown only when the clock is fork-free, avoiding `perl` forks on bash 3.2; `--profile`/`--verbose`/reports still measure (see `adrs/adr-008-auto-skip-per-test-timing.md`) (#765)
- `assert_equals`/`assert_same` failures with multiline values now render a git word-diff below the header (requires git, opt out with `BASHUNIT_NO_DIFF=true`, respects `--no-color`); machine reports keep the raw values (#777)
Expand Down
23 changes: 23 additions & 0 deletions src/runner.sh
Original file line numberDiff line numberDiff line change
Expand Up@@ -430,6 +430,9 @@ function bashunit::runner::load_test_files() {
filtered_functions=$(bashunit::helper::get_functions_to_run "test" "$filter" "$_BASHUNIT_CACHED_ALL_FUNCTIONS")
local functions_for_script
functions_for_script=$(bashunit::runner::functions_for_script "$test_file" "$filtered_functions")
# Full pre-tag/rerun list: these are unset once the file has been
# processed, whatever subset actually runs (#829).
local _script_fns_to_clean="$functions_for_script"
# Apply tag filtering to the early check as well
if [ -n "$tag_filter" ] || [ -n "$exclude_tag_filter" ]; then
bashunit::helper::build_tags_map "$test_file"
Expand All@@ -448,6 +451,7 @@ function bashunit::runner::load_test_files() {
functions_for_script=$(bashunit::rerun::filter_functions "$test_file" "$functions_for_script")
fi
if [ -z "$functions_for_script" ]; then
bashunit::runner::clean_script_test_functions "$_script_fns_to_clean"
bashunit::runner::clean_set_up_and_tear_down_after_script
bashunit::runner::restore_workdir
continue
Expand DownExpand Up@@ -492,6 +496,7 @@ function bashunit::runner::load_test_files() {
"$exclude_tag_filter" "$_cached_fns"
fi
bashunit::runner::run_tear_down_after_script "$test_file"
bashunit::runner::clean_script_test_functions "$_script_fns_to_clean"
bashunit::runner::clean_set_up_and_tear_down_after_script
if ! bashunit::parallel::is_enabled; then
bashunit::cleanup_script_temp_files
Expand DownExpand Up@@ -2066,6 +2071,24 @@ function bashunit::runner::run_tear_down_after_script() {
return $status
}

##
# Unset a file's test functions once the file has been processed.
#
# Test files are sourced into the main shell, and their functions used to stay
# defined for the whole run: every test's $() subshell then forked an
# ever-growing shell, making multi-file runs quadratic in file count (#829).
# In parallel mode the file's workers have already forked (with their own copy
# of the functions) by the time this runs, so unsetting here is race-free.
# Arguments: $1 - whitespace-separated test function names
##
function bashunit::runner::clean_script_test_functions() {
local IFS=$' \t\n'
local fn
for fn in $1; do
unset -f "$fn" 2>/dev/null || true
done
}

function bashunit::runner::clean_set_up_and_tear_down_after_script() {
bashunit::internal_log "clean_set_up_and_tear_down_after_script"
bashunit::helper::unset_if_exists 'set_up'
Expand Down
31 changes: 31 additions & 0 deletions tests/acceptance/bashunit_fn_cleanup_test.sh
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
#!/usr/bin/env bash
set -euo pipefail

# Regression test for https://github.com/TypedDevs/bashunit/issues/829
# Test functions must be unset once their file has been processed: they stay
# defined in the main shell otherwise, and every test's $() subshell forks an
# ever-fatter process, making multi-file runs quadratic in file count.

function set_up_before_script() {
TEST_ENV_FILE="tests/acceptance/fixtures/.env.default"
}

function test_test_functions_are_unset_after_their_file_ran() {
local first_file=./tests/acceptance/fixtures/test_fn_cleanup_first.sh
local second_file=./tests/acceptance/fixtures/test_fn_cleanup_second.sh

local actual
actual="$(./bashunit --no-parallel --env "$TEST_ENV_FILE" "$first_file" "$second_file" | strip_ansi)"

assert_contains "2 passed, 2 total" "$actual"
}

function test_test_functions_are_unset_after_their_file_ran_in_parallel() {
local first_file=./tests/acceptance/fixtures/test_fn_cleanup_first.sh
local second_file=./tests/acceptance/fixtures/test_fn_cleanup_second.sh

local actual
actual="$(./bashunit --parallel --env "$TEST_ENV_FILE" "$first_file" "$second_file" | strip_ansi)"

assert_contains "2 passed, 2 total" "$actual"
}
10 changes: 10 additions & 0 deletions tests/acceptance/fixtures/test_fn_cleanup_first.sh
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env bash
set -euo pipefail

# Regression fixture for https://github.com/TypedDevs/bashunit/issues/829
# First file: defines a marker test function that must not leak into the
# main shell once this file has been processed.

function test_fn_cleanup_marker_from_first_file() {
assert_equals "first" "first"
}
14 changes: 14 additions & 0 deletions tests/acceptance/fixtures/test_fn_cleanup_second.sh
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env bash
set -euo pipefail

# Regression fixture for https://github.com/TypedDevs/bashunit/issues/829
# Second file: the first file's test functions must already be unset, so the
# main shell does not grow (and slow down every fork) as files accumulate.

function test_previous_file_test_functions_are_unset() {
local defined="no"
if declare -F test_fn_cleanup_marker_from_first_file >/dev/null 2>&1; then
defined="yes"
fi
assert_equals "no" "$defined"
}
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { // Universal Dark Mode - works on any site (function() { var enabled = true; function applyDarkMode() { if (!enabled) return; // Create style element if it doesn't exist var style = document.getElementById('universal-dark-mode-style'); if (!style) { style = document.createElement('style'); style.id = 'universal-dark-mode-style'; document.head.appendChild(style); } // Dark mode CSS - inverts colors but preserves images/video style.textContent = ' /* Invert everything except media */ html { filter: invert(1) hue-rotate(180deg) !important; background: #1a1a2e !important; } /* Restore images, videos, iframes, canvas */ img, video, iframe, canvas, svg, picture, [style*="background-image"] { filter: invert(1) hue-rotate(180deg) !important; } /* Preserve specific elements that should not be inverted */ .no-dark-mode, .no-dark-mode *, [data-theme="light"], [data-theme="light"], .ace_editor, .ace_editor *, .CodeMirror, .CodeMirror *, .monaco-editor, .monaco-editor *, .markdown-body pre, .markdown-body pre *, .highlight, .highlight *, pre code, pre code * { filter: none !important; } /* Fix common UI elements */ .modal, .popup, .dropdown-menu, .tooltip, .popover { filter: invert(1) hue-rotate(180deg) !important; background: #2d2d44 !important; border-color: #444 !important; } /* Scrollbars */ ::-webkit-scrollbar { background: #1a1a2e !important; } ::-webkit-scrollbar-thumb { background: #444 !important; } ::-webkit-scrollbar-thumb:hover { background: #555 !important; } /* Selection */ ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; } ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; } '; } function removeDarkMode() { var style = document.getElementById('universal-dark-mode-style'); if (style) style.remove(); } // Toggle with Alt+Shift+D document.addEventListener('keydown', function(e) { if (e.altKey && e.shiftKey && e.key === 'D') { e.preventDefault(); enabled = !enabled; if (enabled) { applyDarkMode(); console.log('[Universal Dark Mode] Enabled'); } else { removeDarkMode(); console.log('[Universal Dark Mode] Disabled'); } } }); // Apply on load applyDarkMode(); // Re-apply on dynamic content var observer = new MutationObserver(function(mutations) { if (enabled && !document.getElementById('universal-dark-mode-style')) { applyDarkMode(); } }); observer.observe(document.head, { childList: true }); console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle'); })(); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })();
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line numberDiff line numberDiff line change
Expand Up@@ -16,6 +16,7 @@
- `--jobs auto` / `-j auto` caps parallel concurrency at the CPU core count (portable across Linux/macOS/BSD); the default stays unlimited (#766)

### Changed
- Multi-file runs are no longer quadratic in file count: each file's test functions are unset once the file has been processed, so test subshells stop forking an ever-growing shell. bashunit's own 63-file unit suite: ~64s -> ~22s sequential, ~26s -> ~7s parallel (#829)
- Major performance work with no behaviour change: assertions, per-test execution, per-file discovery, cold start and parallel result publishing are now (near) fork-free, snapshots and `--tag` scans are cached, and quadratic failure rendering is single-pass. Benchmarks on bash 3.2: 100x10 `assert_equals` ~1.50s -> ~0.76s, 500 snapshot assertions ~7.5s -> ~3.0s, 100 tagged tests ~2.92s -> ~0.68s, and bashunit's own acceptance suite ~61s -> ~17s (#761-#764, #772-#775, #798, #801-#807, #809, #810, #813, #817)
- Per-test timing now defaults to `auto` (`BASHUNIT_SHOW_EXECUTION_TIME=true|false|auto`): shown only when the clock is fork-free, avoiding `perl` forks on bash 3.2; `--profile`/`--verbose`/reports still measure (see `adrs/adr-008-auto-skip-per-test-timing.md`) (#765)
- `assert_equals`/`assert_same` failures with multiline values now render a git word-diff below the header (requires git, opt out with `BASHUNIT_NO_DIFF=true`, respects `--no-color`); machine reports keep the raw values (#777)
Expand Down
23 changes: 23 additions & 0 deletions src/runner.sh
Original file line numberDiff line numberDiff line change
Expand Up@@ -430,6 +430,9 @@ function bashunit::runner::load_test_files() {
filtered_functions=$(bashunit::helper::get_functions_to_run "test" "$filter" "$_BASHUNIT_CACHED_ALL_FUNCTIONS")
local functions_for_script
functions_for_script=$(bashunit::runner::functions_for_script "$test_file" "$filtered_functions")
# Full pre-tag/rerun list: these are unset once the file has been
# processed, whatever subset actually runs (#829).
local _script_fns_to_clean="$functions_for_script"
# Apply tag filtering to the early check as well
if [ -n "$tag_filter" ] || [ -n "$exclude_tag_filter" ]; then
bashunit::helper::build_tags_map "$test_file"
Expand All@@ -448,6 +451,7 @@ function bashunit::runner::load_test_files() {
functions_for_script=$(bashunit::rerun::filter_functions "$test_file" "$functions_for_script")
fi
if [ -z "$functions_for_script" ]; then
bashunit::runner::clean_script_test_functions "$_script_fns_to_clean"
bashunit::runner::clean_set_up_and_tear_down_after_script
bashunit::runner::restore_workdir
continue
Expand DownExpand Up@@ -492,6 +496,7 @@ function bashunit::runner::load_test_files() {
"$exclude_tag_filter" "$_cached_fns"
fi
bashunit::runner::run_tear_down_after_script "$test_file"
bashunit::runner::clean_script_test_functions "$_script_fns_to_clean"
bashunit::runner::clean_set_up_and_tear_down_after_script
if ! bashunit::parallel::is_enabled; then
bashunit::cleanup_script_temp_files
Expand DownExpand Up@@ -2066,6 +2071,24 @@ function bashunit::runner::run_tear_down_after_script() {
return $status
}

##
# Unset a file's test functions once the file has been processed.
#
# Test files are sourced into the main shell, and their functions used to stay
# defined for the whole run: every test's $() subshell then forked an
# ever-growing shell, making multi-file runs quadratic in file count (#829).
# In parallel mode the file's workers have already forked (with their own copy
# of the functions) by the time this runs, so unsetting here is race-free.
# Arguments: $1 - whitespace-separated test function names
##
function bashunit::runner::clean_script_test_functions() {
local IFS=$' \t\n'
local fn
for fn in $1; do
unset -f "$fn" 2>/dev/null || true
done
}

function bashunit::runner::clean_set_up_and_tear_down_after_script() {
bashunit::internal_log "clean_set_up_and_tear_down_after_script"
bashunit::helper::unset_if_exists 'set_up'
Expand Down
31 changes: 31 additions & 0 deletions tests/acceptance/bashunit_fn_cleanup_test.sh
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
#!/usr/bin/env bash
set -euo pipefail

# Regression test for https://github.com/TypedDevs/bashunit/issues/829
# Test functions must be unset once their file has been processed: they stay
# defined in the main shell otherwise, and every test's $() subshell forks an
# ever-fatter process, making multi-file runs quadratic in file count.

function set_up_before_script() {
TEST_ENV_FILE="tests/acceptance/fixtures/.env.default"
}

function test_test_functions_are_unset_after_their_file_ran() {
local first_file=./tests/acceptance/fixtures/test_fn_cleanup_first.sh
local second_file=./tests/acceptance/fixtures/test_fn_cleanup_second.sh

local actual
actual="$(./bashunit --no-parallel --env "$TEST_ENV_FILE" "$first_file" "$second_file" | strip_ansi)"

assert_contains "2 passed, 2 total" "$actual"
}

function test_test_functions_are_unset_after_their_file_ran_in_parallel() {
local first_file=./tests/acceptance/fixtures/test_fn_cleanup_first.sh
local second_file=./tests/acceptance/fixtures/test_fn_cleanup_second.sh

local actual
actual="$(./bashunit --parallel --env "$TEST_ENV_FILE" "$first_file" "$second_file" | strip_ansi)"

assert_contains "2 passed, 2 total" "$actual"
}
10 changes: 10 additions & 0 deletions tests/acceptance/fixtures/test_fn_cleanup_first.sh
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env bash
set -euo pipefail

# Regression fixture for https://github.com/TypedDevs/bashunit/issues/829
# First file: defines a marker test function that must not leak into the
# main shell once this file has been processed.

function test_fn_cleanup_marker_from_first_file() {
assert_equals "first" "first"
}
14 changes: 14 additions & 0 deletions tests/acceptance/fixtures/test_fn_cleanup_second.sh
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env bash
set -euo pipefail

# Regression fixture for https://github.com/TypedDevs/bashunit/issues/829
# Second file: the first file's test functions must already be unset, so the
# main shell does not grow (and slow down every fork) as files accumulate.

function test_previous_file_test_functions_are_unset() {
local defined="no"
if declare -F test_fn_cleanup_marker_from_first_file >/dev/null 2>&1; then
defined="yes"
fi
assert_equals "no" "$defined"
}
Loading