@@ -222,10 +222,10 @@ func TestFlagHeaderTakesPrecedenceOverProfile(t *testing.T) {
222222 }
223223}
224224
225- // TestAPIEditUsesCliStdout verifies that runAPIEdit wires the editor subprocess
226- // to c.Stdout rather than os.Stdout, so embedders that redirect c.Stdout capture
227- // any output the editor produces.
228- func TestAPIEditUsesCliStdout (t * testing.T ) {
225+ // TestConfigEditUsesCliStdout verifies that runConfigEdit wires the editor
226+ // subprocess to c.Stdout rather than os.Stdout, so embedders that redirect
227+ // c.Stdout capture any output the editor produces.
228+ func TestConfigEditUsesCliStdout (t * testing.T ) {
229229 if runtime .GOOS == "windows" {
230230 t .Skip ("editor test uses a POSIX shell script" )
231231 }
@@ -253,6 +253,35 @@ func TestAPIEditUsesCliStdout(t *testing.T) {
253253 if ! strings .Contains (out .String (), "editor-stdout" ) {
254254 t .Errorf ("expected editor stdout in c.Stdout, got: %q" , out .String ())
255255 }
256+ if strings .Contains (out .String (), "Wrote config:" ) {
257+ t .Errorf ("expected unchanged config edit not to print written path, got: %q" , out .String ())
258+ }
259+ }
260+
261+ func TestConfigEditPrintsWrittenPathWhenFileChanges (t * testing.T ) {
262+ if runtime .GOOS == "windows" {
263+ t .Skip ("editor test uses a POSIX shell script" )
264+ }
265+
266+ dir := t .TempDir ()
267+
268+ scriptPath := filepath .Join (dir , "editor.sh" )
269+ if err := os .WriteFile (scriptPath , []byte ("#!/bin/sh\n printf '{\" theme\" :{\" ok\" :\" green\" }}\\ n' > \" $1\" \n " ), 0o755 ); err != nil {
270+ t .Fatal (err )
271+ }
272+ t .Setenv ("VISUAL" , scriptPath )
273+ t .Setenv ("EDITOR" , "" )
274+
275+ c , out , _ := newTestCLI (t )
276+ cfgPath := filepath .Join (dir , "restish.json" )
277+ if err := os .WriteFile (cfgPath , []byte ("{}" ), 0o600 ); err != nil {
278+ t .Fatal (err )
279+ }
280+ c .Hooks ().ConfigPath = cfgPath
281+
282+ if err := c .Run ([]string {"restish" , "config" , "edit" }); err != nil {
283+ t .Fatalf ("config edit: %v" , err )
284+ }
256285 if ! strings .Contains (out .String (), "Wrote config: " + cfgPath ) {
257286 t .Errorf ("expected written config path in c.Stdout, got: %q" , out .String ())
258287 }
0 commit comments