Skip to content

Commit

Permalink
fix, Create directory of MarkDown report file with their directory pa…
Browse files Browse the repository at this point in the history
…th not their file name
  • Loading branch information
bauersimon authored and zimmski committed Apr 26, 2024
1 parent 2a81412 commit dd8a259
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
38 changes: 38 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,32 @@ func TestEvaluateExecute(t *testing.T) {
})
})
})

// This case cehcks 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 current work directory 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 current work directory right within the tests of this case to reproduce the problem and fix it forever.
validate(t, &testCase{
Name: "Current work directory contains a 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 @@ -161,7 +161,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 dd8a259

Please sign in to comment.