cmd/cue/cmd: include tool and test files in fix

This is semantically not entirely correct, but is unlikely
to give issues.

Change-Id: Iaad6de25160a6c92e9ddc7d81a36bbd3fbe3d379
Reviewed-on: https://cue-review.googlesource.com/c/cue/+/6440
Reviewed-by: CUE cueckoo <cueckoo@gmail.com>
Reviewed-by: Marcel van Lohuizen <mpvl@golang.org>
diff --git a/cmd/cue/cmd/fix.go b/cmd/cue/cmd/fix.go
index eccab53..5f5e4d3 100644
--- a/cmd/cue/cmd/fix.go
+++ b/cmd/cue/cmd/fix.go
@@ -76,9 +76,17 @@
 		}
 	}
 
-	instances := load.Instances(args, &load.Config{})
+	instances := load.Instances(args, &load.Config{
+		Tests: true,
+		Tools: true,
+	})
 
 	for _, i := range instances {
+		a := append(i.ToolCUEFiles, i.TestCUEFiles...)
+		for _, f := range a {
+			file := i.Abs(f)
+			_ = i.AddFile(file, nil)
+		}
 		if i.Err != nil {
 			return i.Err
 		}
diff --git a/cmd/cue/cmd/testdata/script/fix.txt b/cmd/cue/cmd/testdata/script/fix.txt
index 5f663aa..6f705d6 100644
--- a/cmd/cue/cmd/testdata/script/fix.txt
+++ b/cmd/cue/cmd/testdata/script/fix.txt
@@ -1,6 +1,8 @@
 cue fix
 
 cmp foo/foo.cue expect/foo/foo_cue
+cmp foo/foo_test.cue expect/foo/foo_test_cue
+cmp foo/foo_tool.cue expect/foo/foo_tool_cue
 cmp bar/bar.cue expect/bar/bar_cue
 cmp cue.mod/pkg/foobar.org/notimported/notimported.cue expect/cue.mod/pkg/foobar.org/notimported/notimported.cue
 cmp cue.mod/gen/foobar.org/imported/imported.cue expect/cue.mod/gen/foobar.org/imported/imported.cue
@@ -52,6 +54,24 @@
 a: Def
 c: [Def.b]: int
 
+-- foo/foo_test.cue --
+package foo
+
+A :: int
+
+-- expect/foo/foo_test_cue --
+package foo
+
+#A: int
+-- foo/foo_tool.cue --
+package foo
+
+B :: int
+
+-- expect/foo/foo_tool_cue --
+package foo
+
+#B: int
 -- expect/bar/bar_cue --
 package bar