From 93c0d3f4a58ee128624309ce91342f00cd87343c Mon Sep 17 00:00:00 2001 From: Fabian Homborg Date: Fri, 1 Feb 2019 18:29:54 +0100 Subject: [PATCH] `functions -q`: Return false without an argument This erroneously listed functions and returned true. --- src/builtin_functions.cpp | 5 +++++ tests/function.err | 3 +++ tests/function.in | 3 +++ tests/function.out | 4 ++++ 4 files changed, 15 insertions(+) diff --git a/src/builtin_functions.cpp b/src/builtin_functions.cpp index 8b5b16d97..42575b503 100644 --- a/src/builtin_functions.cpp +++ b/src/builtin_functions.cpp @@ -337,6 +337,11 @@ int builtin_functions(parser_t &parser, io_streams_t &streams, wchar_t **argv) { return STATUS_CMD_OK; } + // If we query with no argument, just return false. + if (opts.query && argc == optind) { + return STATUS_CMD_ERROR; + } + if (opts.list || argc == optind) { wcstring_list_t names = function_get_names(opts.show_hidden); std::sort(names.begin(), names.end()); diff --git a/tests/function.err b/tests/function.err index 2d69cbb05..7257df763 100644 --- a/tests/function.err +++ b/tests/function.err @@ -29,3 +29,6 @@ fish: function: The name 'test' is reserved, and can not be used as a function name function test; echo banana; end ^ + +#################### +# Checking `functions -q` without arguments diff --git a/tests/function.in b/tests/function.in index 5f64ed777..a774167e4 100644 --- a/tests/function.in +++ b/tests/function.in @@ -48,4 +48,7 @@ diff (functions name3 | psub) (functions name3a | psub) logmsg Checking reserved names function test; echo banana; end + +logmsg Checking `functions -q` without arguments +functions -q; or echo "False" exit 0 diff --git a/tests/function.out b/tests/function.out index 95a79ed2f..6cfd7379e 100644 --- a/tests/function.out +++ b/tests/function.out @@ -73,3 +73,7 @@ Function name4 not found as expected #################### # Checking reserved names + +#################### +# Checking `functions -q` without arguments +False