aboutsummaryrefslogtreecommitdiffstats
path: root/pkg/aflow/tool/codeeditor
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/aflow/tool/codeeditor')
-rw-r--r--pkg/aflow/tool/codeeditor/codeeditor.go8
-rw-r--r--pkg/aflow/tool/codeeditor/codeeditor_test.go19
2 files changed, 25 insertions, 2 deletions
diff --git a/pkg/aflow/tool/codeeditor/codeeditor.go b/pkg/aflow/tool/codeeditor/codeeditor.go
index 750dba5d8..4ee3fe0d2 100644
--- a/pkg/aflow/tool/codeeditor/codeeditor.go
+++ b/pkg/aflow/tool/codeeditor/codeeditor.go
@@ -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
}
@@ -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
}
diff --git a/pkg/aflow/tool/codeeditor/codeeditor_test.go b/pkg/aflow/tool/codeeditor/codeeditor_test.go
index 06a97d7af..0b066e3b5 100644
--- a/pkg/aflow/tool/codeeditor/codeeditor_test.go
+++ b/pkg/aflow/tool/codeeditor/codeeditor_test.go
@@ -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