Skip to content

Commit

Permalink
fix, Properly create report file directory
Browse files Browse the repository at this point in the history
  • Loading branch information
bauersimon committed Apr 26, 2024
1 parent b719180 commit 508ad0c
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
40 changes: 40 additions & 0 deletions cmd/eval-dev-quality/cmd/evaluate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ func TestEvaluateExecute(t *testing.T) {
type testCase struct {
Name string

Before func(t *testing.T, resultPath string)
After func(t *testing.T, resultPath string)

Arguments []string

ExpectedOutputValidate func(t *testing.T, output string, resultPath string)
Expand All @@ -46,6 +49,13 @@ func TestEvaluateExecute(t *testing.T) {
t.Run(tc.Name, func(t *testing.T) {
temporaryPath := t.TempDir()

if tc.Before != nil {
tc.Before(t, temporaryPath)
}
if tc.After != nil {
defer tc.After(t, temporaryPath)
}

logOutput, logger := log.Buffer()
defer func() {
if t.Failed() {
Expand Down Expand Up @@ -218,4 +228,34 @@ func TestEvaluateExecute(t *testing.T) {
})
})
})

// This was a beautiful bug where the Markdown export crashed when the current working directory contained a README.md file.
// While this is not the case during the tests (as the CWD is the directory of this file), it certainly caused problems when our binary was executed from the repository root (which of course contained a README.md).
// Therefore, we sadly have to modify the CWD right within the tests of this case.
validate(t, &testCase{
Name: "CWD Contains README.md",

Before: func(t *testing.T, resultPath string) {
if err := os.Remove("README.md"); err != nil {
require.Contains(t, err.Error(), "no such file or directory")
}
require.NoError(t, os.WriteFile("README.md", []byte(""), 0644))
},
After: func(t *testing.T, resultPath string) {
require.NoError(t, os.Remove("README.md"))
},

Arguments: []string{
"--language", "golang",
"--model", "symflower/symbolic-execution",
},

ExpectedResultFiles: map[string]func(t *testing.T, filePath string, data string){
"categories.svg": nil,
"evaluation.csv": nil,
"evaluation.log": nil,
"README.md": nil,
"symflower_symbolic-execution/golang/golang/plain.log": nil,
},
})
}
2 changes: 1 addition & 1 deletion evaluate/report/markdown.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ func (m Markdown) format(writer io.Writer, markdownFileDirectoryPath string) err

// WriteToFile renders the Markdown to the given file.
func (m Markdown) WriteToFile(path string) (err error) {
if err = os.MkdirAll(filepath.Base(path), 0755); err != nil {
if err = os.MkdirAll(filepath.Dir(path), 0755); err != nil {
return pkgerrors.WithStack(err)
}
file, err := os.Create(path)
Expand Down

0 comments on commit 508ad0c

Please sign in to comment.