Skip to content
This repository has been archived by the owner on Dec 14, 2024. It is now read-only.

Option for writing program output in out#.txt #98

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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