Skip to content

Change lib list --updatable output to be clearer if no lib is updatable #1053

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 3, 2020
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
3 changes: 3 additions & 0 deletions cli/lib/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ func (ir installedResult) Data() interface{} {

func (ir installedResult) String() string {
if ir.installedLibs == nil || len(ir.installedLibs) == 0 {
if listFlags.updatable {
return "No updates available."
}
return "No libraries installed."
}
sort.Slice(ir.installedLibs, func(i, j int) bool {
Expand Down
47 changes: 47 additions & 0 deletions test/test_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,3 +236,50 @@ def test_search_paragraph(run_command):
assert result.ok
libs_json = json.loads(result.stdout)
assert 1 == len(libs_json.get("libraries"))


def test_lib_list_with_updatable_flag(run_command):
# Init the environment explicitly
run_command("lib update-index")

# No libraries to update
result = run_command("lib list --updatable")
assert result.ok
assert "" == result.stderr
assert "No updates available." == result.stdout.strip()
# No library to update in json
result = run_command("lib list --updatable --format json")
assert result.ok
assert "" == result.stderr
assert 0 == len(json.loads(result.stdout))

# Install outdated library
assert run_command("lib install [email protected]")
# Install latest version of library
assert run_command("lib install WiFi101")

res = run_command("lib list --updatable")
assert res.ok
assert "" == res.stderr
# lines = res.stdout.strip().splitlines()
lines = [l.strip().split(maxsplit=4) for l in res.stdout.strip().splitlines()]
assert 2 == len(lines)
assert ["Name", "Installed", "Available", "Location", "Description"] in lines
line = lines[1]
assert "ArduinoJson" == line[0]
assert "6.11.0" == line[1]
# Verifies available version is not equal to installed one and not empty
assert "6.11.0" != line[2]
assert "" != line[2]
assert "An efficient and elegant JSON library..." == line[4]

# Look at the JSON output
res = run_command("lib list --updatable --format json")
assert res.ok
assert "" == res.stderr
data = json.loads(res.stdout)
assert 1 == len(data)
# be sure data contains the available version
assert "6.11.0" == data[0]["library"]["version"]
assert "6.11.0" != data[0]["release"]["version"]
assert "" != data[0]["release"]["version"]