Unverified Commit 357d4653 authored by MatteoPologruto's avatar MatteoPologruto Committed by GitHub

Include platform bundled libs when `-b` flag is used (#2000)

* Show bundled libs when `-b` flag is used

* Modify test_lib.go to test the changes
parent 13fa409c
......@@ -48,8 +48,9 @@ func LibraryList(ctx context.Context, req *rpc.LibraryListRequest) (*rpc.Library
nameFilter := strings.ToLower(req.GetName())
allLibs := listLibraries(lm, req.GetUpdatable(), req.GetAll())
var allLibs []*installedLib
if f := req.GetFqbn(); f != "" {
allLibs = listLibraries(lm, req.GetUpdatable(), true)
fqbn, err := cores.ParseFQBN(req.GetFqbn())
if err != nil {
return nil, &arduino.InvalidFQBNError{Cause: err}
......@@ -93,6 +94,8 @@ func LibraryList(ctx context.Context, req *rpc.LibraryListRequest) (*rpc.Library
for _, lib := range filteredRes {
allLibs = append(allLibs, lib)
}
} else {
allLibs = listLibraries(lm, req.GetUpdatable(), req.GetAll())
}
installedLibs := []*rpc.InstalledLibrary{}
......
......@@ -421,7 +421,7 @@ func TestListWithFqbn(t *testing.T) {
require.NoError(t, err)
// Install core
_, _, err = cli.Run("core", "install", "arduino:avr")
_, _, err = cli.Run("core", "install", "arduino:avr@1.8.6")
require.NoError(t, err)
// Look at the plain text output
......@@ -434,8 +434,12 @@ func TestListWithFqbn(t *testing.T) {
stdout, stderr, err := cli.Run("lib", "list", "-b", "arduino:avr:uno")
require.NoError(t, err)
require.Empty(t, stderr)
// Check if output contains bundled libraries
require.Contains(t, string(stdout), "ArduinoJson")
require.Contains(t, string(stdout), "EEPROM")
require.Contains(t, string(stdout), "HID")
lines := strings.Split(strings.TrimSpace(string(stdout)), "\n")
require.Len(t, lines, 2)
require.Len(t, lines, 7)
// Verifies library is compatible
lines[1] = strings.Join(strings.Fields(lines[1]), " ")
......@@ -447,11 +451,14 @@ func TestListWithFqbn(t *testing.T) {
stdout, stderr, err = cli.Run("lib", "list", "-b", "arduino:avr:uno", "--format", "json")
require.NoError(t, err)
require.Empty(t, stderr)
requirejson.Len(t, stdout, 1)
requirejson.Len(t, stdout, 6)
// Verifies library is compatible
requirejson.Query(t, stdout, `.[0] | .library | .name`, `"ArduinoJson"`)
requirejson.Query(t, stdout, `.[0] | .library | .compatible_with | ."arduino:avr:uno"`, `true`)
requirejson.Query(t, stdout, `sort_by(.library | .name) | .[0] | .library | .name`, `"ArduinoJson"`)
requirejson.Query(t, stdout, `sort_by(.library | .name) | .[0] | .library | .compatible_with | ."arduino:avr:uno"`, `true`)
// Verifies bundled libs are shown if -b flag is used
requirejson.Parse(t, stdout).Query(`.[] | .library | select(.container_platform=="arduino:avr@1.8.6")`).MustNotBeEmpty()
}
func TestListProvidesIncludesFallback(t *testing.T) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment