Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions pkg/aflow/action/crash/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ func testPatch(ctx *aflow.Context, args testArgs) (testResult, error) {
if err != nil {
return res, err
}
if diff == "" {
res.TestError = "No patch to test."
return res, nil
}
res.PatchDiff = diff

if err := kernel.BuildKernel(args.KernelScratchSrc, args.KernelScratchSrc, args.KernelConfig, false); err != nil {
Expand Down
14 changes: 10 additions & 4 deletions pkg/aflow/flow/patching/patching.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,14 +130,17 @@ The explanation of the root cause of the bug is:
{{.BugExplanation}}

{{if .TestError}}
Another developer tried to fix this bug, and come up with the following patch:

{{.PatchDiff}}

and the following explanation:
Another developer tried to fix this bug, and come up with the following strategy for fixing:

{{.PatchExplanation}}

{{/* A TestError without PatchDiff means the previous invocation did not generate any patch. */}}
{{if .PatchDiff}}
and the following patch:

{{.PatchDiff}}

However, the patch testing failed with the following error:

{{.TestError}}
Expand All @@ -149,6 +152,9 @@ then create a new patch from scratch.
Note: in both cases the source tree does not contain the patch yet
(so if you want to create a new fixed patch, you need to recreate it
in its entirety from scratch using the codeeditor tool).
{{else}}
If the strategy looks reasonable to you, proceed with patch generation.
{{end}}
{{end}}
`

Expand Down
1 change: 1 addition & 0 deletions pkg/aflow/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ func walkTemplate(n parse.Node, used map[string]bool, errp *error) {
used[n.Ident[0]] = true
case *parse.VariableNode:
case *parse.TextNode:
case *parse.IdentifierNode:
default:
noteError(errp, "unhandled node type %T", n)
}
Expand Down
8 changes: 8 additions & 0 deletions pkg/aflow/template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,14 @@ func TestTemplate(t *testing.T) {
},
err: "input foo is not provided",
},
{
template: `{{if and .foo .bar}} yes {{end}}`,
vars: map[string]reflect.Type{
"foo": reflect.TypeFor[bool](),
"bar": reflect.TypeFor[int](),
},
used: []string{"foo", "bar"},
},
}
for i, test := range tests {
t.Run(fmt.Sprint(i), func(t *testing.T) {
Expand Down
8 changes: 6 additions & 2 deletions pkg/aflow/tool/codeeditor/codeeditor.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,11 @@ func codeeditor(ctx *aflow.Context, state state, args args) (struct{}, error) {
return struct{}{}, aflow.BadCallError("CurrentCode snippet matched %v places,"+
" increase context in CurrentCode to avoid ambiguity", matches)
}
err = osutil.WriteFile(file, slices.Concat(newLines...))
newFileData := slices.Concat(newLines...)
if bytes.Equal(fileData, newFileData) {
return struct{}{}, aflow.BadCallError("The edit does not change the code.")
}
err = osutil.WriteFile(file, newFileData)
return struct{}{}, err
}

Expand All @@ -97,7 +101,7 @@ func replace(lines, src, dst [][]byte, fuzzy bool) (newLines [][]byte, matches i
si++
continue
}
if len(l) == 0 {
if len(l) == 0 && li != i {
li++
continue
}
Expand Down
19 changes: 19 additions & 0 deletions pkg/aflow/tool/codeeditor/codeeditor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,25 @@ foo`)
)
}

func TestCodeeditorNopEdit(t *testing.T) {
dir := writeTestFile(t, "src.c", `
line0
line1
`)
aflow.TestTool(t, Tool,
state{
KernelScratchSrc: dir,
},
args{
SourceFile: "src.c",
CurrentCode: " line0",
NewCode: "line0",
},
struct{}{},
`The edit does not change the code.`,
)
}

func TestCodeeditorReplacement(t *testing.T) {
type Test struct {
curFile string
Expand Down
Loading