Skip to content

Commit

Permalink
Save output
Browse files Browse the repository at this point in the history
  • Loading branch information
the-redback committed May 15, 2020
1 parent 6ca764e commit 95ed8cc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
11 changes: 9 additions & 2 deletions cmd/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func plain(raw []byte) string {
return b.String()
}

func judge(sampleID, command string) error {
func judge(sampleID, command string, saveOutput bool) error {
inPath := fmt.Sprintf("in%v.txt", sampleID)
ansPath := fmt.Sprintf("ans%v.txt", sampleID)
input, err := os.Open(inPath)
Expand Down Expand Up @@ -113,6 +113,13 @@ func judge(sampleID, command string) error {
ans := plain(b)
out := plain(o.Bytes())

if saveOutput {
outputPath := fmt.Sprintf("out%v.txt", sampleID)
if err := ioutil.WriteFile(outputPath, []byte(out), 0644); err != nil{
fmt.Println( color.New(color.FgRed).Sprintf("Error while writing output file. error: %v", err))
}
}

state := ""
diff := ""
if out == ans {
Expand Down Expand Up @@ -193,7 +200,7 @@ func Test() (err error) {
}
if s := filter(template.Script); len(s) > 0 {
for _, i := range samples {
err := judge(i, s)
err := judge(i, s, cfg.SaveOutput)
if err != nil {
color.Red(err.Error())
}
Expand Down
1 change: 1 addition & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ type Config struct {
Template []CodeTemplate `json:"template"`
Default int `json:"default"`
GenAfterParse bool `json:"gen_after_parse"`
SaveOutput bool `json:"save_output"`
Host string `json:"host"`
Proxy string `json:"proxy"`
FolderName map[string]string `json:"folder_name"`
Expand Down

0 comments on commit 95ed8cc

Please sign in to comment.