From dd8a25980b292920737c522c2b3984a570c12e13 Mon Sep 17 00:00:00 2001 From: Simon Bauer Date: Fri, 26 Apr 2024 12:03:01 +0200 Subject: [PATCH] fix, Create directory of MarkDown report file with their directory path not their file name --- cmd/eval-dev-quality/cmd/evaluate_test.go | 38 +++++++++++++++++++++++ evaluate/report/markdown.go | 2 +- 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/cmd/eval-dev-quality/cmd/evaluate_test.go b/cmd/eval-dev-quality/cmd/evaluate_test.go index 6d628ba8..b9f94fa1 100644 --- a/cmd/eval-dev-quality/cmd/evaluate_test.go +++ b/cmd/eval-dev-quality/cmd/evaluate_test.go @@ -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) @@ -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() { @@ -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, + }, + }) } diff --git a/evaluate/report/markdown.go b/evaluate/report/markdown.go index 7fe37eb2..c7c2c41d 100644 --- a/evaluate/report/markdown.go +++ b/evaluate/report/markdown.go @@ -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)