Skip to content

Commit

Permalink
v2.7.8 (#134)
Browse files Browse the repository at this point in the history
Minor updates
* Execute tests in parallel for speed
* Add option in bf handle to ignore success results
* Adding function to double-quote an input string
  • Loading branch information
bfren authored Dec 2, 2024
1 parent 7774c50 commit 8d2b92c
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 12 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.7.7
2.7.8
17 changes: 13 additions & 4 deletions overlay/etc/nu/scripts/bf/handle.nu
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,14 @@ use dump.nu
# - **this option overrides all others**
#
# ```nu
# > { ^external } | bf handle --ignore-errors
# > { ^external } | bf handle --ignore-success
# ```
# - `external` will be run using `do { } | complete`, capturing the exit code, stdout and stderr
# - if exit code is 0, stdout will be discarded - it is the equivalent of `--on-success {|out| $out | ignore }`
# - **this option overrides `--dump-result` and `--on-success`**
#
# ```nu
# > { ^external } | bf handle --ignore-error
# ```
# - `external` will be run using `do { } | complete`, capturing the exit code, stdout and stderr
# - whatever the exit code is, stdout will be trimmed and returned
Expand Down Expand Up @@ -48,7 +55,8 @@ export def main [
--code-only (-c) # If set, only the exit code will be returned - overrides all other options
--debug (-D) # If set, the result object will be dumped immediately before any processing
--dump-result (-d): string # On error, dump the full $result object with this text
--ignore-errors (-i) # If set, any errors will be ignored and $result.stdout will be returned whatever it is
--ignore-error (-i) # If set, any errors will be ignored and $result.stdout will be returned
--ignore-success (-I) # If set, a successful $result will be discarded
--on-failure (-f): closure # On failure, optionally run this closure with $code and $stderr as inputs
--on-success (-s): closure # On success, optionally run this closure with $stdout as input
]: closure -> any {
Expand All @@ -61,13 +69,14 @@ export def main [
# return exit code
if $code_only { return $result.exit_code }

# on success, run closure (if it has been set) and return
# if ignoring success, return nothing - otherwise, run closure (if it has been set) and return
if $result.exit_code == 0 {
if $ignore_success { return }
if ($on_success | is-not-empty) { do $on_success $result.stdout } else { $result.stdout | str trim } | return $in
}

# if ignoring errors, return the $result.stdout string
if $ignore_errors { $result.stdout | str trim | return $in }
if $ignore_error { $result.stdout | str trim | return $in }

# if we get here, the operation failed
# if $dump_result flag is set, dump the $result object (it won't show unless BF_DEBUG is 1)
Expand Down
3 changes: 3 additions & 0 deletions overlay/etc/nu/scripts/bf/string.nu
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use dump.nu
use write.nu

# Add double quotes to the input string and return.
export def quote []: string -> string { $"\"($in)\"" }

# Format a string by using $values to replace placeholders with values within $input:
# - if $values = {a: "one" b: "two"}
# - and $input = "this contains {a} and {b}"
Expand Down
17 changes: 10 additions & 7 deletions overlay/etc/nu/scripts/bf/test.nu
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@ use write.nu

# Execute tests with debug switch enabled
# Inspired by https://github.com/nushell/nupm/blob/main/nupm/test.nu to work in this ecosystem
export def main [] {
let path = "/usr/bin/bf:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
with-env { BF_DEBUG: 1, PATH: $path } {
discover | execute
export def main [
--path: string # dir(s) to include with default PATH - MUST end with a colon ':'
] {
let e = {
BF_DEBUG: "1"
PATH: $"($path)/usr/bin/bf:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
}
with-env $e { discover | execute }
}

# Discover tests to execute
Expand Down Expand Up @@ -45,10 +48,10 @@ def discover [] {
$tests
}

# Execute each discovered test
# Execute each discovered test in parallel
# WARNING: this means tests need to be self-contained as the execution order cannot be guaranteed
def execute []: list<string> -> any {
# execute each test
let results = $in | sort | each {|x|
let results = $in | sort | par-each {|x|
# capture result
let result = do { ^nu -c $"use tests * ; ($x)" } | complete

Expand Down

0 comments on commit 8d2b92c

Please sign in to comment.