From fe5a40cedcff1e4ee22a75a0d446586bf2fb6dae Mon Sep 17 00:00:00 2001 From: Alessio Perugini Date: Tue, 7 Nov 2023 11:25:42 +0100 Subject: [PATCH] fix tests --- .../integrationtest/compile_1/compile_test.go | 6 +- .../integrationtest/config/config_test.go | 170 ++++++++++-------- internal/integrationtest/lib/lib_test.go | 124 ++++++------- 3 files changed, 157 insertions(+), 143 deletions(-) diff --git a/internal/integrationtest/compile_1/compile_test.go b/internal/integrationtest/compile_1/compile_test.go index 78ceb5ca63c..ae67eb57c52 100644 --- a/internal/integrationtest/compile_1/compile_test.go +++ b/internal/integrationtest/compile_1/compile_test.go @@ -824,10 +824,8 @@ func TestCompileWithArchivesAndLongPaths(t *testing.T) { stdout, _, err := cli.Run("lib", "examples", "ArduinoIoTCloud", "--format", "json", "--config-file", "arduino-cli.yaml") require.NoError(t, err) - var libOutput []map[string]interface{} - err = json.Unmarshal(stdout, &libOutput) - require.NoError(t, err) - sketchPath := paths.New(libOutput[0]["library"].(map[string]interface{})["install_dir"].(string)) + libOutput := strings.Trim(requirejson.Parse(t, stdout).Query(`.examples.[0].library.install_dir`).String(), `"`) + sketchPath := paths.New(libOutput) sketchPath = sketchPath.Join("examples", "ArduinoIoTCloud-Advanced") _, _, err = cli.Run("compile", "-b", "esp8266:esp8266:huzzah", sketchPath.String(), "--config-file", "arduino-cli.yaml") diff --git a/internal/integrationtest/config/config_test.go b/internal/integrationtest/config/config_test.go index e21d6db55dc..4ccb5460acc 100644 --- a/internal/integrationtest/config/config_test.go +++ b/internal/integrationtest/config/config_test.go @@ -239,7 +239,7 @@ func TestDump(t *testing.T) { stdout, _, err := cli.Run("config", "dump", "--config-file", configFile.String(), "--format", "json") require.NoError(t, err) - requirejson.Query(t, stdout, ".board_manager | .additional_urls", "[]") + requirejson.Query(t, stdout, ".config | .board_manager | .additional_urls", "[]") stdout, _, err = cli.Run("config", "init", "--additional-urls", "https://example.com") require.NoError(t, err) @@ -249,7 +249,7 @@ func TestDump(t *testing.T) { stdout, _, err = cli.Run("config", "dump", "--format", "json") require.NoError(t, err) - requirejson.Query(t, stdout, ".board_manager | .additional_urls", "[\"https://example.com\"]") + requirejson.Query(t, stdout, ".config | .board_manager | .additional_urls", "[\"https://example.com\"]") } func TestDumpWithConfigFileFlag(t *testing.T) { @@ -265,7 +265,7 @@ func TestDumpWithConfigFileFlag(t *testing.T) { stdout, _, err := cli.Run("config", "dump", "--config-file", configFile.String(), "--format", "json") require.NoError(t, err) - requirejson.Query(t, stdout, ".board_manager | .additional_urls", "[\"https://example.com\"]") + requirejson.Query(t, stdout, ".config | .board_manager | .additional_urls", "[\"https://example.com\"]") stdout, _, err = cli.Run( "config", @@ -277,7 +277,7 @@ func TestDumpWithConfigFileFlag(t *testing.T) { "json", ) require.NoError(t, err) - requirejson.Query(t, stdout, ".board_manager | .additional_urls", "[\"https://another-url.com\"]") + requirejson.Query(t, stdout, ".config | .board_manager | .additional_urls", "[\"https://another-url.com\"]") } func TestAddRemoveSetDeleteOnUnexistingKey(t *testing.T) { @@ -316,7 +316,7 @@ func TestAddSingleArgument(t *testing.T) { // Verifies no additional urls are present stdout, _, err := cli.Run("config", "dump", "--format", "json", "--config-file", "arduino-cli.yaml") require.NoError(t, err) - requirejson.Query(t, stdout, ".board_manager | .additional_urls", "[]") + requirejson.Query(t, stdout, ".config | .board_manager | .additional_urls", "[]") // Adds one URL url := "https://example.com" @@ -326,7 +326,7 @@ func TestAddSingleArgument(t *testing.T) { // Verifies URL has been saved stdout, _, err = cli.Run("config", "dump", "--format", "json", "--config-file", "arduino-cli.yaml") require.NoError(t, err) - requirejson.Query(t, stdout, ".board_manager | .additional_urls", "[\"https://example.com\"]") + requirejson.Query(t, stdout, ".config | .board_manager | .additional_urls", "[\"https://example.com\"]") // Adds the same URL (should not error) _, _, err = cli.Run("config", "add", @@ -337,7 +337,7 @@ func TestAddSingleArgument(t *testing.T) { // Verifies a second copy has NOT been added stdout, _, err = cli.Run("config", "dump", "--format", "json", "--config-file", "arduino-cli.yaml") require.NoError(t, err) - requirejson.Query(t, stdout, ".board_manager | .additional_urls", "[\"https://example.com\"]") + requirejson.Query(t, stdout, ".config | .board_manager | .additional_urls", "[\"https://example.com\"]") } func TestAddMultipleArguments(t *testing.T) { @@ -351,7 +351,7 @@ func TestAddMultipleArguments(t *testing.T) { // Verifies no additional urls are present stdout, _, err := cli.Run("config", "dump", "--format", "json", "--config-file", "arduino-cli.yaml") require.NoError(t, err) - requirejson.Query(t, stdout, ".board_manager | .additional_urls", "[]") + requirejson.Query(t, stdout, ".config | .board_manager | .additional_urls", "[]") // Adds multiple URLs at the same time urls := [3]string{ @@ -366,14 +366,16 @@ func TestAddMultipleArguments(t *testing.T) { // Verifies URL has been saved stdout, _, err = cli.Run("config", "dump", "--format", "json", "--config-file", "arduino-cli.yaml") require.NoError(t, err) - requirejson.Query(t, stdout, ".board_manager | .additional_urls | length", "2") + requirejson.Query(t, stdout, ".config | .board_manager | .additional_urls | length", "2") requirejson.Contains(t, stdout, ` { - "board_manager": { - "additional_urls": [ - "https://example.com/package_example_index.json", - "https://example.com/yet_another_package_example_index.json" - ] + "config": { + "board_manager": { + "additional_urls": [ + "https://example.com/package_example_index.json", + "https://example.com/yet_another_package_example_index.json" + ] + } } }`) @@ -384,14 +386,16 @@ func TestAddMultipleArguments(t *testing.T) { // Verifies no change in result array stdout, _, err = cli.Run("config", "dump", "--format", "json", "--config-file", "arduino-cli.yaml") require.NoError(t, err) - requirejson.Query(t, stdout, ".board_manager | .additional_urls | length", "2") + requirejson.Query(t, stdout, ".config | .board_manager | .additional_urls | length", "2") requirejson.Contains(t, stdout, ` { - "board_manager": { - "additional_urls": [ - "https://example.com/package_example_index.json", - "https://example.com/yet_another_package_example_index.json" - ] + "config": { + "board_manager": { + "additional_urls": [ + "https://example.com/package_example_index.json", + "https://example.com/yet_another_package_example_index.json" + ] + } } }`) @@ -407,15 +411,17 @@ func TestAddMultipleArguments(t *testing.T) { // Verifies URL has been saved stdout, _, err = cli.Run("config", "dump", "--format", "json", "--config-file", "arduino-cli.yaml") require.NoError(t, err) - requirejson.Query(t, stdout, ".board_manager | .additional_urls | length", "3") + requirejson.Query(t, stdout, ".config | .board_manager | .additional_urls | length", "3") requirejson.Contains(t, stdout, ` { - "board_manager": { - "additional_urls": [ - "https://example.com/package_example_index.json", - "https://example.com/a_third_package_example_index.json", - "https://example.com/yet_another_package_example_index.json" - ] + "config": { + "board_manager": { + "additional_urls": [ + "https://example.com/package_example_index.json", + "https://example.com/a_third_package_example_index.json", + "https://example.com/yet_another_package_example_index.json" + ] + } } }`) } @@ -431,7 +437,7 @@ func TestAddOnUnsupportedKey(t *testing.T) { // Verifies default value stdout, _, err := cli.Run("config", "dump", "--format", "json", "--config-file", "arduino-cli.yaml") require.NoError(t, err) - requirejson.Query(t, stdout, ".daemon | .port", "\"50051\"") + requirejson.Query(t, stdout, ".config | .daemon | .port", "\"50051\"") // Tries and fails to add a new item _, stderr, err := cli.Run("config", "add", "daemon.port", "50000", "--config-file", "arduino-cli.yaml") @@ -441,7 +447,7 @@ func TestAddOnUnsupportedKey(t *testing.T) { // Verifies value is not changed stdout, _, err = cli.Run("config", "dump", "--format", "json", "--config-file", "arduino-cli.yaml") require.NoError(t, err) - requirejson.Query(t, stdout, ".daemon | .port", "\"50051\"") + requirejson.Query(t, stdout, ".config | .daemon | .port", "\"50051\"") } func TestRemoveSingleArgument(t *testing.T) { @@ -463,14 +469,16 @@ func TestRemoveSingleArgument(t *testing.T) { // Verifies default state stdout, _, err := cli.Run("config", "dump", "--format", "json", "--config-file", "arduino-cli.yaml") require.NoError(t, err) - requirejson.Query(t, stdout, ".board_manager | .additional_urls | length", "2") + requirejson.Query(t, stdout, ".config | .board_manager | .additional_urls | length", "2") requirejson.Contains(t, stdout, ` { - "board_manager": { - "additional_urls": [ - "https://example.com/package_example_index.json", - "https://example.com/yet_another_package_example_index.json" - ] + "config": { + "board_manager": { + "additional_urls": [ + "https://example.com/package_example_index.json", + "https://example.com/yet_another_package_example_index.json" + ] + } } }`) @@ -481,7 +489,7 @@ func TestRemoveSingleArgument(t *testing.T) { // Verifies URLs has been removed stdout, _, err = cli.Run("config", "dump", "--format", "json", "--config-file", "arduino-cli.yaml") require.NoError(t, err) - requirejson.Query(t, stdout, ".board_manager | .additional_urls", "[\"https://example.com/yet_another_package_example_index.json\"]") + requirejson.Query(t, stdout, ".config | .board_manager | .additional_urls", "[\"https://example.com/yet_another_package_example_index.json\"]") } func TestRemoveMultipleArguments(t *testing.T) { @@ -503,14 +511,16 @@ func TestRemoveMultipleArguments(t *testing.T) { // Verifies default state stdout, _, err := cli.Run("config", "dump", "--format", "json", "--config-file", "arduino-cli.yaml") require.NoError(t, err) - requirejson.Query(t, stdout, ".board_manager | .additional_urls | length", "2") + requirejson.Query(t, stdout, ".config | .board_manager | .additional_urls | length", "2") requirejson.Contains(t, stdout, ` { - "board_manager": { - "additional_urls": [ - "https://example.com/package_example_index.json", - "https://example.com/yet_another_package_example_index.json" - ] + "config": { + "board_manager": { + "additional_urls": [ + "https://example.com/package_example_index.json", + "https://example.com/yet_another_package_example_index.json" + ] + } } }`) @@ -521,7 +531,7 @@ func TestRemoveMultipleArguments(t *testing.T) { // Verifies all URLs have been removed stdout, _, err = cli.Run("config", "dump", "--format", "json", "--config-file", "arduino-cli.yaml") require.NoError(t, err) - requirejson.Query(t, stdout, ".board_manager | .additional_urls", "[]") + requirejson.Query(t, stdout, ".config | .board_manager | .additional_urls", "[]") } func TestRemoveOnUnsupportedKey(t *testing.T) { @@ -535,7 +545,7 @@ func TestRemoveOnUnsupportedKey(t *testing.T) { // Verifies default value stdout, _, err := cli.Run("config", "dump", "--format", "json", "--config-file", "arduino-cli.yaml") require.NoError(t, err) - requirejson.Query(t, stdout, ".daemon | .port", "\"50051\"") + requirejson.Query(t, stdout, ".config | .daemon | .port", "\"50051\"") // Tries and fails to remove an item _, stderr, err := cli.Run("config", "remove", "daemon.port", "50051", "--config-file", "arduino-cli.yaml") @@ -545,7 +555,7 @@ func TestRemoveOnUnsupportedKey(t *testing.T) { // Verifies value is not changed stdout, _, err = cli.Run("config", "dump", "--format", "json", "--config-file", "arduino-cli.yaml") require.NoError(t, err) - requirejson.Query(t, stdout, ".daemon | .port", "\"50051\"") + requirejson.Query(t, stdout, ".config | .daemon | .port", "\"50051\"") } func TestSetSliceWithSingleArgument(t *testing.T) { @@ -559,7 +569,7 @@ func TestSetSliceWithSingleArgument(t *testing.T) { // Verifies default state stdout, _, err := cli.Run("config", "dump", "--format", "json", "--config-file", "arduino-cli.yaml") require.NoError(t, err) - requirejson.Query(t, stdout, ".board_manager | .additional_urls", "[]") + requirejson.Query(t, stdout, ".config | .board_manager | .additional_urls", "[]") // Set an URL in the list url := "https://example.com/package_example_index.json" @@ -569,7 +579,7 @@ func TestSetSliceWithSingleArgument(t *testing.T) { // Verifies value is changed stdout, _, err = cli.Run("config", "dump", "--format", "json", "--config-file", "arduino-cli.yaml") require.NoError(t, err) - requirejson.Query(t, stdout, ".board_manager | .additional_urls", "[\"https://example.com/package_example_index.json\"]") + requirejson.Query(t, stdout, ".config | .board_manager | .additional_urls", "[\"https://example.com/package_example_index.json\"]") // Set an URL in the list url = "https://example.com/yet_another_package_example_index.json" @@ -579,7 +589,7 @@ func TestSetSliceWithSingleArgument(t *testing.T) { // Verifies value is changed stdout, _, err = cli.Run("config", "dump", "--format", "json", "--config-file", "arduino-cli.yaml") require.NoError(t, err) - requirejson.Query(t, stdout, ".board_manager | .additional_urls", "[\"https://example.com/yet_another_package_example_index.json\"]") + requirejson.Query(t, stdout, ".config | .board_manager | .additional_urls", "[\"https://example.com/yet_another_package_example_index.json\"]") } func TestSetSliceWithMultipleArguments(t *testing.T) { @@ -593,7 +603,7 @@ func TestSetSliceWithMultipleArguments(t *testing.T) { // Verifies default state stdout, _, err := cli.Run("config", "dump", "--format", "json", "--config-file", "arduino-cli.yaml") require.NoError(t, err) - requirejson.Query(t, stdout, ".board_manager | .additional_urls", "[]") + requirejson.Query(t, stdout, ".config | .board_manager | .additional_urls", "[]") // Set some URLs in the list urls := [7]string{ @@ -606,14 +616,16 @@ func TestSetSliceWithMultipleArguments(t *testing.T) { // Verifies value is changed stdout, _, err = cli.Run("config", "dump", "--format", "json", "--config-file", "arduino-cli.yaml") require.NoError(t, err) - requirejson.Query(t, stdout, ".board_manager | .additional_urls | length", "2") + requirejson.Query(t, stdout, ".config | .board_manager | .additional_urls | length", "2") requirejson.Contains(t, stdout, ` { - "board_manager": { - "additional_urls": [ - "https://example.com/first_package_index.json", - "https://example.com/second_package_index.json" - ] + "config": { + "board_manager": { + "additional_urls": [ + "https://example.com/first_package_index.json", + "https://example.com/second_package_index.json" + ] + } } }`) @@ -628,14 +640,16 @@ func TestSetSliceWithMultipleArguments(t *testing.T) { // Verifies previous value is overwritten stdout, _, err = cli.Run("config", "dump", "--format", "json", "--config-file", "arduino-cli.yaml") require.NoError(t, err) - requirejson.Query(t, stdout, ".board_manager | .additional_urls | length", "2") + requirejson.Query(t, stdout, ".config | .board_manager | .additional_urls | length", "2") requirejson.Contains(t, stdout, ` { - "board_manager": { - "additional_urls": [ - "https://example.com/third_package_index.json", - "https://example.com/fourth_package_index.json" - ] + "config": { + "board_manager": { + "additional_urls": [ + "https://example.com/third_package_index.json", + "https://example.com/fourth_package_index.json" + ] + } } }`) @@ -658,16 +672,18 @@ func TestSetSliceWithMultipleArguments(t *testing.T) { // Verifies all unique values exist in config stdout, _, err = cli.Run("config", "dump", "--format", "json", "--config-file", "arduino-cli.yaml") require.NoError(t, err) - requirejson.Query(t, stdout, ".board_manager | .additional_urls | length", "4") + requirejson.Query(t, stdout, ".config | .board_manager | .additional_urls | length", "4") requirejson.Contains(t, stdout, ` { - "board_manager": { - "additional_urls": [ - "https://example.com/first_package_index.json", - "https://example.com/second_package_index.json", - "https://example.com/fifth_package_index.json", - "https://example.com/sixth_package_index.json" - ] + "config": { + "board_manager": { + "additional_urls": [ + "https://example.com/first_package_index.json", + "https://example.com/second_package_index.json", + "https://example.com/fifth_package_index.json", + "https://example.com/sixth_package_index.json" + ] + } } }`) } @@ -683,7 +699,7 @@ func TestSetStringWithSingleArgument(t *testing.T) { // Verifies default state stdout, _, err := cli.Run("config", "dump", "--format", "json", "--config-file", "arduino-cli.yaml") require.NoError(t, err) - requirejson.Query(t, stdout, ".logging | .level", "\"info\"") + requirejson.Query(t, stdout, ".config | .logging | .level", "\"info\"") // Changes value _, _, err = cli.Run("config", "set", "logging.level", "trace", "--config-file", "arduino-cli.yaml") @@ -692,7 +708,7 @@ func TestSetStringWithSingleArgument(t *testing.T) { // Verifies value is changed stdout, _, err = cli.Run("config", "dump", "--format", "json", "--config-file", "arduino-cli.yaml") require.NoError(t, err) - requirejson.Query(t, stdout, ".logging | .level", "\"trace\"") + requirejson.Query(t, stdout, ".config | .logging | .level", "\"trace\"") } func TestSetStringWithMultipleArguments(t *testing.T) { @@ -706,7 +722,7 @@ func TestSetStringWithMultipleArguments(t *testing.T) { // Verifies default state stdout, _, err := cli.Run("config", "dump", "--format", "json", "--config-file", "arduino-cli.yaml") require.NoError(t, err) - requirejson.Query(t, stdout, ".logging | .level", "\"info\"") + requirejson.Query(t, stdout, ".config | .logging | .level", "\"info\"") // Tries to change value _, stderr, err := cli.Run("config", "set", "logging.level", "trace", "debug") @@ -725,7 +741,7 @@ func TestSetBoolWithSingleArgument(t *testing.T) { // Verifies default state stdout, _, err := cli.Run("config", "dump", "--format", "json", "--config-file", "arduino-cli.yaml") require.NoError(t, err) - requirejson.Query(t, stdout, ".library | .enable_unsafe_install", "false") + requirejson.Query(t, stdout, ".config | .library | .enable_unsafe_install", "false") // Changes value _, _, err = cli.Run("config", "set", "library.enable_unsafe_install", "true", "--config-file", "arduino-cli.yaml") @@ -734,7 +750,7 @@ func TestSetBoolWithSingleArgument(t *testing.T) { // Verifies value is changed stdout, _, err = cli.Run("config", "dump", "--format", "json", "--config-file", "arduino-cli.yaml") require.NoError(t, err) - requirejson.Query(t, stdout, ".library | .enable_unsafe_install", "true") + requirejson.Query(t, stdout, ".config | .library | .enable_unsafe_install", "true") } func TestSetBoolWithMultipleArguments(t *testing.T) { @@ -748,7 +764,7 @@ func TestSetBoolWithMultipleArguments(t *testing.T) { // Verifies default state stdout, _, err := cli.Run("config", "dump", "--format", "json", "--config-file", "arduino-cli.yaml") require.NoError(t, err) - requirejson.Query(t, stdout, ".library | .enable_unsafe_install", "false") + requirejson.Query(t, stdout, ".config | .library | .enable_unsafe_install", "false") // Changes value _, stderr, err := cli.Run("config", "set", "library.enable_unsafe_install", "true", "foo", "--config-file", "arduino-cli.yaml") @@ -767,7 +783,7 @@ func TestDelete(t *testing.T) { // Verifies default state stdout, _, err := cli.Run("config", "dump", "--format", "json", "--config-file", "arduino-cli.yaml") require.NoError(t, err) - requirejson.Query(t, stdout, ".library | .enable_unsafe_install", "false") + requirejson.Query(t, stdout, ".config | .library | .enable_unsafe_install", "false") // Delete config key _, _, err = cli.Run("config", "delete", "library.enable_unsafe_install", "--config-file", "arduino-cli.yaml") @@ -784,7 +800,7 @@ func TestDelete(t *testing.T) { // Verifies default state stdout, _, err = cli.Run("config", "dump", "--format", "json", "--config-file", "arduino-cli.yaml") require.NoError(t, err) - requirejson.Query(t, stdout, ".board_manager | .additional_urls", "[]") + requirejson.Query(t, stdout, ".config | .board_manager | .additional_urls", "[]") // Delete config key and sub keys _, _, err = cli.Run("config", "delete", "board_manager", "--config-file", "arduino-cli.yaml") diff --git a/internal/integrationtest/lib/lib_test.go b/internal/integrationtest/lib/lib_test.go index b00948a0c4c..868f3f2097c 100644 --- a/internal/integrationtest/lib/lib_test.go +++ b/internal/integrationtest/lib/lib_test.go @@ -57,22 +57,22 @@ func TestLibUpgradeCommand(t *testing.T) { require.NoError(t, err) stdOut, _, err := cli.Run("lib", "list", "--format", "json") require.NoError(t, err) - requirejson.Contains(t, stdOut, `[ { "library":{ "name":"Servo", "version": "1.1.6" } } ]`) + requirejson.Contains(t, stdOut, `{"installed_libraries": [ { "library":{ "name":"Servo", "version": "1.1.6" } } ]}`) _, _, err = cli.Run("lib", "upgrade", "Servo") require.NoError(t, err) stdOut, _, err = cli.Run("lib", "list", "--format", "json") require.NoError(t, err) jsonOut := requirejson.Parse(t, stdOut) - jsonOut.MustNotContain(`[ { "library":{ "name":"Servo", "version": "1.1.6" } } ]`) - servoVersion := jsonOut.Query(`.[].library | select(.name=="Servo") | .version`).String() + jsonOut.MustNotContain(`{"installed_libraries": [{"library":{ "name":"Servo", "version": "1.1.6" }}]}`) + servoVersion := jsonOut.Query(`.installed_libraries.[].library | select(.name=="Servo") | .version`).String() // Upgrade of already up-to-date library _, _, err = cli.Run("lib", "upgrade", "Servo") require.NoError(t, err) stdOut, _, err = cli.Run("lib", "list", "--format", "json") require.NoError(t, err) - requirejson.Query(t, stdOut, `.[].library | select(.name=="Servo") | .version`, servoVersion) + requirejson.Query(t, stdOut, `.installed_libraries.[].library | select(.name=="Servo") | .version`, servoVersion) } func TestLibCommandsUsingNameInsteadOfDirName(t *testing.T) { @@ -107,7 +107,7 @@ func TestLibInstallMultipleSameLibrary(t *testing.T) { require.NoError(t, err) // Count how many libraries with the name "Arduino SigFox for MKRFox1200" are installed requirejson.Parse(t, jsonOut). - Query(`[.[].library.name | select(. == "Arduino SigFox for MKRFox1200")]`). + Query(`[.installed_libraries.[].library.name | select(. == "Arduino SigFox for MKRFox1200")]`). LengthMustEqualTo(1, "Found multiple installations of Arduino SigFox for MKRFox1200'") // Check that 'lib upgrade' didn't create a double install @@ -122,7 +122,7 @@ func TestLibInstallMultipleSameLibrary(t *testing.T) { require.NoError(t, err) // Count how many libraries with the name "Arduino SigFox for MKRFox1200" are installed requirejson.Parse(t, jsonOut). - Query(`[.[].library.name | select(. == "Arduino SigFox for MKRFox1200")]`). + Query(`[.installed_libraries.[].library.name | select(. == "Arduino SigFox for MKRFox1200")]`). LengthMustEqualTo(1, "Found multiple installations of Arduino SigFox for MKRFox1200'") } @@ -140,7 +140,7 @@ func TestDuplicateLibInstallDetection(t *testing.T) { require.NoError(t, err) jsonOut, _, err := cli.Run("lib", "list", "--format", "json") require.NoError(t, err) - requirejson.Len(t, jsonOut, 2, "Duplicate library install is not detected by the CLI") + requirejson.Query(t, jsonOut, `.installed_libraries | length`, `2`, "Duplicate library install is not detected by the CLI") _, stdErr, err := cli.Run("lib", "install", "ArduinoOTA") require.Error(t, err) @@ -170,7 +170,7 @@ func TestDuplicateLibInstallFromGitDetection(t *testing.T) { require.NoError(t, err) // Count how many libraries with the name "Arduino SigFox for MKRFox1200" are installed requirejson.Parse(t, jsonOut). - Query(`[.[].library.name | select(. == "Arduino SigFox for MKRFox1200")]`). + Query(`[.installed_libraries.[].library.name | select(. == "Arduino SigFox for MKRFox1200")]`). LengthMustEqualTo(1, "Found multiple installations of Arduino SigFox for MKRFox1200'") // Try to make a double install by upgrade @@ -181,7 +181,7 @@ func TestDuplicateLibInstallFromGitDetection(t *testing.T) { jsonOut, _, err = cli.Run("lib", "list", "--format", "json") require.NoError(t, err) requirejson.Parse(t, jsonOut). - Query(`[.[].library.name | select(. == "Arduino SigFox for MKRFox1200")]`). + Query(`[.installed_libraries.[].library.name | select(. == "Arduino SigFox for MKRFox1200")]`). LengthMustEqualTo(1, "Found multiple installations of Arduino SigFox for MKRFox1200'") // Try to make a double install by zip-installing @@ -206,7 +206,7 @@ func TestDuplicateLibInstallFromGitDetection(t *testing.T) { jsonOut, _, err = cli.Run("lib", "list", "--format", "json") require.NoError(t, err) requirejson.Parse(t, jsonOut). - Query(`[.[].library.name | select(. == "Arduino SigFox for MKRFox1200")]`). + Query(`[.installed_libraries.[].library.name | select(. == "Arduino SigFox for MKRFox1200")]`). LengthMustEqualTo(1, "Found multiple installations of Arduino SigFox for MKRFox1200'") } @@ -332,7 +332,7 @@ func TestList(t *testing.T) { stdout, stderr, err = cli.Run("lib", "list", "--format", "json") require.NoError(t, err) require.Empty(t, stderr) - requirejson.Empty(t, stdout) + requirejson.Query(t, stdout, `.installed_libraries | length`, `0`) // Install something we can list at a version older than latest _, _, err = cli.Run("lib", "install", "ArduinoJson@6.11.0") @@ -358,9 +358,9 @@ func TestList(t *testing.T) { stdout, stderr, err = cli.Run("lib", "list", "--format", "json") require.NoError(t, err) require.Empty(t, stderr) - requirejson.Len(t, stdout, 1) + requirejson.Query(t, stdout, `.installed_libraries | length`, `1`) // be sure data contains the available version - requirejson.Query(t, stdout, `.[0] | .release | .version != ""`, "true") + requirejson.Query(t, stdout, `.installed_libraries.[0] | .release | .version != ""`, "true") // Install something we can list without provides_includes field given in library.properties _, _, err = cli.Run("lib", "install", "Arduino_APDS9960@1.0.3") @@ -369,9 +369,9 @@ func TestList(t *testing.T) { stdout, stderr, err = cli.Run("lib", "list", "Arduino_APDS9960", "--format", "json") require.NoError(t, err) require.Empty(t, stderr) - requirejson.Len(t, stdout, 1) + requirejson.Query(t, stdout, `.installed_libraries | length`, `1`) // be sure data contains the correct provides_includes field - requirejson.Query(t, stdout, ".[0] | .library | .provides_includes | .[0]", `"Arduino_APDS9960.h"`) + requirejson.Query(t, stdout, ".installed_libraries.[0] | .library | .provides_includes | .[0]", `"Arduino_APDS9960.h"`) } func TestListExitCode(t *testing.T) { @@ -451,14 +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, 6) + requirejson.Query(t, stdout, `.installed_libraries | length`, `6`) // Verifies library is compatible - 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`) + requirejson.Query(t, stdout, `.installed_libraries | sort_by(.library | .name) | .[0] | .library | .name`, `"ArduinoJson"`) + requirejson.Query(t, stdout, `.installed_libraries | 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() + requirejson.Parse(t, stdout).Query(`.installed_libraries.[] | .library | select(.container_platform=="arduino:avr@1.8.6")`).MustNotBeEmpty() } func TestListProvidesIncludesFallback(t *testing.T) { @@ -481,9 +481,9 @@ func TestListProvidesIncludesFallback(t *testing.T) { require.NoError(t, err) require.Empty(t, stderr) - requirejson.Len(t, stdout, 6) + requirejson.Query(t, stdout, `.installed_libraries | length`, `6`) - requirejson.Query(t, stdout, "[.[] | .library | { (.name): .provides_includes }] | add", + requirejson.Query(t, stdout, "[.installed_libraries.[] | .library | { (.name): .provides_includes }] | add", `{ "SPI": [ "SPI.h" @@ -548,7 +548,7 @@ func TestInstall(t *testing.T) { require.NoError(t, err) stdout, _, err := cli.Run("lib", "list", "--format", "json") require.NoError(t, err) - requirejson.Parse(t, stdout).Query(`.[] | select(.library.name == "ILI9341_t3") | .library.version`).MustEqual(`"1.0"`) + requirejson.Parse(t, stdout).Query(`.installed_libraries.[] | select(.library.name == "ILI9341_t3") | .library.version`).MustEqual(`"1.0"`) _, _, err = cli.Run("lib", "install", "ILI9341_t3@1") require.NoError(t, err) _, _, err = cli.Run("lib", "install", "ILI9341_t3@1.0.0") @@ -565,7 +565,7 @@ func TestInstallLibraryWithDependencies(t *testing.T) { // Verifies libraries are not installed stdout, _, err := cli.Run("lib", "list", "--format", "json") require.NoError(t, err) - requirejson.Empty(t, stdout) + requirejson.Query(t, stdout, `.installed_libraries | length`, `0`) // Install library _, _, err = cli.Run("lib", "install", "MD_Parola@3.5.5") @@ -574,7 +574,7 @@ func TestInstallLibraryWithDependencies(t *testing.T) { // Verifies library's dependencies are correctly installed stdout, _, err = cli.Run("lib", "list", "--format", "json") require.NoError(t, err) - requirejson.Query(t, stdout, `[ .[] | .library | .name ] | sort`, `["MD_MAX72XX","MD_Parola"]`) + requirejson.Query(t, stdout, `[.installed_libraries.[] | .library | .name ] | sort`, `["MD_MAX72XX","MD_Parola"]`) // Try upgrading with --no-overwrite (should fail) and without --no-overwrite (should succeed) _, _, err = cli.Run("lib", "install", "MD_Parola@3.6.1", "--no-overwrite") @@ -603,7 +603,7 @@ func TestInstallNoDeps(t *testing.T) { // Verifies libraries are not installed stdout, _, err := cli.Run("lib", "list", "--format", "json") require.NoError(t, err) - requirejson.Empty(t, stdout) + requirejson.Query(t, stdout, `.installed_libraries | length`, `0`) // Install library skipping dependencies installation _, _, err = cli.Run("lib", "install", "MD_Parola@3.5.5", "--no-deps") @@ -612,7 +612,7 @@ func TestInstallNoDeps(t *testing.T) { // Verifies library's dependencies are not installed stdout, _, err = cli.Run("lib", "list", "--format", "json") require.NoError(t, err) - requirejson.Query(t, stdout, `.[] | .library | .name`, `"MD_Parola"`) + requirejson.Query(t, stdout, `.installed_libraries.[] | .library | .name`, `"MD_Parola"`) } func TestInstallWithGitUrl(t *testing.T) { @@ -712,7 +712,7 @@ func TestUninstallSpaces(t *testing.T) { require.NoError(t, err) stdout, _, err := cli.Run("lib", "list", "--format", "json") require.NoError(t, err) - requirejson.Len(t, stdout, 0) + requirejson.Query(t, stdout, `.installed_libraries | length`, `0`) } func TestLibOpsCaseInsensitive(t *testing.T) { @@ -740,7 +740,7 @@ func TestLibOpsCaseInsensitive(t *testing.T) { require.NoError(t, err) stdout, _, err := cli.Run("lib", "list", "--format", "json") require.NoError(t, err) - requirejson.Len(t, stdout, 0) + requirejson.Query(t, stdout, `.installed_libraries | length`, `0`) } func TestSearch(t *testing.T) { @@ -847,7 +847,7 @@ func TestLibListWithUpdatableFlag(t *testing.T) { stdout, stderr, err = cli.Run("lib", "list", "--updatable", "--format", "json") require.NoError(t, err) require.Empty(t, stderr) - requirejson.Empty(t, stdout) + requirejson.Query(t, stdout, `.installed_libraries | length`, `0`) // Install outdated library _, _, err = cli.Run("lib", "install", "ArduinoJson@6.11.0") @@ -877,11 +877,11 @@ func TestLibListWithUpdatableFlag(t *testing.T) { stdout, stderr, err = cli.Run("lib", "list", "--updatable", "--format", "json") require.NoError(t, err) require.Empty(t, stderr) - requirejson.Len(t, stdout, 1) + requirejson.Query(t, stdout, `.installed_libraries | length`, `1`) // be sure data contains the available version - requirejson.Query(t, stdout, `.[0] | .library | .version`, `"6.11.0"`) - requirejson.Query(t, stdout, `.[0] | .release | .version != "6.11.0"`, `true`) - requirejson.Query(t, stdout, `.[0] | .release | .version != ""`, `true`) + requirejson.Query(t, stdout, `.installed_libraries.[0] | .library | .version`, `"6.11.0"`) + requirejson.Query(t, stdout, `.installed_libraries.[0] | .release | .version != "6.11.0"`, `true`) + requirejson.Query(t, stdout, `.installed_libraries.[0] | .release | .version != ""`, `true`) } func TestInstallWithGitUrlFromCurrentDirectory(t *testing.T) { @@ -1041,8 +1041,8 @@ func TestLibExamples(t *testing.T) { stdout, _, err := cli.Run("lib", "examples", "Arduino_JSON", "--format", "json") require.NoError(t, err) - requirejson.Len(t, stdout, 1) - examples := requirejson.Parse(t, stdout).Query(".[0] | .examples").String() + requirejson.Query(t, stdout, `.examples | length`, `1`) + examples := requirejson.Parse(t, stdout).Query(".examples.[0] | .examples").String() examples = strings.ReplaceAll(examples, "\\\\", "\\") require.Contains(t, examples, cli.SketchbookDir().Join("libraries", "Arduino_JSON", "examples", "JSONArray").String()) require.Contains(t, examples, cli.SketchbookDir().Join("libraries", "Arduino_JSON", "examples", "JSONKitchenSink").String()) @@ -1061,8 +1061,8 @@ func TestLibExamplesWithPdeFile(t *testing.T) { stdout, _, err := cli.Run("lib", "examples", "Encoder", "--format", "json") require.NoError(t, err) - requirejson.Len(t, stdout, 1) - examples := requirejson.Parse(t, stdout).Query(".[0] | .examples").String() + requirejson.Query(t, stdout, `.examples | length`, `1`) + examples := requirejson.Parse(t, stdout).Query(".examples.[0] | .examples").String() examples = strings.ReplaceAll(examples, "\\\\", "\\") require.Contains(t, examples, cli.SketchbookDir().Join("libraries", "Encoder", "examples", "Basic").String()) require.Contains(t, examples, cli.SketchbookDir().Join("libraries", "Encoder", "examples", "NoInterrupts").String()) @@ -1082,10 +1082,10 @@ func TestLibExamplesWithCaseMismatch(t *testing.T) { stdout, _, err := cli.Run("lib", "examples", "WiFiManager", "--format", "json") require.NoError(t, err) - requirejson.Len(t, stdout, 1) - requirejson.Query(t, stdout, ".[0] | .examples | length", "14") + requirejson.Query(t, stdout, `.examples | length`, `1`) + requirejson.Query(t, stdout, ".examples.[0] | .examples | length", "14") - examples := requirejson.Parse(t, stdout).Query(".[0] | .examples").String() + examples := requirejson.Parse(t, stdout).Query(".examples.[0] | .examples").String() examples = strings.ReplaceAll(examples, "\\\\", "\\") examplesPath := cli.SketchbookDir().Join("libraries", "WiFiManager", "examples") // Verifies sketches with correct casing are listed @@ -1122,8 +1122,8 @@ func TestLibCommandsWithLibraryHavingInvalidVersion(t *testing.T) { // Verifies library is correctly returned stdout, _, err := cli.Run("lib", "list", "--format", "json") require.NoError(t, err) - requirejson.Len(t, stdout, 1) - requirejson.Query(t, stdout, ".[0] | .library | .version", `"0.16.1"`) + requirejson.Query(t, stdout, `.installed_libraries | length`, `1`) + requirejson.Query(t, stdout, ".installed_libraries.[0] | .library | .version", `"0.16.1"`) // Changes the version of the currently installed library so that it's // invalid @@ -1133,8 +1133,8 @@ func TestLibCommandsWithLibraryHavingInvalidVersion(t *testing.T) { // Verifies version is now empty stdout, _, err = cli.Run("lib", "list", "--format", "json") require.NoError(t, err) - requirejson.Len(t, stdout, 1) - requirejson.Query(t, stdout, ".[0] | .library | .version", "null") + requirejson.Query(t, stdout, `.installed_libraries | length`, `1`) + requirejson.Query(t, stdout, ".installed_libraries.[0] | .library | .version", "null") // Upgrade library _, _, err = cli.Run("lib", "upgrade", "WiFi101") @@ -1143,8 +1143,8 @@ func TestLibCommandsWithLibraryHavingInvalidVersion(t *testing.T) { // Verifies library has been updated stdout, _, err = cli.Run("lib", "list", "--format", "json") require.NoError(t, err) - requirejson.Len(t, stdout, 1) - requirejson.Query(t, stdout, ".[0] | .library | .version != \"\"", "true") + requirejson.Query(t, stdout, `.installed_libraries | length`, `1`) + requirejson.Query(t, stdout, ".installed_libraries.[0] | .library | .version != \"\"", "true") } func TestInstallZipLibWithMacosMetadata(t *testing.T) { @@ -1301,10 +1301,10 @@ func TestUpgradeDoesNotTryToUpgradeBundledCoreLibrariesInSketchbook(t *testing.T stdout, _, err := cli.Run("lib", "list", "--all", "--format", "json") require.NoError(t, err) - requirejson.Len(t, stdout, 2) + requirejson.Query(t, stdout, `.installed_libraries | length`, `2`) // Verify both libraries have the same name - requirejson.Query(t, stdout, ".[0] | .library | .name", `"USBHost"`) - requirejson.Query(t, stdout, ".[1] | .library | .name", `"USBHost"`) + requirejson.Query(t, stdout, ".installed_libraries.[0] | .library | .name", `"USBHost"`) + requirejson.Query(t, stdout, ".installed_libraries.[1] | .library | .name", `"USBHost"`) stdout, _, err = cli.Run("lib", "upgrade") require.NoError(t, err) @@ -1333,10 +1333,10 @@ func TestUpgradeDoesNotTryToUpgradeBundledCoreLibraries(t *testing.T) { stdout, _, err := cli.Run("lib", "list", "--all", "--format", "json") require.NoError(t, err) - requirejson.Len(t, stdout, 2) + requirejson.Query(t, stdout, `.installed_libraries | length`, `2`) // Verify both libraries have the same name - requirejson.Query(t, stdout, ".[0] | .library | .name", `"USBHost"`) - requirejson.Query(t, stdout, ".[1] | .library | .name", `"USBHost"`) + requirejson.Query(t, stdout, ".installed_libraries.[0] | .library | .name", `"USBHost"`) + requirejson.Query(t, stdout, ".installed_libraries.[1] | .library | .name", `"USBHost"`) stdout, _, err = cli.Run("lib", "upgrade") require.NoError(t, err) @@ -1581,8 +1581,8 @@ func TestLibBundlesWhenLibWithTheSameNameIsInstalledGlobally(t *testing.T) { stdout, _, err := cli.Run("lib", "list", "--all", "--fqbn", "arduino:samd:mkrzero", "USBHost", "--format", "json") require.NoError(t, err) j := requirejson.Parse(t, stdout) - j.Query(`.[0].library.name`).MustEqual(`"USBHost"`) - j.Query(`.[0].library.compatible_with."arduino:samd:mkrzero"`).MustEqual(`true`) + j.Query(`.installed_libraries.[0].library.name`).MustEqual(`"USBHost"`) + j.Query(`.installed_libraries.[0].library.compatible_with."arduino:samd:mkrzero"`).MustEqual(`true`) } _, _, err = cli.Run("lib", "install", "USBHost@1.0.5") require.NoError(t, err) @@ -1591,8 +1591,8 @@ func TestLibBundlesWhenLibWithTheSameNameIsInstalledGlobally(t *testing.T) { stdout, _, err := cli.Run("lib", "list", "--all", "--fqbn", "arduino:samd:mkrzero", "USBHost", "--format", "json") require.NoError(t, err) j := requirejson.Parse(t, stdout) - j.Query(`.[0].library.name`).MustEqual(`"USBHost"`) - j.Query(`.[0].library.compatible_with."arduino:samd:mkrzero"`).MustEqual(`true`) + j.Query(`.installed_libraries.[0].library.name`).MustEqual(`"USBHost"`) + j.Query(`.installed_libraries.[0].library.compatible_with."arduino:samd:mkrzero"`).MustEqual(`true`) } // See: https://github.com/arduino/arduino-cli/issues/1656 @@ -1605,8 +1605,8 @@ func TestLibBundlesWhenLibWithTheSameNameIsInstalledGlobally(t *testing.T) { require.NoError(t, err) stdout, _, err := cli.Run("lib", "examples", "--fqbn", "esp8266:esp8266:generic", "ArduinoOTA", "--format", "json") require.NoError(t, err) - requirejson.Parse(t, stdout).Query(`.[].library.examples[0]`).MustContain(`"BasicOTA"`) - requirejson.Parse(t, stdout).Query(`.[].library.examples[1]`).MustContain(`"OTALeds"`) + requirejson.Parse(t, stdout).Query(`.examples.[].library.examples[0]`).MustContain(`"BasicOTA"`) + requirejson.Parse(t, stdout).Query(`.examples.[].library.examples[1]`).MustContain(`"OTALeds"`) } } @@ -1624,11 +1624,11 @@ func TestLibListDoesNotIncludeEmptyLibraries(t *testing.T) { // Check that the output of lib list and lib examples is empty stdout, _, err := cli.Run("lib", "list", "--format", "json") require.NoError(t, err) - requirejson.Empty(t, stdout) + requirejson.Query(t, stdout, `.installed_libraries | length`, `0`) stdout, _, err = cli.Run("lib", "examples", "--format", "json") require.NoError(t, err) - requirejson.Empty(t, stdout) + requirejson.Query(t, stdout, `.examples | length`, `0`) // Create a library with a header libWithHeader := cli.SketchbookDir().Join("libraries", "libWithHeader") @@ -1640,11 +1640,11 @@ func TestLibListDoesNotIncludeEmptyLibraries(t *testing.T) { // Check that the output of lib list and lib examples contains the library stdout, _, err = cli.Run("lib", "list", "--format", "json") require.NoError(t, err) - requirejson.Len(t, stdout, 1) + requirejson.Query(t, stdout, `.installed_libraries | length`, `1`) stdout, _, err = cli.Run("lib", "examples", "--format", "json") require.NoError(t, err) - requirejson.Len(t, stdout, 1) + requirejson.Query(t, stdout, `.examples | length`, `1`) } func TestDependencyResolver(t *testing.T) {