From 95ed8cc103358f92c139238ec422852a54094803 Mon Sep 17 00:00:00 2001 From: the-redback Date: Sat, 16 May 2020 04:08:03 +0600 Subject: [PATCH] Save output --- cmd/test.go | 11 +++++++++-- config/config.go | 1 + 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/cmd/test.go b/cmd/test.go index 072c9316..56b140bc 100644 --- a/cmd/test.go +++ b/cmd/test.go @@ -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) @@ -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 { @@ -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()) } diff --git a/config/config.go b/config/config.go index e2f4bef7..9d751dbb 100644 --- a/config/config.go +++ b/config/config.go @@ -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"`