-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #68 from muandane/fix/commitcmd
Fix: commit printing tabs
- Loading branch information
Showing
11 changed files
with
290 additions
and
421 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package cmd | ||
|
||
import ( | ||
"bytes" | ||
"io" | ||
"os" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
// captureOutput captures and returns the output of a function that prints to stdout. | ||
func captureOutput(f func()) string { | ||
// Save the current stdout | ||
oldStdout := os.Stdout | ||
|
||
// Create a pipe to capture stdout | ||
r, w, _ := os.Pipe() | ||
os.Stdout = w | ||
|
||
// Execute the function | ||
f() | ||
|
||
// Close the writer and restore stdout | ||
_ = w.Close() | ||
os.Stdout = oldStdout | ||
|
||
// Read the captured output | ||
var buf bytes.Buffer | ||
_, _ = io.Copy(&buf, r) | ||
_ = r.Close() | ||
|
||
return buf.String() | ||
} | ||
|
||
// TestManCmd tests the `manCmd` to ensure it outputs the manual correctly. | ||
func TestManCmd(t *testing.T) { | ||
// Capturing the output of the manCmd. | ||
output := captureOutput(func() { | ||
manCmd.Run(&cobra.Command{}, []string{}) | ||
}) | ||
|
||
// Check that the output contains key sections. | ||
sections := []string{ | ||
"NAME", | ||
"SYNOPSIS", | ||
"DESCRIPTION", | ||
"OPTIONS", | ||
"EXAMPLES", | ||
"AUTHOR", | ||
"COPYRIGHT", | ||
} | ||
|
||
for _, section := range sections { | ||
if !strings.Contains(output, section) { | ||
t.Errorf("Expected section %s in man page output, but it was not found.", section) | ||
} | ||
} | ||
} |
Oops, something went wrong.