@@ -11,6 +11,7 @@ import (
11
11
"testing"
12
12
13
13
"github.com/google/go-cmp/cmp"
14
+ "github.com/nao1215/gup/internal/cmdinfo"
14
15
"github.com/nao1215/gup/internal/config"
15
16
"github.com/nao1215/gup/internal/file"
16
17
"github.com/nao1215/gup/internal/goutil"
@@ -517,16 +518,6 @@ func TestExecute_Import_WithInputOption(t *testing.T) {
517
518
}
518
519
}
519
520
520
- defer func () {
521
- os .RemoveAll (filepath .Join ("testdata" , ".config" , "fish" ))
522
- os .RemoveAll (filepath .Join ("testdata" , ".zsh" ))
523
- os .RemoveAll (filepath .Join ("testdata" , ".zshrc" ))
524
- os .RemoveAll (filepath .Join ("testdata" , ".bash_completion" ))
525
- os .RemoveAll (filepath .Join ("testdata" , ".config" , "gup" , "assets" ))
526
- os .RemoveAll (filepath .Join ("testdata" , "go" ))
527
- os .RemoveAll (filepath .Join ("testdata" , ".cache" ))
528
- }()
529
-
530
521
orgStdout := print .Stdout
531
522
orgStderr := print .Stderr
532
523
pr , pw , err := os .Pipe ()
@@ -687,16 +678,6 @@ func TestExecute_Update(t *testing.T) {
687
678
}
688
679
}
689
680
690
- defer func () {
691
- os .RemoveAll (filepath .Join ("testdata" , ".config" , "fish" ))
692
- os .RemoveAll (filepath .Join ("testdata" , ".zsh" ))
693
- os .RemoveAll (filepath .Join ("testdata" , ".zshrc" ))
694
- os .RemoveAll (filepath .Join ("testdata" , ".bash_completion" ))
695
- os .RemoveAll (filepath .Join ("testdata" , ".config" , "gup" , "assets" ))
696
- os .RemoveAll (filepath .Join ("testdata" , "go" ))
697
- os .RemoveAll (filepath .Join ("testdata" , ".cache" ))
698
- }()
699
-
700
681
orgStdout := print .Stdout
701
682
orgStderr := print .Stderr
702
683
pr , pw , err := os .Pipe ()
@@ -791,16 +772,6 @@ func TestExecute_Update_DryRun(t *testing.T) {
791
772
}
792
773
}
793
774
794
- defer func () {
795
- os .RemoveAll (filepath .Join ("testdata" , ".config" , "fish" ))
796
- os .RemoveAll (filepath .Join ("testdata" , ".zsh" ))
797
- os .RemoveAll (filepath .Join ("testdata" , ".zshrc" ))
798
- os .RemoveAll (filepath .Join ("testdata" , ".bash_completion" ))
799
- os .RemoveAll (filepath .Join ("testdata" , ".config" , "gup" , "assets" ))
800
- os .RemoveAll (filepath .Join ("testdata" , "go" ))
801
- os .RemoveAll (filepath .Join ("testdata" , ".cache" ))
802
- }()
803
-
804
775
orgStdout := print .Stdout
805
776
orgStderr := print .Stderr
806
777
pr , pw , err := os .Pipe ()
@@ -834,3 +805,43 @@ func TestExecute_Update_DryRun(t *testing.T) {
834
805
t .Errorf ("failed to update posixer command" )
835
806
}
836
807
}
808
+
809
+ func TestExecute_Completion (t * testing.T ) {
810
+ t .Run ("generate completion file" , func (t * testing.T ) {
811
+ os .Args = []string {"gup" , "completion" }
812
+ Execute ()
813
+
814
+ bash := filepath .Join (os .Getenv ("HOME" ), ".bash_completion" )
815
+ if runtime .GOOS == "windows" {
816
+ if file .IsFile (bash ) {
817
+ t .Errorf ("generate %s, however shell completion file is not generated on Windows" , bash )
818
+ }
819
+ } else {
820
+ if ! file .IsFile (bash ) {
821
+ t .Errorf ("failed to generate %s" , bash )
822
+ }
823
+ }
824
+
825
+ fish := filepath .Join (os .Getenv ("HOME" ), ".config" , "fish" , "completions" , cmdinfo .Name + ".fish" )
826
+ if runtime .GOOS == "windows" {
827
+ if file .IsFile (fish ) {
828
+ t .Errorf ("generate %s, however shell completion file is not generated on Windows" , fish )
829
+ }
830
+ } else {
831
+ if ! file .IsFile (fish ) {
832
+ t .Errorf ("failed to generate %s" , fish )
833
+ }
834
+ }
835
+
836
+ zsh := filepath .Join (os .Getenv ("HOME" ), ".zsh" , "completion" , "_" + cmdinfo .Name )
837
+ if runtime .GOOS == "windows" {
838
+ if file .IsFile (zsh ) {
839
+ t .Errorf ("generate %s, however shell completion file is not generated on Windows" , zsh )
840
+ }
841
+ } else {
842
+ if ! file .IsFile (zsh ) {
843
+ t .Errorf ("failed to generate %s" , zsh )
844
+ }
845
+ }
846
+ })
847
+ }
0 commit comments