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 ...@@ -48,8 +48,9 @@ func LibraryList(ctx context.Context, req *rpc.LibraryListRequest) (*rpc.Library
nameFilter := strings.ToLower(req.GetName()) nameFilter := strings.ToLower(req.GetName())
allLibs := listLibraries(lm, req.GetUpdatable(), req.GetAll()) var allLibs []*installedLib
if f := req.GetFqbn(); f != "" { if f := req.GetFqbn(); f != "" {
allLibs = listLibraries(lm, req.GetUpdatable(), true)
fqbn, err := cores.ParseFQBN(req.GetFqbn()) fqbn, err := cores.ParseFQBN(req.GetFqbn())
if err != nil { if err != nil {
return nil, &arduino.InvalidFQBNError{Cause: err} return nil, &arduino.InvalidFQBNError{Cause: err}
...@@ -93,6 +94,8 @@ func LibraryList(ctx context.Context, req *rpc.LibraryListRequest) (*rpc.Library ...@@ -93,6 +94,8 @@ func LibraryList(ctx context.Context, req *rpc.LibraryListRequest) (*rpc.Library
for _, lib := range filteredRes { for _, lib := range filteredRes {
allLibs = append(allLibs, lib) allLibs = append(allLibs, lib)
} }
} else {
allLibs = listLibraries(lm, req.GetUpdatable(), req.GetAll())
} }
installedLibs := []*rpc.InstalledLibrary{} installedLibs := []*rpc.InstalledLibrary{}
......
...@@ -421,7 +421,7 @@ func TestListWithFqbn(t *testing.T) { ...@@ -421,7 +421,7 @@ func TestListWithFqbn(t *testing.T) {
require.NoError(t, err) require.NoError(t, err)
// Install core // Install core
_, _, err = cli.Run("core", "install", "arduino:avr") _, _, err = cli.Run("core", "install", "arduino:avr@1.8.6")
require.NoError(t, err) require.NoError(t, err)
// Look at the plain text output // Look at the plain text output
...@@ -434,8 +434,12 @@ func TestListWithFqbn(t *testing.T) { ...@@ -434,8 +434,12 @@ func TestListWithFqbn(t *testing.T) {
stdout, stderr, err := cli.Run("lib", "list", "-b", "arduino:avr:uno") stdout, stderr, err := cli.Run("lib", "list", "-b", "arduino:avr:uno")
require.NoError(t, err) require.NoError(t, err)
require.Empty(t, stderr) 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") lines := strings.Split(strings.TrimSpace(string(stdout)), "\n")
require.Len(t, lines, 2) require.Len(t, lines, 7)
// Verifies library is compatible // Verifies library is compatible
lines[1] = strings.Join(strings.Fields(lines[1]), " ") lines[1] = strings.Join(strings.Fields(lines[1]), " ")
...@@ -447,11 +451,14 @@ func TestListWithFqbn(t *testing.T) { ...@@ -447,11 +451,14 @@ func TestListWithFqbn(t *testing.T) {
stdout, stderr, err = cli.Run("lib", "list", "-b", "arduino:avr:uno", "--format", "json") stdout, stderr, err = cli.Run("lib", "list", "-b", "arduino:avr:uno", "--format", "json")
require.NoError(t, err) require.NoError(t, err)
require.Empty(t, stderr) require.Empty(t, stderr)
requirejson.Len(t, stdout, 1) requirejson.Len(t, stdout, 6)
// Verifies library is compatible // Verifies library is compatible
requirejson.Query(t, stdout, `.[0] | .library | .name`, `"ArduinoJson"`) requirejson.Query(t, stdout, `sort_by(.library | .name) | .[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 | .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) { 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