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
14 changes: 9 additions & 5 deletions nu/tests.nu
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,13 @@ def run_test [test: record<name: string, execute: closure>]: nothing -> record<n
}

def format_error [error: string] {
$error
# Get the value for the text key in a partly non-json error message
# Get the value for the text key in a partly non-json error message
let parsed = $error
| parse --regex ".+text: \"(.+)\""
if ($parsed | is-empty) {
return ''
}
$parsed
| first
| get capture0
| str replace --all --regex "\\\\n" " "
Expand All @@ -101,7 +105,7 @@ def "test Nu version is correct" [] {

def "test nu is added as a shell" [] {
cat /etc/shells | print
let shell = cat /etc/shells
let shell = open /etc/shells
| lines
| where ($it | str contains "nu")
| first
Expand All @@ -110,12 +114,12 @@ def "test nu is added as a shell" [] {
}

def 'test nu is not the only shell' [] {
let shells = cat /etc/shells
let shells = open /etc/shells
| lines
| where not ($it | str contains "nu")
| length

assert greater $shells 1
assert greater $shells 0
}

def "test main plugins are installed" [] {
Expand Down
14 changes: 11 additions & 3 deletions scripts/post-install.nu
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,18 @@ def 'setup-plugins' [] {

# Add /usr/bin/nu to /etc/shells if it's not already there
def 'add-shells' [] {
let shells = open /etc/shells
if not ($shells =~ $'/usr/bin/nu') {
echo $'/usr/bin/nu(char nl)' o>> /etc/shells
let content = open /etc/shells
const nu_bin = '/usr/bin/nu'
if ($content | str contains $nu_bin) {
return
}
mut $new_line = $"($nu_bin)\n"
# Handle edge case when the content doesn't have ending newline,
# blindly appending the $new_line will end up writing to the same line.
if not ($content | str ends-with "\n") {
$new_line = "\n" ++ $new_line
}
echo $new_line o>> /etc/shells
}

def main [] {
Expand Down
6 changes: 4 additions & 2 deletions scripts/pre-remove.nu
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@

# Remove /usr/bin/nu from /etc/shells
def 'remove-nu-from-shells' [] {
open /etc/shells
let new_content = open /etc/shells
| lines
| where $it !~ '/usr/bin/nu'
| str join "\n"
| save -rf /etc/shells
# Keep a new line at the end of file to prevent other packages from making mistake
# when modifying this file.
$new_content ++ "\n" | save -rf /etc/shells
}

def main [] {
Expand Down