Skip to content

Commit 88e37f4

Browse files
committed
Refactored integration test
1 parent 919852d commit 88e37f4

File tree

1 file changed

+38
-41
lines changed

1 file changed

+38
-41
lines changed

internal/integrationtest/compile_4/lib_discovery_caching_test.go

Lines changed: 38 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -39,72 +39,69 @@ func TestLibDiscoveryCache(t *testing.T) {
3939
require.NoError(t, sketchbook.RemoveAll())
4040
require.NoError(t, testdata.CopyDirTo(cli.SketchbookDir()))
4141

42-
buildpath, err := paths.MkTempDir("", "tmpbuildpath")
43-
require.NoError(t, err)
44-
t.Cleanup(func() { buildpath.RemoveAll() })
45-
46-
{
42+
t.Run("BasicLibDiscovery", func(t *testing.T) {
4743
sketchA := sketchbook.Join("SketchA")
44+
buildpath, err := sketchA.Join("build").Abs()
45+
require.NoError(t, err)
46+
t.Cleanup(func() { buildpath.RemoveAll() })
47+
4848
{
49+
require.NoError(t, sketchA.Join("SketchA.ino").WriteFile([]byte(`
50+
#include <LibA.h>
51+
void setup() {}
52+
void loop() {libAFunction();}`)))
4953
outjson, _, err := cli.Run("compile", "-v", "-b", "arduino:avr:uno", "--build-path", buildpath.String(), "--json", sketchA.String())
5054
require.NoError(t, err)
5155
j := requirejson.Parse(t, outjson)
52-
j.MustContain(`{"builder_result":{
53-
"used_libraries": [
54-
{ "name": "LibA" },
55-
{ "name": "LibB" }
56-
],
57-
}}`)
56+
usedLibs := j.Query("[.builder_result.used_libraries[].name]")
57+
usedLibs.MustEqual(`["LibA", "LibB"]`)
5858
}
5959

60-
// Update SketchA
61-
require.NoError(t, sketchA.Join("SketchA.ino").WriteFile([]byte(`
60+
{
61+
// Update SketchA
62+
require.NoError(t, sketchA.Join("SketchA.ino").WriteFile([]byte(`
6263
#include <LibC.h>
6364
#include <LibA.h>
6465
void setup() {}
6566
void loop() {libAFunction();}
66-
`)))
67-
68-
{
67+
`)))
6968
// This compile should FAIL!
7069
outjson, _, err := cli.Run("compile", "-v", "-b", "arduino:avr:uno", "--build-path", buildpath.String(), "--json", sketchA.String())
7170
require.Error(t, err)
7271
j := requirejson.Parse(t, outjson)
72+
usedLibs := j.Query("[.builder_result.used_libraries[].name]")
73+
usedLibs.MustEqual(`["LibC", "LibA"]`)
7374
j.MustContain(`{
74-
"builder_result":{
75-
"used_libraries": [
76-
{ "name": "LibC" },
77-
{ "name": "LibA" }
78-
],
79-
"diagnostics": [
80-
{
81-
"severity": "ERROR",
82-
"message": "'libAFunction' was not declared in this scope\n void loop() {libAFunction();}\n ^~~~~~~~~~~~"
83-
}
84-
]
85-
}}`)
75+
"builder_result":{
76+
"diagnostics": [
77+
{
78+
"severity": "ERROR",
79+
"message": "'libAFunction' was not declared in this scope\n void loop() {libAFunction();}\n ^~~~~~~~~~~~"
80+
}
81+
]
82+
}}`)
8683
j.Query(".compiler_out").MustContain(`"The list of included libraries has been changed... rebuilding all libraries."`)
8784
}
8885

8986
{
87+
// Compile again the bad sketch
88+
9089
// This compile should FAIL!
9190
outjson, _, err := cli.Run("compile", "-v", "-b", "arduino:avr:uno", "--build-path", buildpath.String(), "--json", sketchA.String())
9291
require.Error(t, err)
9392
j := requirejson.Parse(t, outjson)
93+
usedLibs := j.Query("[.builder_result.used_libraries[].name]")
94+
usedLibs.MustEqual(`["LibC", "LibA"]`)
9495
j.MustContain(`{
95-
"builder_result":{
96-
"used_libraries": [
97-
{ "name": "LibC" },
98-
{ "name": "LibA" }
99-
],
100-
"diagnostics": [
101-
{
102-
"severity": "ERROR",
103-
"message": "'libAFunction' was not declared in this scope\n void loop() {libAFunction();}\n ^~~~~~~~~~~~"
104-
}
105-
]
106-
}}`)
96+
"builder_result":{
97+
"diagnostics": [
98+
{
99+
"severity": "ERROR",
100+
"message": "'libAFunction' was not declared in this scope\n void loop() {libAFunction();}\n ^~~~~~~~~~~~"
101+
}
102+
]
103+
}}`)
107104
j.Query(".compiler_out").MustNotContain(`"The list of included libraries has changed... rebuilding all libraries."`)
108105
}
109-
}
106+
})
110107
}

0 commit comments

Comments
 (0)