From 4ec3bc5318e28b239a4e5be0e8c17dcd1f4d378c Mon Sep 17 00:00:00 2001 From: Massimiliano Pippi Date: Wed, 11 Dec 2019 17:53:16 +0100 Subject: [PATCH 1/2] add test for #443 --- test/test_lib.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/test/test_lib.py b/test/test_lib.py index 6323e849e66..654c5e6cc97 100644 --- a/test/test_lib.py +++ b/test/test_lib.py @@ -70,13 +70,21 @@ def test_update_index(run_command): ) -def test_remove(run_command): - libs = ['"AzureIoTProtocol_MQTT"', '"CMMC MQTT Connector"', '"WiFiNINA"'] +def test_uninstall(run_command): + libs = ['"AzureIoTProtocol_MQTT"', '"WiFiNINA"'] assert run_command("lib install {}".format(" ".join(libs))) result = run_command("lib uninstall {}".format(" ".join(libs))) assert result.ok +def test_uninstall_spaces(run_command): + key = '"LiquidCrystal I2C"' + assert run_command("lib install {}".format(key)) + assert run_command("lib uninstall {}".format(key)) + result = run_command("lib list --format json") + assert result.ok + assert len(json.loads(result.stdout)) == 0 + def test_search(run_command): assert run_command("lib update-index") From fbfdbf13ef5bdcd3731ac17f34634fcc1249a93a Mon Sep 17 00:00:00 2001 From: Massimiliano Pippi Date: Wed, 11 Dec 2019 18:11:47 +0100 Subject: [PATCH 2/2] return an empty json array when there are no libs --- cli/lib/list.go | 8 +++++++- test/test_lib.py | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/cli/lib/list.go b/cli/lib/list.go index 495174caf0f..0454d2cd15a 100644 --- a/cli/lib/list.go +++ b/cli/lib/list.go @@ -65,8 +65,14 @@ func runListCommand(cmd *cobra.Command, args []string) { } libs := res.GetInstalledLibrary() - feedback.PrintResult(installedResult{libs}) + // To uniform the output to other commands, when there are no result + // print out an empty slice. + if libs == nil { + libs = []*rpc.InstalledLibrary{} + } + + feedback.PrintResult(installedResult{libs}) logrus.Info("Done") } diff --git a/test/test_lib.py b/test/test_lib.py index 654c5e6cc97..eca85e1738b 100644 --- a/test/test_lib.py +++ b/test/test_lib.py @@ -27,7 +27,7 @@ def test_list(run_command): result = run_command("lib list --format json") assert result.ok assert "" == result.stderr - assert "null" == result.stdout + assert 0 == len(json.loads(result.stdout)) # Install something we can list at a version older than latest result = run_command("lib install ArduinoJson@6.11.0")