mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-05-07 23:41:15 -03:00
functions --copy: store file and lineno (#9542)
Keeps the location of original function definition, and also stores where it was copied. `functions` and `type` show both locations, instead of none. It also retains the line numbers in the stack trace.
This commit is contained in:
@@ -99,12 +99,26 @@ set -l name1 (functions name1)
|
||||
set -l name1a (functions name1a)
|
||||
set -l name3 (functions name3)
|
||||
set -l name3a (functions name3a)
|
||||
# First line for the non-copied function is "# Defined in checks/function.fish" - skip it to work around #6575.
|
||||
# First two lines for the copied and non-copied functions are different. Skip it for now.
|
||||
test "$name1[3..-1]" = "$name1a[3..-1]"; and echo "1 = 1a"
|
||||
#CHECK: 1 = 1a
|
||||
test "$name3[3..-1]" = "$name3a[3..-1]"; and echo "3 = 3a"
|
||||
#CHECK: 3 = 3a
|
||||
|
||||
# Test the first two lines.
|
||||
string join \n -- $name1[1..2]
|
||||
#CHECK: # Defined in {{(?:(?!, copied).)*}}
|
||||
#CHECK: function name1 --argument arg1 arg2
|
||||
string join \n -- $name1a[1..2]
|
||||
#CHECK: # Defined in {{.*}}, copied in {{.*}}
|
||||
#CHECK: function name1a --argument arg1 arg2
|
||||
string join \n -- $name3[1..2]
|
||||
#CHECK: # Defined in {{(?:(?!, copied).)*}}
|
||||
#CHECK: function name3 --argument arg1 arg2
|
||||
string join \n -- $name3a[1..2]
|
||||
#CHECK: # Defined in {{.*}}, copied in {{.*}}
|
||||
#CHECK: function name3a --argument arg1 arg2
|
||||
|
||||
function test
|
||||
echo banana
|
||||
end
|
||||
|
||||
@@ -54,6 +54,28 @@ if test $x[5] != 'line 1\\\\n\\nline 2 & more; way more'
|
||||
echo "Unexpected output for 'functions -v -D multiline_descr': $x" >&2
|
||||
end
|
||||
|
||||
# ==========
|
||||
# Verify that `functions --details` works as expected when given the name of a
|
||||
# function that is copied. (Prints the filename where it was copied.)
|
||||
functions -c f1 f1a
|
||||
functions -D f1a
|
||||
#CHECK: {{.*}}checks/functions.fish
|
||||
functions -Dv f1a
|
||||
#CHECK: {{.*}}checks/functions.fish
|
||||
#CHECK: {{.*}}checks/functions.fish
|
||||
#CHECK: {{\d+}}
|
||||
#CHECK: scope-shadowing
|
||||
#CHECK:
|
||||
echo "functions -c f1 f1b" | source
|
||||
functions -D f1b
|
||||
#CHECK: -
|
||||
functions -Dv f1b
|
||||
#CHECK: -
|
||||
#CHECK: {{.*}}checks/functions.fish
|
||||
#CHECK: {{\d+}}
|
||||
#CHECK: scope-shadowing
|
||||
#CHECK:
|
||||
|
||||
# ==========
|
||||
# Verify function description setting
|
||||
function test_func_desc
|
||||
@@ -106,6 +128,41 @@ functions --no-details t
|
||||
# CHECK: echo tttt;
|
||||
# CHECK: end
|
||||
|
||||
functions -c t t2
|
||||
functions t2
|
||||
# CHECK: # Defined via `source`, copied in {{.*}}checks/functions.fish @ line {{\d+}}
|
||||
# CHECK: function t2
|
||||
# CHECK: echo tttt;
|
||||
# CHECK: end
|
||||
functions -D t2
|
||||
#CHECK: {{.*}}checks/functions.fish
|
||||
functions -Dv t2
|
||||
#CHECK: {{.*}}checks/functions.fish
|
||||
#CHECK: -
|
||||
#CHECK: {{\d+}}
|
||||
#CHECK: scope-shadowing
|
||||
#CHECK:
|
||||
|
||||
echo "functions -c t t3" | source
|
||||
functions t3
|
||||
# CHECK: # Defined via `source`, copied via `source`
|
||||
# CHECK: function t3
|
||||
# CHECK: echo tttt;
|
||||
# CHECK: end
|
||||
functions -D t3
|
||||
#CHECK: -
|
||||
functions -Dv t3
|
||||
#CHECK: -
|
||||
#CHECK: -
|
||||
#CHECK: {{\d+}}
|
||||
#CHECK: scope-shadowing
|
||||
#CHECK:
|
||||
|
||||
functions --no-details t2
|
||||
# CHECK: function t2
|
||||
# CHECK: echo tttt;
|
||||
# CHECK: end
|
||||
|
||||
functions --no-details --details t
|
||||
# CHECKERR: functions: invalid option combination
|
||||
# CHECKERR:
|
||||
|
||||
@@ -105,3 +105,24 @@ end
|
||||
# CHECK: Failed write tests {{finished|skipped}}
|
||||
# CHECKERR: write: {{.*}}
|
||||
# CHECKERR: write: {{.*}}
|
||||
|
||||
function test-stack-trace-main
|
||||
status stack-trace
|
||||
end
|
||||
|
||||
function test-stack-trace-other
|
||||
test-stack-trace-main
|
||||
end
|
||||
|
||||
printf "%s\n" (test-stack-trace-other | string replace \t '<TAB>')[1..4]
|
||||
# CHECK: in function 'test-stack-trace-main'
|
||||
# CHECK: <TAB>called on line {{\d+}} of file {{.*}}/status.fish
|
||||
# CHECK: in function 'test-stack-trace-other'
|
||||
# CHECK: <TAB>called on line {{\d+}} of file {{.*}}/status.fish
|
||||
|
||||
functions -c test-stack-trace-other test-stack-trace-copy
|
||||
printf "%s\n" (test-stack-trace-copy | string replace \t '<TAB>')[1..4]
|
||||
# CHECK: in function 'test-stack-trace-main'
|
||||
# CHECK: <TAB>called on line {{\d+}} of file {{.*}}/status.fish
|
||||
# CHECK: in function 'test-stack-trace-copy'
|
||||
# CHECK: <TAB>called on line {{\d+}} of file {{.*}}/status.fish
|
||||
|
||||
@@ -61,7 +61,7 @@ type -p alias
|
||||
# CHECK: {{.*}}/alias.fish
|
||||
|
||||
type -s alias
|
||||
# CHECK: alias is a function (defined in {{.*}}/alias.fish)
|
||||
# CHECK: alias is a function (Defined in {{.*}}/alias.fish @ line {{\d+}})
|
||||
|
||||
function test-type
|
||||
echo this is a type test
|
||||
@@ -76,3 +76,61 @@ type test-type
|
||||
|
||||
type -p test-type
|
||||
# CHECK: {{.*}}/type.fish
|
||||
|
||||
functions -c test-type test-type2
|
||||
type test-type2
|
||||
# CHECK: test-type2 is a function with definition
|
||||
# CHECK: # Defined in {{.*}}/type.fish @ line {{\d+}}, copied in {{.*}}/type.fish @ line {{\d+}}
|
||||
# CHECK: function test-type2
|
||||
# CHECK: echo this is a type test
|
||||
# CHECK: end
|
||||
|
||||
type -p test-type2
|
||||
# CHECK: {{.*}}/type.fish
|
||||
|
||||
type -s test-type2
|
||||
# CHECK: test-type2 is a function (Defined in {{.*}}/type.fish @ line {{\d+}}, copied in {{.*}}/type.fish @ line {{\d+}})
|
||||
|
||||
echo "functions -c test-type test-type3" | source
|
||||
type test-type3
|
||||
# CHECK: test-type3 is a function with definition
|
||||
# CHECK: # Defined in {{.*}}/type.fish @ line {{\d+}}, copied via `source`
|
||||
# CHECK: function test-type3
|
||||
# CHECK: echo this is a type test
|
||||
# CHECK: end
|
||||
|
||||
type -p test-type3
|
||||
# CHECK: -
|
||||
|
||||
type -s test-type3
|
||||
# CHECK: test-type3 is a function (Defined in {{.*}}/type.fish @ line {{\d+}}, copied via `source`)
|
||||
|
||||
echo "function other-test-type; echo this is a type test; end" | source
|
||||
|
||||
functions -c other-test-type other-test-type2
|
||||
type other-test-type2
|
||||
# CHECK: other-test-type2 is a function with definition
|
||||
# CHECK: # Defined via `source`, copied in {{.*}}/type.fish @ line {{\d+}}
|
||||
# CHECK: function other-test-type2
|
||||
# CHECK: echo this is a type test;
|
||||
# CHECK: end
|
||||
|
||||
type -p other-test-type2
|
||||
# CHECK: {{.*}}/type.fish
|
||||
|
||||
type -s other-test-type2
|
||||
# CHECK: other-test-type2 is a function (Defined via `source`, copied in {{.*}}/type.fish @ line {{\d+}})
|
||||
|
||||
echo "functions -c other-test-type other-test-type3" | source
|
||||
type other-test-type3
|
||||
# CHECK: other-test-type3 is a function with definition
|
||||
# CHECK: # Defined via `source`, copied via `source`
|
||||
# CHECK: function other-test-type3
|
||||
# CHECK: echo this is a type test;
|
||||
# CHECK: end
|
||||
|
||||
type -p other-test-type3
|
||||
# CHECK: -
|
||||
|
||||
type -s other-test-type3
|
||||
# CHECK: other-test-type3 is a function (Defined via `source`, copied via `source`)
|
||||
|
||||
Reference in New Issue
Block a user