Skip to content

Commit

Permalink
add stderr to the output report
Browse files Browse the repository at this point in the history
  • Loading branch information
chermehdi committed Mar 14, 2020
1 parent 8159d6a commit aa6a3ed
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions commands/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ var (
yellow = color.New(color.FgYellow).SprintfFunc()
)

const WorkDir = "work"

// Checks the output of a given testcase against it's expected output
type Checker interface {
// Execute the check (got, expected) and returns
Expand Down Expand Up @@ -84,15 +86,15 @@ type CaseStatus struct {
Stderr string
}

// Implementation must be able to prepare the working environement to compile and execute testscases,
// Implementation must be able to prepare the working environment to compile and execute testscases,
// And run each testcase and report the status back to the invoker, and perform any necessary cleanup (binaries created, directories created ...)
type Judge interface {
// setup the working directory and perform any necessary compilation of the task
// if the setup returned an error, the Judge should abort the operation and report the error back.
Setup() error

// Run on every testcase, and the status is reported back to the invoker.
// The implementation is free to Run all testcases at once, or report every testcase execution status once it finishes.
// Run on every test case, and the status is reported back to the invoker.
// The implementation is free to Run all testcases at once, or report every test case execution status once it finishes.
// If it's needed, running independent cases can be done on different go routines.
RunTestCase(CaseDescription) CaseStatus

Expand All @@ -101,6 +103,7 @@ type Judge interface {

// Return the working directory of the judge
WorkDir() string

// Cleanup the working directory, if an error occured, implementation must report it to the caller.
Cleanup() error
}
Expand Down Expand Up @@ -144,10 +147,17 @@ func getDisplayStatus(status int8) string {
return "Unknown"
}

func getStderrDisplay(stderr string) string {
if stderr == "" {
return "-"
}
return red(stderr)
}

func (c *ConsoleJudgeReport) Display() {
t := table.NewWriter()
t.SetOutputMirror(os.Stdout)
t.AppendHeader(table.Row{"#", "Test Name", "Status", "Custom", "Additional infos"})
t.AppendHeader(table.Row{"#", "Test Name", "Status", "Custom", "Additional infos", "Stderr"})
for i, stat := range c.Stats {
output := "None"
if stat.CheckerError != nil {
Expand All @@ -159,6 +169,7 @@ func (c *ConsoleJudgeReport) Display() {
getDisplayStatus(stat.Status),
c.Descs[i].CustomCase,
output,
getStderrDisplay(stat.Stderr),
})
}
t.SetStyle(table.StyleLight)
Expand Down Expand Up @@ -248,7 +259,7 @@ func (judge *JavaJudge) Setup() error {
if err != nil {
return err
}
workDirPath := path.Join(currentDir, "work")
workDirPath := path.Join(currentDir, WorkDir)
if _, err = os.Stat(workDirPath); os.IsNotExist(err) {
if err := os.Mkdir(workDirPath, 0777); err != nil {
return err
Expand All @@ -257,7 +268,7 @@ func (judge *JavaJudge) Setup() error {
//TODO(chermehdi): make the executables path configurable #14
// Compilation for Java
var stderrBuffer bytes.Buffer
cmd := exec.Command("javac", judge.Meta.TaskFile, "-d", "work")
cmd := exec.Command("javac", judge.Meta.TaskFile, "-d", WorkDir)
cmd.Dir = currentDir
cmd.Stderr = &stderrBuffer
if err = cmd.Run(); err != nil {
Expand Down Expand Up @@ -300,7 +311,7 @@ func (judge *CppJudge) Setup() error {
if err != nil {
return err
}
workDirPath := path.Join(currentDir, "work")
workDirPath := path.Join(currentDir, WorkDir)
if _, err = os.Stat(workDirPath); os.IsNotExist(err) {
if err := os.Mkdir(workDirPath, 0777); err != nil {
return err
Expand Down

0 comments on commit aa6a3ed

Please sign in to comment.