File manager - Edit - /home/rbwebsco/sidrafran2.rb-webs.com/bats-core.zip
Back
PK )8�\y� �� � formatter.bashnu ȯ�� #!/usr/bin/bash # reads (extended) bats tap streams from stdin and calls callback functions for each line # bats_tap_stream_plan <number of tests> -> when the test plan is encountered # bats_tap_stream_begin <test index> <test name> -> when a new test is begun WARNING: extended only # bats_tap_stream_ok [--duration <milliseconds] <test index> <test name> -> when a test was successful # bats_tap_stream_not_ok [--duration <milliseconds>] <test index> <test name> -> when a test has failed # bats_tap_stream_skipped <test index> <test name> <skip reason> -> when a test was skipped # bats_tap_stream_comment <comment text without leading '# '> <scope> -> when a comment line was encountered, # scope tells the last encountered of plan, begin, ok, not_ok, skipped, suite # bats_tap_stream_suite <file name> -> when a new file is begun WARNING: extended only # bats_tap_stream_unknown <full line> <scope> -> when a line is encountered that does not match the previous entries, # scope @see bats_tap_stream_comment # forwards all input as is, when there is no TAP test plan header function bats_parse_internal_extended_tap() { local header_pattern='[0-9]+\.\.[0-9]+' IFS= read -r header if [[ "$header" =~ $header_pattern ]]; then bats_tap_stream_plan "${header:3}" else # If the first line isn't a TAP plan, print it and pass the rest through printf '%s\n' "$header" exec cat fi ok_line_regexpr="ok ([0-9]+) (.*)" skip_line_regexpr="ok ([0-9]+) (.*) # skip( (.*))?$" not_ok_line_regexpr="not ok ([0-9]+) (.*)" timing_expr="in ([0-9]+)ms$" local test_name begin_index ok_index not_ok_index index scope begin_index=0 index=0 scope=plan while IFS= read -r line; do case "$line" in 'begin '*) # this might only be called in extended tap output ((++begin_index)) scope=begin test_name="${line#* $begin_index }" bats_tap_stream_begin "$begin_index" "$test_name" ;; 'ok '*) ((++index)) scope=ok if [[ "$line" =~ $ok_line_regexpr ]]; then ok_index="${BASH_REMATCH[1]}" test_name="${BASH_REMATCH[2]}" if [[ "$line" =~ $skip_line_regexpr ]]; then test_name="${BASH_REMATCH[2]}" # cut off name before "# skip" local skip_reason="${BASH_REMATCH[4]}" bats_tap_stream_skipped "$ok_index" "$test_name" "$skip_reason" else if [[ "$line" =~ $timing_expr ]]; then bats_tap_stream_ok --duration "${BASH_REMATCH[1]}" "$ok_index" "$test_name" else bats_tap_stream_ok "$ok_index" "$test_name" fi fi else printf "ERROR: could not match ok line: %s" "$line" >&2 exit 1 fi ;; 'not ok '*) ((++index)) scope=not_ok if [[ "$line" =~ $not_ok_line_regexpr ]]; then not_ok_index="${BASH_REMATCH[1]}" test_name="${BASH_REMATCH[2]}" if [[ "$line" =~ $timing_expr ]]; then bats_tap_stream_not_ok --duration "${BASH_REMATCH[1]}" "$not_ok_index" "$test_name" else bats_tap_stream_not_ok "$not_ok_index" "$test_name" fi else printf "ERROR: could not match not ok line: %s" "$line" >&2 exit 1 fi ;; '# '*) bats_tap_stream_comment "${line:2}" "$scope" ;; 'suite '*) scope=suite # pass on the bats_tap_stream_suite "${line:6}" ;; *) bats_tap_stream_unknown "$line" "$scope" ;; esac done } # given a prefix and a path, remove the prefix if the path starts with it # e.g. # remove_prefix /usr/bin /usr/bin/bash -> bash # remove_prefix /usr /usr/lib/bash -> lib/bash # remove_prefix /usr/bin /usr/local/bin/bash -> /usr/local/bin/bash remove_prefix() { base_path="$1" path="$2" if [[ "$path" == "$base_path"* ]]; then # cut off the common prefix printf "%s" "${path:${#base_path}}" else printf "%s" "$path" fi } normalize_base_path() { # <target variable> <base path> # the relative path root to use for reporting filenames # this is mainly intended for suite mode, where this will be the suite root folder local base_path="$2" # use the containing directory when --base-path is a file if [[ ! -d "$base_path" ]]; then base_path="$(dirname "$base_path")" fi # get the absolute path base_path="$(cd "$base_path" && pwd)" # ensure the path ends with / to strip that later on if [[ "${base_path}" != *"/" ]]; then base_path="$base_path/" fi printf -v "$1" "%s" "$base_path" } PK )8�\8n�J common.bashnu ȯ�� #!/usr/bin/bash bats_prefix_lines_for_tap_output() { while IFS= read -r line; do printf '# %s\n' "$line" || break # avoid feedback loop when errors are redirected into BATS_OUT (see #353) done if [[ -n "$line" ]]; then printf '# %s\n' "$line" fi }PK )8�\e��_� � tracing.bashnu ȯ�� #!/usr/bin/bash bats_capture_stack_trace() { local test_file local funcname local i # The last entry in the stack trace is not useful when en error occured: # It is either duplicated (kinda correct) or has wrong line number (Bash < 4.4) # Therefore we capture the stacktrace but use it only after the next debug # trap fired. # Expansion is required for empty arrays which otherwise error BATS_CURRENT_STACK_TRACE=("${BATS_STACK_TRACE[@]+"${BATS_STACK_TRACE[@]}"}") BATS_STACK_TRACE=() for ((i = 2; i != ${#FUNCNAME[@]}; ++i)); do # Use BATS_TEST_SOURCE if necessary to work around Bash < 4.4 bug whereby # calling an exported function erases the test file's BASH_SOURCE entry. test_file="${BASH_SOURCE[$i]:-$BATS_TEST_SOURCE}" funcname="${FUNCNAME[$i]}" BATS_STACK_TRACE+=("${BASH_LINENO[$((i - 1))]} $funcname $test_file") case "$funcname" in "$BATS_TEST_NAME" | setup | teardown | setup_file | teardown_file) break ;; esac if [[ "${BASH_SOURCE[$i + 1]:-}" == *"bats-exec-file" ]] && [[ "$funcname" == 'source' ]]; then break fi done } bats_print_stack_trace() { local frame local index=1 local count="${#@}" local filename local lineno for frame in "$@"; do bats_frame_filename "$frame" 'filename' bats_trim_filename "$filename" 'filename' bats_frame_lineno "$frame" 'lineno' if [[ $index -eq 1 ]]; then printf '# (' else printf '# ' fi local fn bats_frame_function "$frame" 'fn' if [[ "$fn" != "$BATS_TEST_NAME" ]] && # don't print "from function `source'"", # when failing in free code during `source $test_file` from bats-exec-file ! [[ "$fn" == 'source' && $index -eq $count ]]; then printf "from function \`%s' " "$fn" fi if [[ $index -eq $count ]]; then printf 'in test file %s, line %d)\n' "$filename" "$lineno" else printf 'in file %s, line %d,\n' "$filename" "$lineno" fi ((++index)) done } bats_print_failed_command() { if [[ ${#BATS_STACK_TRACE[@]} -eq 0 ]]; then return fi local frame="${BATS_STACK_TRACE[${#BATS_STACK_TRACE[@]} - 1]}" local filename local lineno local failed_line local failed_command bats_frame_filename "$frame" 'filename' bats_frame_lineno "$frame" 'lineno' bats_extract_line "$filename" "$lineno" 'failed_line' bats_strip_string "$failed_line" 'failed_command' printf '%s' "# \`${failed_command}' " if [[ "$BATS_ERROR_STATUS" -eq 1 ]]; then printf 'failed%s\n' "$BATS_ERROR_SUFFIX" else printf 'failed with status %d%s\n' "$BATS_ERROR_STATUS" "$BATS_ERROR_SUFFIX" fi } bats_frame_lineno() { printf -v "$2" '%s' "${1%% *}" } bats_frame_function() { local __bff_function="${1#* }" printf -v "$2" '%s' "${__bff_function%% *}" } bats_frame_filename() { local __bff_filename="${1#* }" __bff_filename="${__bff_filename#* }" if [[ "$__bff_filename" == "$BATS_TEST_SOURCE" ]]; then __bff_filename="$BATS_TEST_FILENAME" fi printf -v "$2" '%s' "$__bff_filename" } bats_extract_line() { local __bats_extract_line_line local __bats_extract_line_index=0 while IFS= read -r __bats_extract_line_line; do if [[ "$((++__bats_extract_line_index))" -eq "$2" ]]; then printf -v "$3" '%s' "${__bats_extract_line_line%$'\r'}" break fi done <"$1" } bats_strip_string() { [[ "$1" =~ ^[[:space:]]*(.*)[[:space:]]*$ ]] printf -v "$2" '%s' "${BASH_REMATCH[1]}" } bats_trim_filename() { printf -v "$2" '%s' "${1#$BATS_CWD/}" } # normalize a windows path from e.g. C:/directory to /c/directory # The path must point to an existing/accessable directory, not a file! bats_normalize_windows_dir_path() { # <output-var> <path> local output_var="$1" local path="$2" if [[ $path == ?:* ]]; then NORMALIZED_INPUT="$(cd "$path" || exit 1; pwd)" else NORMALIZED_INPUT="$path" fi printf -v "$output_var" "%s" "$NORMALIZED_INPUT" } bats_emit_trace() { if [[ $BATS_TRACE_LEVEL -gt 0 ]]; then local line=${BASH_LINENO[1]} # shellcheck disable=SC2016 if [[ $BASH_COMMAND != '"$BATS_TEST_NAME" >> "$BATS_OUT" 2>&1 4>&1' && $BASH_COMMAND != "bats_test_begin "* ]] && # don't emit these internal calls [[ $BASH_COMMAND != "$BATS_LAST_BASH_COMMAND" || $line != "$BATS_LAST_BASH_LINENO" ]] && # avoid printing a function twice (at call site and at definiton site) [[ $BASH_COMMAND != "$BATS_LAST_BASH_COMMAND" || ${BASH_LINENO[2]} != "$BATS_LAST_BASH_LINENO" || ${BASH_SOURCE[3]} != "$BATS_LAST_BASH_SOURCE" ]]; then local file="${BASH_SOURCE[2]}" # index 2: skip over bats_emit_trace and bats_debug_trap if [[ $file == "${BATS_TEST_SOURCE}" ]]; then file="$BATS_TEST_FILENAME" fi local padding='$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$' if (( BATS_LAST_STACK_DEPTH != ${#BASH_LINENO[@]} )); then printf '%s [%s:%d]\n' "${padding::${#BASH_LINENO[@]}-4}" "${file##*/}" "$line" >&4 fi printf '%s %s\n' "${padding::${#BASH_LINENO[@]}-4}" "$BASH_COMMAND" >&4 BATS_LAST_BASH_COMMAND="$BASH_COMMAND" BATS_LAST_BASH_LINENO="$line" BATS_LAST_BASH_SOURCE="${BASH_SOURCE[2]}" BATS_LAST_STACK_DEPTH="${#BASH_LINENO[@]}" fi fi } bats_debug_trap() { # on windows we sometimes get a mix of paths (when install via nmp install -g) # which have C:/... or /c/... comparing them is going to be problematic. # We need to normalize them to a common format! local NORMALIZED_INPUT bats_normalize_windows_dir_path NORMALIZED_INPUT "${1%/*}" local file_excluded='' path for path in "${_BATS_DEBUG_EXCLUDE_PATHS[@]}"; do if [[ "$NORMALIZED_INPUT" == "$path"* ]]; then file_excluded=1 break fi done # don't update the trace within library functions or we get backtraces from inside traps # also don't record new stack traces while handling interruptions, to avoid overriding the interrupted command if [[ -z "$file_excluded" && "${BATS_INTERRUPTED-NOTSET}" == NOTSET ]]; then bats_capture_stack_trace bats_emit_trace fi } # For some versions of Bash, the `ERR` trap may not always fire for every # command failure, but the `EXIT` trap will. Also, some command failures may not # set `$?` properly. See #72 and #81 for details. # # For this reason, we call `bats_error_trap` at the very beginning of # `bats_teardown_trap` (the `DEBUG` trap for the call will fix the stack trace) # and check the value of `$BATS_TEST_COMPLETED` before taking other actions. # We also adjust the exit status value if needed. # # See `bats_exit_trap` for an additional EXIT error handling case when `$?` # isn't set properly during `teardown()` errors. bats_error_trap() { local status="$?" if [[ -z "$BATS_TEST_COMPLETED" ]]; then BATS_ERROR_STATUS="${BATS_ERROR_STATUS:-$status}" if [[ "$BATS_ERROR_STATUS" -eq 0 ]]; then BATS_ERROR_STATUS=1 fi BATS_STACK_TRACE=("${BATS_CURRENT_STACK_TRACE[@]}") trap - DEBUG fi } bats_add_debug_exclude_path() { # <path> if [[ -z "$1" ]]; then # don't exclude everything printf "bats_add_debug_exclude_path: Exclude path must not be empty!\n" >&2 return 1 fi if [[ "$OSTYPE" == cygwin || "$OSTYPE" == msys ]]; then bats_normalize_windows_dir_path normalized_dir "$1" _BATS_DEBUG_EXCLUDE_PATHS+=("$normalized_dir") else _BATS_DEBUG_EXCLUDE_PATHS+=("$1") fi } bats_setup_tracing() { _BATS_DEBUG_EXCLUDE_PATHS=() # exclude some paths by default bats_add_debug_exclude_path "$BATS_ROOT/lib/" bats_add_debug_exclude_path "$BATS_ROOT/libexec/" exec 4<&1 # used for tracing if [[ "${BATS_TRACE_LEVEL:-0}" -gt 0 ]]; then # avoid undefined variable errors BATS_LAST_BASH_COMMAND= BATS_LAST_BASH_LINENO= BATS_LAST_BASH_SOURCE= BATS_LAST_STACK_DEPTH= # try to exclude helper libraries if found, this is only relevant for tracing while read -r path; do bats_add_debug_exclude_path "$path" done < <(find "$PWD" -type d -name bats-assert -o -name bats-support) fi # exclude user defined libraries IFS=':' read -r exclude_paths <<< "${BATS_DEBUG_EXCLUDE_PATHS:-}" for path in "${exclude_paths[@]}"; do if [[ -n "$path" ]]; then bats_add_debug_exclude_path "$path" fi done # turn on traps after setting excludedes to avoid tracing the exclude setup trap 'bats_debug_trap "$BASH_SOURCE"' DEBUG trap 'bats_error_trap' ERR }PK )8�\�90 validator.bashnu ȯ�� #!/usr/bin/bash bats_test_count_validator() { trap '' INT # continue forwarding header_pattern='[0-9]+\.\.[0-9]+' IFS= read -r header # repeat the header printf "%s\n" "$header" # if we detect a TAP plan if [[ "$header" =~ $header_pattern ]]; then # extract the number of tests ... local expected_number_of_tests="${header:3}" # ... count the actual number of [not ] oks... local actual_number_of_tests=0 while IFS= read -r line; do # forward line printf "%s\n" "$line" case "$line" in 'ok '*) (( ++actual_number_of_tests )) ;; 'not ok'*) (( ++actual_number_of_tests )) ;; esac done # ... and error if they are not the same if [[ "${actual_number_of_tests}" != "${expected_number_of_tests}" ]]; then printf '# bats warning: Executed %s instead of expected %s tests\n' "$actual_number_of_tests" "$expected_number_of_tests" return 1 fi else # forward output unchanged cat fi }PK )8�\W��� � test_functions.bashnu ȯ�� #!/usr/bin/bash BATS_TEST_DIRNAME="${BATS_TEST_FILENAME%/*}" BATS_TEST_NAMES=() # Shorthand for source-ing files relative to the BATS_TEST_DIRNAME, # optionally with a .bash suffix appended. If the argument doesn't # resolve relative to BATS_TEST_DIRNAME it is sourced as-is. load() { local file="${1:?}" # For backwards-compatibility first look for a .bash-suffixed file. # TODO consider flipping the order here; it would be more consistent # and less surprising to look for an exact-match first. if [[ -f "${BATS_TEST_DIRNAME}/${file}.bash" ]]; then file="${BATS_TEST_DIRNAME}/${file}.bash" elif [[ -f "${BATS_TEST_DIRNAME}/${file}" ]]; then file="${BATS_TEST_DIRNAME}/${file}" fi if [[ ! -f "$file" ]] && ! type -P "$file" >/dev/null; then printf 'bats: %s does not exist\n' "$file" >&2 exit 1 fi # Dynamically loaded user file provided outside of Bats. # Note: 'source "$file" || exit' doesn't work on bash3.2. # shellcheck disable=SC1090 source "${file}" } bats_redirect_stderr_into_file() { "$@" 2>>"$bats_run_separate_stderr_file" # use >> to see collisions' content } bats_merge_stdout_and_stderr() { "$@" 2>&1 } # write separate lines from <input-var> into <output-array> bats_separate_lines() { # <output-array> <input-var> output_array_name="$1" input_var_name="$2" if [[ $keep_empty_lines ]]; then local bats_separate_lines_lines=() while IFS= read -r line; do bats_separate_lines_lines+=("$line") done <<<"${!input_var_name}" eval "${output_array_name}=(\"\${bats_separate_lines_lines[@]}\")" else # shellcheck disable=SC2034,SC2206 IFS=$'\n' read -d '' -r -a "$output_array_name" <<<"${!input_var_name}" fi } run() { # [!|-N] [--keep-empty-lines] [--separate-stderr] [--] <command to run...> trap bats_interrupt_trap_in_run INT local expected_rc= local keep_empty_lines= local output_case=merged # parse options starting with - while [[ $# -gt 0 ]] && [[ $1 == -* || $1 == '!' ]]; do case "$1" in '!') expected_rc=-1 ;; -[0-9]*) expected_rc=${1#-} if [[ $expected_rc =~ [^0-9] ]]; then printf "Usage error: run: '=NNN' requires numeric NNN (got: %s)\n" "$expected_rc" >&2 return 1 elif [[ $expected_rc -gt 255 ]]; then printf "Usage error: run: '=NNN': NNN must be <= 255 (got: %d)\n" "$expected_rc" >&2 return 1 fi ;; --keep-empty-lines) keep_empty_lines=1 ;; --separate-stderr) output_case="separate" ;; --) shift # eat the -- before breaking away break ;; esac shift done local pre_command= case "$output_case" in merged) # redirects stderr into stdout and fills only $output/$lines pre_command=bats_merge_stdout_and_stderr ;; separate) # splits stderr into own file and fills $stderr/$stderr_lines too local bats_run_separate_stderr_file bats_run_separate_stderr_file="$(mktemp "${BATS_TEST_TMPDIR}/separate-stderr-XXXXXX")" pre_command=bats_redirect_stderr_into_file ;; esac local origFlags="$-" set +eET local origIFS="$IFS" status=0 if [[ $keep_empty_lines ]]; then # 'output', 'status', 'lines' are global variables available to tests. # preserve trailing newlines by appending . and removing it later # shellcheck disable=SC2034 output="$($pre_command "$@"; status=$?; printf .; exit $status)" || status="$?" output="${output%.}" else # 'output', 'status', 'lines' are global variables available to tests. # shellcheck disable=SC2034 output="$($pre_command "$@")" || status="$?" fi bats_separate_lines lines output if [[ "$output_case" == separate ]]; then # shellcheck disable=SC2034 read -d '' -r stderr < "$bats_run_separate_stderr_file" bats_separate_lines stderr_lines stderr fi # shellcheck disable=SC2034 BATS_RUN_COMMAND="${*}" IFS="$origIFS" set "-$origFlags" if [[ ${BATS_VERBOSE_RUN:-} ]]; then printf "%s\n" "$output" fi if [[ -n "$expected_rc" ]]; then if [[ "$expected_rc" = "-1" ]]; then if [[ "$status" -eq 0 ]]; then bats_capture_stack_trace # fix backtrace BATS_ERROR_SUFFIX=", expected nonzero exit code!" return 1 fi elif [ "$status" -ne "$expected_rc" ]; then bats_capture_stack_trace # fix backtrace # shellcheck disable=SC2034 BATS_ERROR_SUFFIX=", expected exit code $expected_rc, got $status" return 1 fi fi } setup() { return 0 } teardown() { return 0 } skip() { # if this is a skip in teardown ... if [[ -n "${BATS_TEARDOWN_STARTED-}" ]]; then # ... we want to skip the rest of teardown. # communicate to bats_exit_trap that the teardown was completed without error # shellcheck disable=SC2034 BATS_TEARDOWN_COMPLETED=1 # if we are already in the exit trap (e.g. due to previous skip) ... if [[ "$BATS_TEARDOWN_STARTED" == as-exit-trap ]]; then # ... we need to do the rest of the tear_down_trap that would otherwise be skipped after the next call to exit bats_exit_trap # and then do the exit (at the end of this function) fi # if we aren't in exit trap, the normal exit handling should suffice else # ... this is either skip in test or skip in setup. # Following variables are used in bats-exec-test which sources this file # shellcheck disable=SC2034 BATS_TEST_SKIPPED="${1:-1}" # shellcheck disable=SC2034 BATS_TEST_COMPLETED=1 fi exit 0 } bats_test_begin() { BATS_TEST_DESCRIPTION="$1" if [[ -n "$BATS_EXTENDED_SYNTAX" ]]; then printf 'begin %d %s\n' "$BATS_SUITE_TEST_NUMBER" "$BATS_TEST_DESCRIPTION" >&3 fi setup } bats_test_function() { local test_name="$1" BATS_TEST_NAMES+=("$test_name") } PK )8�\�9��� � preprocessing.bashnu ȯ�� #!/usr/bin/bash BATS_TMPNAME="$BATS_RUN_TMPDIR/bats.$$" BATS_PARENT_TMPNAME="$BATS_RUN_TMPDIR/bats.$PPID" # shellcheck disable=SC2034 BATS_OUT="${BATS_TMPNAME}.out" # used in bats-exec-file bats_preprocess_source() { # export to make it visible to bats_evaluate_preprocessed_source # since the latter runs in bats-exec-test's bash while this runs in bats-exec-file's export BATS_TEST_SOURCE="${BATS_TMPNAME}.src" bats-preprocess "$BATS_TEST_FILENAME" >"$BATS_TEST_SOURCE" } bats_evaluate_preprocessed_source() { if [[ -z "${BATS_TEST_SOURCE:-}" ]]; then BATS_TEST_SOURCE="${BATS_PARENT_TMPNAME}.src" fi # Dynamically loaded user files provided outside of Bats. # shellcheck disable=SC1090 source "$BATS_TEST_SOURCE" } PK )8�\��7�� � semaphore.bashnu ȯ�� #!/usr/bin/bash # setup the semaphore environment for the loading file bats_semaphore_setup() { export -f bats_semaphore_get_free_slot_count export -f bats_semaphore_acquire_while_locked export BATS_SEMAPHORE_DIR="$BATS_RUN_TMPDIR/semaphores" if command -v flock >/dev/null; then bats_run_under_lock() { flock "$BATS_SEMAPHORE_DIR" "$@" } elif command -v shlock >/dev/null; then bats_run_under_lock() { local lockfile="$BATS_SEMAPHORE_DIR/shlock.lock" while ! shlock -p $$ -f "$lockfile"; do sleep 1 done # we got the lock now, execute the command "$@" local status=$? # free the lock rm -f "$lockfile" return $status } else printf "ERROR: flock/shlock is required for parallelization within files!\n" >&2 exit 1 fi } # $1 - output directory for stdout/stderr # $@ - command to run # run the given command in a semaphore # block when there is no free slot for the semaphore # when there is a free slot, run the command in background # gather the output of the command in files in the given directory bats_semaphore_run() { local output_dir=$1 shift local semaphore_slot semaphore_slot=$(bats_semaphore_acquire_slot) bats_semaphore_release_wrapper "$output_dir" "$semaphore_slot" "$@" & printf "%d\n" "$!" } # $1 - output directory for stdout/stderr # $@ - command to run # this wraps the actual function call to install some traps on exiting bats_semaphore_release_wrapper() { local output_dir="$1" local semaphore_name="$2" shift 2 # all other parameters will be use for the command to execute # shellcheck disable=SC2064 # we want to expand the semaphore_name right now! trap "status=$?; bats_semaphore_release_slot '$semaphore_name'; exit $status" EXIT mkdir -p "$output_dir" "$@" 2>"$output_dir/stderr" >"$output_dir/stdout" local status=$? # bash bug: the exit trap is not called for the background process bats_semaphore_release_slot "$semaphore_name" trap - EXIT # avoid calling release twice return $status } bats_semaphore_acquire_while_locked() { if [[ $(bats_semaphore_get_free_slot_count) -gt 0 ]]; then local slot=0 while [[ -e "$BATS_SEMAPHORE_DIR/slot-$slot" ]]; do (( ++slot )) done if [[ $slot -lt $BATS_SEMAPHORE_NUMBER_OF_SLOTS ]]; then touch "$BATS_SEMAPHORE_DIR/slot-$slot" && printf "%d\n" "$slot" && return 0 fi fi return 1 } # block until a semaphore slot becomes free # prints the number of the slot that it received bats_semaphore_acquire_slot() { mkdir -p "$BATS_SEMAPHORE_DIR" # wait for a slot to become free # TODO: avoid busy waiting by using signals -> this opens op prioritizing possibilities as well while true; do # don't lock for reading, we are fine with spuriously getting no free slot if [[ $(bats_semaphore_get_free_slot_count) -gt 0 ]]; then bats_run_under_lock bash -c bats_semaphore_acquire_while_locked && break fi sleep 1 done } bats_semaphore_release_slot() { # we don't need to lock this, since only our process owns this file # and freeing a semaphore cannot lead to conflicts with others rm "$BATS_SEMAPHORE_DIR/slot-$1" # this will fail if we had not aqcuired a semaphore! } bats_semaphore_get_free_slot_count() { # find might error out without returning something useful when a file is deleted, # while the directory is traversed -> only continue when there was no error until used_slots=$(find "$BATS_SEMAPHORE_DIR" -name 'slot-*' 2>/dev/null | wc -l); do :; done echo $(( BATS_SEMAPHORE_NUMBER_OF_SLOTS - used_slots )) } PK )8�\y� �� � formatter.bashnu ȯ�� PK )8�\8n�J common.bashnu ȯ�� PK )8�\e��_� � ] tracing.bashnu ȯ�� PK )8�\�90 r6 validator.bashnu ȯ�� PK )8�\W��� � �: test_functions.bashnu ȯ�� PK )8�\�9��� � �Q preprocessing.bashnu ȯ�� PK )8�\��7�� � U semaphore.bashnu ȯ�� PK & 7d
| ver. 1.4 |
Github
|
.
| PHP 8.4.23 | Generation time: 0 |
proxy
|
phpinfo
|
Settings