21
21
def test_core_search (run_command ):
22
22
url = "https://raw.githubusercontent.com/arduino/arduino-cli/master/test/testdata/test_index.json"
23
23
assert run_command ("core update-index --additional-urls={}" .format (url ))
24
- # list all
25
- result = run_command ("core search" )
26
- assert result .ok
27
- # filter out empty lines and subtract 1 for the header line
28
- platforms_count = len ([l for l in result .stdout .splitlines () if l ]) - 1
29
- result = run_command ("core search --format json" )
30
- assert result .ok
31
- assert len (json .loads (result .stdout )) == platforms_count
32
24
# search a specific core
33
25
result = run_command ("core search avr" )
34
26
assert result .ok
@@ -51,3 +43,55 @@ def test_core_search(run_command):
51
43
assert result .ok
52
44
data = json .loads (result .stdout )
53
45
assert 2 == len (data )
46
+
47
+
48
+ def test_core_search_no_args (run_command ):
49
+ """
50
+ This tests `core search` with and without additional URLs in case no args
51
+ are passed (i.e. all results are shown).
52
+ """
53
+ # update custom index and install test core (installed cores affect `core search`)
54
+ url = "https://raw.githubusercontent.com/arduino/arduino-cli/massi/506/test/testdata/test_index.json"
55
+ assert run_command ("core update-index --additional-urls={}" .format (url ))
56
+ assert run_command ("core install test:x86 --additional-urls={}" .format (url ))
57
+
58
+ # list all with no additional urls, ensure the test core won't show up
59
+ result = run_command ("core search" )
60
+ assert result .ok
61
+ num_platforms = 0
62
+ for l in result .stdout .splitlines ()[1 :]: # ignore the header on first line
63
+ if l : # ignore empty lines
64
+ assert not l .startswith ("test:x86" )
65
+ num_platforms += 1
66
+
67
+ # same thing in JSON format, also check the number of platforms found is the same
68
+ result = run_command ("core search --format json" )
69
+ assert result .ok
70
+ platforms = json .loads (result .stdout )
71
+ for elem in platforms :
72
+ assert elem .get ("Name" ) != "test_core"
73
+ assert len (platforms ) == num_platforms
74
+
75
+ # list all with additional urls, check the test core is there
76
+ result = run_command ("core search --additional-urls={}" .format (url ))
77
+ assert result .ok
78
+ num_platforms = 0
79
+ found = False
80
+ for l in result .stdout .splitlines ()[1 :]: # ignore the header on first line
81
+ if l : # ignore empty lines
82
+ if l .startswith ("test:x86" ):
83
+ found = True
84
+ num_platforms += 1
85
+ assert found
86
+
87
+ # same thing in JSON format, also check the number of platforms found is the same
88
+ result = run_command ("core search --format json --additional-urls={}" .format (url ))
89
+ assert result .ok
90
+ found = False
91
+ platforms = json .loads (result .stdout )
92
+ for elem in platforms :
93
+ if elem .get ("Name" ) == "test_core" :
94
+ found = True
95
+ break
96
+ assert found
97
+ assert len (platforms ) == num_platforms
0 commit comments