Add prefix to helper functions to prevent user code conflicts#539
Merged
Chemaclass merged 3 commits intomainfrom Dec 6, 2025
Merged
Add prefix to helper functions to prevent user code conflicts#539Chemaclass merged 3 commits intomainfrom
Chemaclass merged 3 commits intomainfrom
Conversation
BREAKING CHANGE: All helper functions now require bashunit:: prefix. Renamed functions: - skip → bashunit::skip - todo → bashunit::todo - fail → bashunit::fail - mock → bashunit::mock - unmock → bashunit::unmock - spy → bashunit::spy - temp_file → bashunit::temp_file - temp_dir → bashunit::temp_dir - data_set → bashunit::data_set - current_dir → bashunit::current_dir - current_filename → bashunit::current_filename - random_str → bashunit::random_str - log → bashunit::log - set_test_title → bashunit::set_test_title All assert_* functions remain unchanged.
JesusValeraDev
approved these changes
Dec 6, 2025
fabriziofs
approved these changes
Dec 6, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
📚 Description
This PR addresses the namespace pollution issue (#538) that makes bashunit unusable for projects that define common function names like
log,fail,mock, etc.The Problem:
Bashunit previously defined generic function names at the global scope. When users have their own functions with the same names (e.g., a
log()function in a logging module), conflicts occur silently, causing tests to fail or behave unexpectedly. Since bash has no concept of private methods or namespaces, any function defined by bashunit can collide with user code.Example conflict scenario:
The Solution:
All helper functions now use the
bashunit::namespace prefix, following the same convention already used internally (e.g.,console::print,state::add_assertions_passed). This ensures bashunit functions never conflict with user-defined functions.🔖 Changes
Function Renames (Breaking Changes)
All helper functions accessible to test files now require the
bashunit::prefix:skipbashunit::skiptodobashunit::todofailbashunit::failmockbashunit::mockunmockbashunit::unmockspybashunit::spytemp_filebashunit::temp_filetemp_dirbashunit::temp_dirdata_setbashunit::data_setcurrent_dirbashunit::current_dircurrent_filenamebashunit::current_filenamerandom_strbashunit::random_strlogbashunit::logset_test_titlebashunit::set_test_titleWhat Remains Unchanged
assert_*functions keep their names (they already have a unique prefix)set_up,tear_down,set_up_before_script,tear_down_after_script) keep their names (these are user-defined functions, not bashunit-provided)Files Updated
src/- renamed function definitions and internal callsdocs/- updated all examples to use new namesCHANGELOG.mdupdated with migration guideMigration Guide
Users upgrading to this version need to update their test files:
Quick migration command:
✅ To-do list
CHANGELOG.mdto reflect the new feature or fixFixes #538