-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-Authored-By: Llewellyn Falco <[email protected]> Co-Authored-By: Stephen Young <[email protected]>
- Loading branch information
1 parent
4e1dc5e
commit 15d1ffb
Showing
4 changed files
with
79 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,3 +27,5 @@ _testmain.go | |
*.test | ||
*.prof | ||
coverage.txt | ||
|
||
.approval_tests_temp |
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,58 @@ | ||
package reporters | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"github.com/approvals/go-approval-tests/utils" | ||
) | ||
|
||
var ( | ||
directory = ".approval_tests_temp" | ||
filenameWithoutExtention = directory + "/approval_script" | ||
filename = "" | ||
) | ||
|
||
type approvalScript struct{} | ||
|
||
// NewAllFailingTestReporter copies move file command to your clipboard | ||
func NewReporterThatCreatesAnApprovalScript() Reporter { | ||
initializeFile() | ||
return &approvalScript{} | ||
} | ||
|
||
func (s *approvalScript) Report(approved, received string) bool { | ||
move := getMoveCommandText(approved, received) + "\n" | ||
|
||
utils.AppendToFile(filename, move) | ||
|
||
return true | ||
} | ||
|
||
func initializeFile() { | ||
if filename != "" { | ||
return | ||
} | ||
|
||
filename = filenameWithoutExtention + ".sh" | ||
|
||
// create the file and setup the parent directory if needed | ||
err := os.MkdirAll(directory, os.ModePerm) | ||
if err != nil { | ||
fmt.Println("Error creating directory: ", err) | ||
return | ||
} | ||
|
||
// create the file and make it executable in one step | ||
file, err := os.OpenFile(filename, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0755) | ||
if err != nil { | ||
fmt.Println("Error creating file: ", err) | ||
return | ||
} | ||
file.Close() | ||
|
||
utils.AppendToFile(filename, "#!/bin/bash\n") | ||
|
||
fmt.Println("You can run the approval script by executing: ", filename) | ||
|
||
} |
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