Skip to content
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

Change lib deps CLI command output to sorted alphabetically #1934

Merged
merged 4 commits into from
Oct 21, 2022

Conversation

silvanocerza
Copy link
Contributor

Please check if the PR fulfills these requirements

See how to contribute

  • The PR has no duplicates (please search among the Pull Requests
    before creating one)
  • The PR follows
    our contributing guidelines
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)
  • UPGRADING.md has been updated with a migration guide (for breaking changes)

What kind of change does this PR introduce?

Enhances output of an existing command.

What is the current behavior?

lib deps command output is non deterministic and always changes on subsequent calls, both in plain text and JSON.

$ ino lib deps Arduino_ConnectionHandler
✕ Arduino_ConnectionHandler 0.6.5 deve essere installato.
✕ Arduino_DebugUtils 1.1.0 deve essere installato.
✓ WiFi101 0.16.1 è già installato.
✕ WiFiNINA 1.8.13 deve essere installato.
✕ MKRGSM 1.5.0 deve essere installato.
✕ MKRNB 1.5.1 deve essere installato.
✓ MKRWAN 1.1.0 è già installato.

$ ino lib deps Arduino_ConnectionHandler
✕ MKRNB 1.5.1 deve essere installato.
✓ MKRWAN 1.1.0 è già installato.
✕ Arduino_ConnectionHandler 0.6.5 deve essere installato.
✕ Arduino_DebugUtils 1.1.0 deve essere installato.
✓ WiFi101 0.16.1 è già installato.
✕ WiFiNINA 1.8.13 deve essere installato.
✕ MKRGSM 1.5.0 deve essere installato.

$ ino lib deps Arduino_ConnectionHandler
✕ WiFiNINA 1.8.13 deve essere installato.
✕ MKRGSM 1.5.0 deve essere installato.
✕ MKRNB 1.5.1 deve essere installato.
✓ MKRWAN 1.1.0 è già installato.
✕ Arduino_ConnectionHandler 0.6.5 deve essere installato.
✕ Arduino_DebugUtils 1.1.0 deve essere installato.
✓ WiFi101 0.16.1 è già installato.

What is the new behavior?

Output of lib deps is now sorted alphabetically both in plain text and JSON.
In plain text it's also sorted by installation state, dependencies that are installed are shown first.

Example plain text output:

$ ino lib deps Arduino_ConnectionHandler      
✓ MKRWAN 1.1.0 è già installato.
✓ WiFi101 0.16.1 è già installato.
✕ Arduino_ConnectionHandler 0.6.5 deve essere installato.
✕ Arduino_DebugUtils 1.1.0 deve essere installato.
✕ MKRGSM 1.5.0 deve essere installato.
✕ MKRNB 1.5.1 deve essere installato.
✕ WiFiNINA 1.8.13 deve essere installato.

Example json output:

$ ino lib deps Arduino_ConnectionHandler --format json
{
  "dependencies": [
    {
      "name": "Arduino_ConnectionHandler",
      "version_required": "0.6.5"
    },
    {
      "name": "Arduino_DebugUtils",
      "version_required": "1.1.0"
    },
    {
      "name": "MKRGSM",
      "version_required": "1.5.0"
    },
    {
      "name": "MKRNB",
      "version_required": "1.5.1"
    },
    {
      "name": "MKRWAN",
      "version_required": "1.1.0",
      "version_installed": "1.1.0"
    },
    {
      "name": "WiFi101",
      "version_required": "0.16.1",
      "version_installed": "0.16.1"
    },
    {
      "name": "WiFiNINA",
      "version_required": "1.8.13"
    }
  ]
}

Does this PR introduce a breaking change, and is titled accordingly?

Nope.

Other information

This will ease integration testing for a PR that fixes #1856.

@silvanocerza
Copy link
Contributor Author

Check failures are caused by flaky tests on Windows, please rerun them as I don't have permissions to do so.

Comment on lines 161 to 183
stdOut, _, err := cli.Run("lib", "deps", "[email protected]", "--no-color")
require.NoError(t, err)
lines := strings.Split(strings.TrimSpace(string(stdOut)), "\n")
require.Len(t, lines, 7)
require.Equal(t, "✓ Arduino_DebugUtils 1.3.0 is already installed.", lines[0])
require.Equal(t, "✓ MKRGSM 1.5.0 is already installed.", lines[1])
require.Equal(t, "✓ MKRNB 1.5.1 is already installed.", lines[2])
require.Equal(t, "✓ WiFiNINA 1.8.13 is already installed.", lines[3])
require.Equal(t, "✕ Arduino_ConnectionHandler 0.6.6 must be installed.", lines[4])
require.Equal(t, "✕ MKRWAN 1.1.0 must be installed.", lines[5])
require.Equal(t, "✕ WiFi101 0.16.1 must be installed.", lines[6])

stdOut, _, err = cli.Run("lib", "deps", "[email protected]", "--format", "json")
require.NoError(t, err)
expectedOutput := `{"dependencies":[
{"name":"Arduino_ConnectionHandler","version_required":"0.6.6"},
{"name":"Arduino_DebugUtils","version_required":"1.3.0","version_installed":"1.3.0"},
{"name":"MKRGSM","version_required":"1.5.0","version_installed":"1.5.0"},
{"name":"MKRNB","version_required":"1.5.1","version_installed":"1.5.1"},
{"name":"MKRWAN","version_required":"1.1.0"},
{"name":"WiFi101","version_required":"0.16.1"},
{"name":"WiFiNINA","version_required":"1.8.13","version_installed":"1.8.13"}]}`
require.JSONEq(t, expectedOutput, string(stdOut))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same thing as in the other PR, this test will fail as soon as one of the libraries gets another release.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, there's no way of setting the version of libraries' dependencies, didn't think about that.
I'll find a reliable way to test it.

@cmaglie cmaglie merged commit 960c210 into arduino:master Oct 21, 2022
@silvanocerza silvanocerza deleted the lib-deps-sorted-output branch October 21, 2022 14:29
@per1234 per1234 added type: enhancement Proposed improvement topic: code Related to content of the project itself labels Oct 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: code Related to content of the project itself type: enhancement Proposed improvement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

lib upgrade does not install dependencies
3 participants