Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
updated tests and fixed some error wording
  • Loading branch information
cmaglie committed Aug 28, 2021
commit 763fcb82a4fd1d12f3e9900652aa0ceed1363bd3
2 changes: 1 addition & 1 deletion commands/board/attach.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func Attach(ctx context.Context, req *rpc.BoardAttachRequest, taskCB commands.Ta
}
sk, err := sketch.New(sketchPath)
if err != nil {
return nil, &commands.SketchNotFoundError{Cause: err}
return nil, &commands.CantOpenSketchError{Cause: err}
}

boardURI := req.GetBoardUri()
Expand Down
2 changes: 1 addition & 1 deletion commands/compile/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func Compile(ctx context.Context, req *rpc.CompileRequest, outStream, errStream
sketchPath := paths.New(req.GetSketchPath())
sk, err := sketch.New(sketchPath)
if err != nil {
return nil, &commands.SketchNotFoundError{Cause: err}
return nil, &commands.CantOpenSketchError{Cause: err}
}

fqbnIn := req.GetFqbn()
Expand Down
2 changes: 1 addition & 1 deletion commands/debug/debug_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func getDebugProperties(req *debug.DebugConfigRequest, pm *packagemanager.Packag
sketchPath := paths.New(req.GetSketchPath())
sk, err := sketch.New(sketchPath)
if err != nil {
return nil, &commands.SketchNotFoundError{Cause: err}
return nil, &commands.CantOpenSketchError{Cause: err}
}

// XXX Remove this code duplication!!
Expand Down
12 changes: 6 additions & 6 deletions commands/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,20 +304,20 @@ func (e *MissingSketchPathError) ToRPCStatus() *status.Status {
return status.New(codes.InvalidArgument, e.Error())
}

// SketchNotFoundError is returned when the sketch is not found
type SketchNotFoundError struct {
// CantOpenSketchError is returned when the sketch is not found or cannot be opened
type CantOpenSketchError struct {
Cause error
}

func (e *SketchNotFoundError) Error() string {
return composeErrorMsg(tr("Sketch not found"), e.Cause)
func (e *CantOpenSketchError) Error() string {
return composeErrorMsg(tr("Can't open sketch"), e.Cause)
}

func (e *SketchNotFoundError) Unwrap() error {
func (e *CantOpenSketchError) Unwrap() error {
return e.Cause
}

func (e *SketchNotFoundError) ToRPCStatus() *status.Status {
func (e *CantOpenSketchError) ToRPCStatus() *status.Status {
return status.New(codes.NotFound, e.Error())
}

Expand Down
2 changes: 1 addition & 1 deletion commands/instances.go
Original file line number Diff line number Diff line change
Expand Up @@ -862,7 +862,7 @@ func LoadSketch(ctx context.Context, req *rpc.LoadSketchRequest) (*rpc.LoadSketc
// TODO: This should be a ToRpc function for the Sketch struct
sketch, err := sk.New(paths.New(req.SketchPath))
if err != nil {
return nil, &SketchNotFoundError{Cause: err}
return nil, &CantOpenSketchError{Cause: err}
}

otherSketchFiles := make([]string, sketch.OtherSketchFiles.Len())
Expand Down
2 changes: 1 addition & 1 deletion commands/sketch/archive.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func ArchiveSketch(ctx context.Context, req *rpc.ArchiveSketchRequest) (*rpc.Arc

s, err := sketch.New(sketchPath)
if err != nil {
return nil, &commands.SketchNotFoundError{Cause: err}
return nil, &commands.CantOpenSketchError{Cause: err}
}

sketchPath = s.FullPath
Expand Down
2 changes: 1 addition & 1 deletion commands/upload/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func Upload(ctx context.Context, req *rpc.UploadRequest, outStream io.Writer, er
sketchPath := paths.New(req.GetSketchPath())
sk, err := sketch.New(sketchPath)
if err != nil && req.GetImportDir() == "" && req.GetImportFile() == "" {
return nil, &commands.SketchNotFoundError{Cause: err}
return nil, &commands.CantOpenSketchError{Cause: err}
}

pm := commands.GetPackageManager(req.GetInstance().GetId())
Expand Down
2 changes: 1 addition & 1 deletion test/test_board.py
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ def test_board_details_no_flags(run_command):
run_command("core install arduino:samd@1.8.6")
result = run_command("board details")
assert not result.ok
assert "Error getting board details: parsing fqbn: invalid fqbn:" in result.stderr
assert "Error getting board details: Invalid FQBN:" in result.stderr
assert result.stdout == ""


Expand Down
16 changes: 8 additions & 8 deletions test/test_compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def test_compile_with_sketch_with_symlink_selfloop(run_command, data_dir):
result = run_command("compile -b {fqbn} {sketch_path}".format(fqbn=fqbn, sketch_path=sketch_path))
# The assertion is a bit relaxed in this case because win behaves differently from macOs and linux
# returning a different error detailed message
assert "Error during build: opening sketch" in result.stderr
assert "Error during build: Can't open sketch:" in result.stderr
assert not result.ok

sketch_name = "CompileIntegrationTestSymlinkDirLoop"
Expand All @@ -154,7 +154,7 @@ def test_compile_with_sketch_with_symlink_selfloop(run_command, data_dir):
result = run_command("compile -b {fqbn} {sketch_path}".format(fqbn=fqbn, sketch_path=sketch_path))
# The assertion is a bit relaxed in this case because win behaves differently from macOs and linux
# returning a different error detailed message
assert "Error during build: opening sketch" in result.stderr
assert "Error during build: Can't open sketch:" in result.stderr
assert not result.ok


Expand Down Expand Up @@ -685,17 +685,17 @@ def test_compile_sketch_with_multiple_main_files(run_command, data_dir):
# Build sketch from folder
res = run_command(f"compile --clean -b {fqbn} {sketch_path}")
assert res.failed
assert "Error during build: opening sketch: multiple main sketch files found" in res.stderr
assert "Error during build: Can't open sketch: multiple main sketch files found" in res.stderr

# Build sketch from .ino file
res = run_command(f"compile --clean -b {fqbn} {sketch_ino_file}")
assert res.failed
assert "Error during build: opening sketch: multiple main sketch files found" in res.stderr
assert "Error during build: Can't open sketch: multiple main sketch files found" in res.stderr

# Build sketch from .pde file
res = run_command(f"compile --clean -b {fqbn} {sketch_pde_file}")
assert res.failed
assert "Error during build: opening sketch: multiple main sketch files found" in res.stderr
assert "Error during build: Can't open sketch: multiple main sketch files found" in res.stderr


def test_compile_sketch_case_mismatch_fails(run_command, data_dir):
Expand All @@ -718,15 +718,15 @@ def test_compile_sketch_case_mismatch_fails(run_command, data_dir):
# * Compiling with sketch path
res = run_command(f"compile --clean -b {fqbn} {sketch_path}")
assert res.failed
assert "Error during build: opening sketch: no valid sketch found" in res.stderr
assert "Error during build: Can't open sketch: no valid sketch found" in res.stderr
# * Compiling with sketch main file
res = run_command(f"compile --clean -b {fqbn} {sketch_main_file}")
assert res.failed
assert "Error during build: opening sketch: no valid sketch found" in res.stderr
assert "Error during build: Can't open sketch: no valid sketch found" in res.stderr
# * Compiling in sketch path
res = run_command(f"compile --clean -b {fqbn}", custom_working_dir=sketch_path)
assert res.failed
assert "Error during build: opening sketch: no valid sketch found" in res.stderr
assert "Error during build: Can't open sketch: no valid sketch found" in res.stderr


def test_compile_with_only_compilation_database_flag(run_command, data_dir):
Expand Down
7 changes: 5 additions & 2 deletions test/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ def test_core_updateindex_url_not_found(run_command, httpserver):
result = run_command(f"core update-index --additional-urls={url}")
assert result.failed
lines = [l.strip() for l in result.stderr.splitlines()]
assert f"Error updating index: downloading index {url}: 404 NOT FOUND" in lines
assert f"Error updating index: Error downloading index '{url}': Server responded with: 404 NOT FOUND" in lines


def test_core_updateindex_internal_server_error(run_command, httpserver):
Expand All @@ -190,7 +190,10 @@ def test_core_updateindex_internal_server_error(run_command, httpserver):
result = run_command(f"core update-index --additional-urls={url}")
assert result.failed
lines = [l.strip() for l in result.stderr.splitlines()]
assert f"Error updating index: downloading index {url}: 500 INTERNAL SERVER ERROR" in lines
assert (
f"Error updating index: Error downloading index '{url}': Server responded with: 500 INTERNAL SERVER ERROR"
in lines
)


def test_core_install_without_updateindex(run_command):
Expand Down
10 changes: 3 additions & 7 deletions test/test_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,18 +117,14 @@ def test_list_exit_code(run_command):
# Verify lib list command fails because specified platform is not installed
result = run_command("lib list -b arduino:samd:mkr1000")
assert result.failed
assert (
result.stderr.strip() == "Error listing Libraries: loading board data: platform arduino:samd is not installed"
)
assert result.stderr.strip() == "Error listing Libraries: Unknown FQBN: platform arduino:samd is not installed"

assert run_command('lib install "AllThingsTalk LoRaWAN SDK"')

# Verifies lib list command keeps failing
result = run_command("lib list -b arduino:samd:mkr1000")
assert result.failed
assert (
result.stderr.strip() == "Error listing Libraries: loading board data: platform arduino:samd is not installed"
)
assert result.stderr.strip() == "Error listing Libraries: Unknown FQBN: platform arduino:samd is not installed"

assert run_command("core install arduino:samd")

Expand Down Expand Up @@ -224,7 +220,7 @@ def test_install(run_command):
# (https://github.com/arduino/arduino-cli/issues/534)
res = run_command("lib install MD_Parola@3.2.0")
assert res.failed
assert "Error resolving dependencies for MD_Parola@3.2.0: dependency 'MD_MAX72xx' is not available" in res.stderr
assert "No valid dependencies solution found: dependency 'MD_MAX72xx' is not available" in res.stderr


def test_install_library_with_dependencies(run_command):
Expand Down
4 changes: 2 additions & 2 deletions test/test_sketch.py
Original file line number Diff line number Diff line change
Expand Up @@ -845,7 +845,7 @@ def test_sketch_archive_with_multiple_main_files(run_command, copy_sketch, worki
assert res.failed
assert "Sketches with .pde extension are deprecated, please rename the following files to .ino" in res.stderr
assert str(sketch_file.relative_to(sketch_dir)) in res.stderr
assert "Error archiving: multiple main sketch files found" in res.stderr
assert "Error archiving: Can't open sketch: multiple main sketch files found" in res.stderr


def test_sketch_archive_case_mismatch_fails(run_command, data_dir):
Expand All @@ -859,4 +859,4 @@ def test_sketch_archive_case_mismatch_fails(run_command, data_dir):

res = run_command(f'sketch archive "{sketch_path}"')
assert res.failed
assert "Error archiving: no valid sketch found" in res.stderr
assert "Error archiving: Can't open sketch: no valid sketch found" in res.stderr
10 changes: 8 additions & 2 deletions test/test_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,10 @@ def test_update_with_url_not_found(run_command, httpserver):
res = run_command(f"update --additional-urls={url}")
assert res.failed
lines = [l.strip() for l in res.stderr.splitlines()]
assert f"Error updating core and libraries index: downloading index {url}: 404 NOT FOUND" in lines
assert (
f"Error updating core and libraries index: Error downloading index '{url}':"
" Server responded with: 404 NOT FOUND" in lines
)


def test_update_with_url_internal_server_error(run_command, httpserver):
Expand All @@ -76,7 +79,10 @@ def test_update_with_url_internal_server_error(run_command, httpserver):
res = run_command(f"update --additional-urls={url}")
assert res.failed
lines = [l.strip() for l in res.stderr.splitlines()]
assert f"Error updating core and libraries index: downloading index {url}: 500 INTERNAL SERVER ERROR" in lines
assert (
f"Error updating core and libraries index: Error downloading index '{url}':"
" Server responded with: 500 INTERNAL SERVER ERROR" in lines
)


def test_update_showing_outdated_using_library_with_invalid_version(run_command, data_dir):
Expand Down