-
Notifications
You must be signed in to change notification settings - Fork 527
Enhancement: goal Error UX Improvement
#4951
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
Changes from all commits
89f980a
59244bf
d57acc2
0e430cc
a64a924
7a7ff1f
dac1023
aaf63bf
26c0945
2072cab
cb6308b
37c97b1
2241126
7d14d87
b30ca2f
3c91244
5f7de10
7db01b5
5e4f0ea
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,6 +19,7 @@ package logic | |
| import ( | ||
| "bytes" | ||
| "encoding/hex" | ||
| "errors" | ||
| "fmt" | ||
| "regexp" | ||
| "strings" | ||
|
|
@@ -1457,7 +1458,7 @@ done:` | |
| require.Equal(t, expectedProgBytes, ops.Program) | ||
| } | ||
|
|
||
| func TestMultipleErrors(t *testing.T) { | ||
| func TestSeveralErrors(t *testing.T) { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Renaming as the natural name of a new unit test for renamed function |
||
| partitiontest.PartitionTest(t) | ||
| t.Parallel() | ||
|
|
||
|
|
@@ -3053,3 +3054,108 @@ func TestAssemblePushConsts(t *testing.T) { | |
| source = `pushbytess "x" "y"; +` | ||
| testProg(t, source, AssemblerMaxVersion, Expect{1, "+ arg 1 wanted type uint64 got []byte"}) | ||
| } | ||
|
|
||
| func TestAssembleEmpty(t *testing.T) { | ||
| partitiontest.PartitionTest(t) | ||
| t.Parallel() | ||
|
|
||
| emptyExpect := Expect{0, "Cannot assemble empty program text"} | ||
| emptyPrograms := []string{ | ||
| "", | ||
| " ", | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What about "label:" or " //"
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The goal of the PR was to address the original concern (see #2585 ) which is when someone basically accidentally puts in a blank program for assembly. I expanded the definition to include any program that consists of all whitespace. We can expand even further, but it does seem to me to be a can of worms that I am inclined to push back against... However, I'm more than happy to test this out experimentally in our pair programming project. |
||
| " \n\t\t\t\n\n ", | ||
| " \n \t \t \t \n \n \n\n", | ||
| } | ||
|
|
||
| nonEmpty := " \n \t \t \t int 1 \n \n \t \t \n\n" | ||
|
|
||
| for version := uint64(1); version <= AssemblerMaxVersion; version++ { | ||
| for _, prog := range emptyPrograms { | ||
| testProg(t, prog, version, emptyExpect) | ||
| } | ||
| testProg(t, nonEmpty, version) | ||
| } | ||
| } | ||
|
|
||
| func TestReportMultipleErrors(t *testing.T) { | ||
| partitiontest.PartitionTest(t) | ||
| t.Parallel() | ||
|
|
||
| assertWithMsg := func(t *testing.T, expectedOutput string, b bytes.Buffer) { | ||
| if b.String() != expectedOutput { | ||
| t.Errorf("Unexpected output: got %q, want %q", b.String(), expectedOutput) | ||
| } | ||
| } | ||
|
|
||
| ops := &OpStream{ | ||
| Errors: []lineError{ | ||
| {Line: 1, Err: errors.New("error 1")}, | ||
| {Err: errors.New("error 2")}, | ||
| {Line: 3, Err: errors.New("error 3")}, | ||
| }, | ||
| Warnings: []error{ | ||
| errors.New("warning 1"), | ||
| errors.New("warning 2"), | ||
| }, | ||
| } | ||
|
|
||
| // Test the case where fname is not empty | ||
| var b bytes.Buffer | ||
| ops.ReportMultipleErrors("test.txt", &b) | ||
| expected := `test.txt: 1: error 1 | ||
| test.txt: 0: error 2 | ||
| test.txt: 3: error 3 | ||
| test.txt: warning 1 | ||
| test.txt: warning 2 | ||
| ` | ||
| assertWithMsg(t, expected, b) | ||
|
|
||
| // Test the case where fname is empty | ||
| b.Reset() | ||
| ops.ReportMultipleErrors("", &b) | ||
| expected = `1: error 1 | ||
| 0: error 2 | ||
| 3: error 3 | ||
| warning 1 | ||
| warning 2 | ||
| ` | ||
| assertWithMsg(t, expected, b) | ||
|
|
||
| // no errors or warnings at all | ||
| ops = &OpStream{} | ||
| b.Reset() | ||
| ops.ReportMultipleErrors("blah blah", &b) | ||
| expected = "" | ||
| assertWithMsg(t, expected, b) | ||
|
|
||
| // more than 10 errors: | ||
| file := "great-file.go" | ||
| les := []lineError{} | ||
| expectedStrs := []string{} | ||
| for i := 1; i <= 11; i++ { | ||
| errS := fmt.Errorf("error %d", i) | ||
| les = append(les, lineError{i, errS}) | ||
| if i <= 10 { | ||
| expectedStrs = append(expectedStrs, fmt.Sprintf("%s: %d: %s", file, i, errS)) | ||
| } | ||
| } | ||
| expected = strings.Join(expectedStrs, "\n") + "\n" | ||
| ops = &OpStream{Errors: les} | ||
| b.Reset() | ||
| ops.ReportMultipleErrors(file, &b) | ||
| assertWithMsg(t, expected, b) | ||
|
|
||
| // exactly 1 error + filename | ||
| ops = &OpStream{Errors: []lineError{{42, errors.New("super annoying error")}}} | ||
| b.Reset() | ||
| ops.ReportMultipleErrors("galaxy.py", &b) | ||
| expected = "galaxy.py: 1 error: 42: super annoying error\n" | ||
| assertWithMsg(t, expected, b) | ||
|
|
||
| // exactly 1 error w/o filename | ||
| ops = &OpStream{Errors: []lineError{{42, errors.New("super annoying error")}}} | ||
| b.Reset() | ||
| ops.ReportMultipleErrors("", &b) | ||
| expected = "1 error: 42: super annoying error\n" | ||
| assertWithMsg(t, expected, b) | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.