From ea45541d534447b3b95a1e95b59b913d631b51da Mon Sep 17 00:00:00 2001 From: Kurtis Rader Date: Wed, 16 Aug 2017 13:39:48 -0700 Subject: [PATCH] fix `set --show` of semi-empty var A semi-empty var is one with a single empty string element. The `env_var_t::empty()` method returns true for such vars but we want `set --show` to report that it has a single empty element. --- src/builtin_set.cpp | 2 +- tests/set.in | 3 +++ tests/set.out | 5 +++++ tests/test_cmdsub.out | 3 ++- 4 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/builtin_set.cpp b/src/builtin_set.cpp index 41ab75aeb..9d45f9e80 100644 --- a/src/builtin_set.cpp +++ b/src/builtin_set.cpp @@ -539,7 +539,7 @@ static void show_scope(const wchar_t *var_name, int scope, io_streams_t &streams const env_var_t var = env_get(var_name, scope | ENV_USER); wcstring_list_t result; - if (!var.empty()) var.to_list(result); + var.to_list(result); streams.out.append_format(_(L"$%ls: set in %ls scope, %ls, with %d elements\n"), var_name, scope_name, exportv, result.size()); diff --git a/tests/set.in b/tests/set.in index 74ddb9232..46415de69 100644 --- a/tests/set.in +++ b/tests/set.in @@ -4,6 +4,9 @@ logmsg Verify behavior of `set --show` given an invalid var name set --show 'argle bargle' logmsg Verify behavior of `set --show` +set semiempty '' +set --show semiempty + set -U var1 hello set --show var1 diff --git a/tests/set.out b/tests/set.out index b094b0107..561d24cea 100644 --- a/tests/set.out +++ b/tests/set.out @@ -4,6 +4,11 @@ #################### # Verify behavior of `set --show` +$semiempty: not set in local scope +$semiempty: set in global scope, unexported, with 1 elements +$semiempty[1]: length=0 value=|| +$semiempty: not set in universal scope + $var1: not set in local scope $var1: not set in global scope $var1: set in universal scope, unexported, with 1 elements diff --git a/tests/test_cmdsub.out b/tests/test_cmdsub.out index 26011ce4b..53872dc00 100644 --- a/tests/test_cmdsub.out +++ b/tests/test_cmdsub.out @@ -17,7 +17,8 @@ $b: not set in universal scope #################### # Command sub over the limit should fail $c: not set in local scope -$c: set in global scope, unexported, with 0 elements +$c: set in global scope, unexported, with 1 elements +$c[1]: length=0 value=|| $c: not set in universal scope