@@ -28,27 +28,20 @@ func getProjectWd() string {
2828}
2929
3030func Test_Cli_Error (t * testing.T ) {
31- t .Parallel ()
3231 r := require .New (t )
3332
3433 binPath := filepath .Join (t .TempDir (), "hype" )
3534 buildBin (binPath )
3635
3736 root := filepath .Join (getProjectWd (), "testdata" , "to_md" , "source_code" , "broken" )
38- err := os .Chdir (root )
39- r .NoError (err )
37+ t .Chdir (root )
4038
4139 args := []string {"export" , "-format=markdown" , "-f" , "hype.md" }
4240
4341 t .Logf ("Running command: %s %s, root: %s" , binPath , strings .Join (args , " " ), root )
4442
45- hypeCmd := exec .Command (binPath , args ... )
46- var stderr bytes.Buffer
47- var stdout bytes.Buffer
48- hypeCmd .Stderr = & stderr
49- hypeCmd .Stdout = & stdout
50-
51- err = hypeCmd .Run ()
43+ hypeCmd , stdout , _ := setupCmd (binPath , args )
44+ err := hypeCmd .Run ()
5245 r .Error (err )
5346
5447 r .Equal (0 , stdout .Len ())
@@ -60,26 +53,31 @@ func Test_Cli_Error(t *testing.T) {
6053 r .Equal (1 , exitCode )
6154}
6255
56+ func setupCmd (binPath string , args []string ) (* exec.Cmd , * bytes.Buffer , * bytes.Buffer ) {
57+ cmd := exec .Command (binPath , args ... )
58+ var stderr bytes.Buffer
59+ var stdout bytes.Buffer
60+ cmd .Stderr = & stderr
61+ cmd .Stdout = & stdout
62+
63+ return cmd , & stdout , & stderr
64+ }
65+
6366func Test_Cli_Success (t * testing.T ) {
64- t .Parallel ()
6567 r := require .New (t )
6668
6769 binPath := filepath .Join (t .TempDir (), "hype" )
6870 buildBin (binPath )
6971
7072 root := filepath .Join (getProjectWd (), "testdata" , "to_md" , "source_code" , "full" )
71- err := os .Chdir (root )
72- r .NoError (err )
73+ t .Chdir (root )
7374
7475 args := []string {"export" , "-format=markdown" , "-f" , "hype.md" }
76+
7577 t .Logf ("Running command: %s %s" , binPath , strings .Join (args , " " ))
76- hypeCmd := exec .Command (binPath , args ... )
77- var stderr bytes.Buffer
78- var stdout bytes.Buffer
79- hypeCmd .Stderr = & stderr
80- hypeCmd .Stdout = & stdout
8178
82- err = hypeCmd .Run ()
79+ hypeCmd , stdout , stderr := setupCmd (binPath , args )
80+ err := hypeCmd .Run ()
8381 if err != nil {
8482 fmt .Printf ("%s\n " , stderr .String ())
8583 }
@@ -97,3 +95,58 @@ func Test_Cli_Success(t *testing.T) {
9795
9896 r .Equal (exp , act )
9997}
98+
99+ func Test_Output_Flag_Error (t * testing.T ) {
100+ r := require .New (t )
101+
102+ binPath := filepath .Join (t .TempDir (), "hype" )
103+ buildBin (binPath )
104+
105+ root := filepath .Join (getProjectWd (), "testdata" , "to_md" , "source_code" , "broken" )
106+ t .Chdir (root )
107+
108+ inputFile := "hype.md"
109+ outputFile := inputFile
110+
111+ args := []string {"export" , "-format=markdown" , "-f" , inputFile , "-o" , outputFile }
112+ hypeCmd , _ , _ := setupCmd (binPath , args )
113+ err := hypeCmd .Run ()
114+ r .Error (err )
115+
116+ info , err := os .Stat (filepath .Join (root , inputFile ))
117+ r .NoError (err )
118+
119+ r .True (info .Size () > 0 )
120+ }
121+
122+ func Test_Output_Flag_Success (t * testing.T ) {
123+ r := require .New (t )
124+
125+ binPath := filepath .Join (t .TempDir (), "hype" )
126+ buildBin (binPath )
127+
128+ root := filepath .Join (getProjectWd (), "testdata" , "to_md" , "source_code" , "full" )
129+ t .Chdir (root )
130+
131+ inputFile := "hype.md"
132+ outputFile := filepath .Join (t .TempDir (), "output.md" )
133+
134+ args := []string {"export" , "-format=markdown" , "-f" , inputFile , "-o" , outputFile }
135+ hypeCmd , _ , _ := setupCmd (binPath , args )
136+ err := hypeCmd .Run ()
137+ r .NoError (err )
138+
139+ info , err := os .Stat (outputFile )
140+ r .NoError (err )
141+ r .True (info .Size () > 0 )
142+
143+ bExp , err := os .ReadFile (filepath .Join (root , "hype.gold" ))
144+ r .NoError (err )
145+ bAct , err := os .ReadFile (outputFile )
146+ r .NoError (err )
147+
148+ exp := strings .TrimSpace (string (bExp ))
149+ act := strings .TrimSpace (string (bAct ))
150+
151+ r .Equal (exp , act )
152+ }
0 commit comments