Skip to content

Commit

Permalink
Language method to query which test framework should be used if any
Browse files Browse the repository at this point in the history
  • Loading branch information
zimmski committed Apr 22, 2024
1 parent 5d491dd commit dcb7b9b
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 1 deletion.
5 changes: 5 additions & 0 deletions language/golang/language.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ func (l *Language) TestFilePath(projectRootPath string, filePath string) (testFi
return strings.TrimSuffix(filePath, ".go") + "_test.go"
}

// TestFramework returns the human-readable name of the test framework that should be used.
func (l *Language) TestFramework() (testFramework string) {
return ""
}

var languageGoNoTestsMatch = regexp.MustCompile(`(?m)^DONE (\d+) tests.*in (.+?)$`)
var languageGoCoverageMatch = regexp.MustCompile(`(?m)^coverage: (\d+\.?\d+)% of statements`)
var languageGoNoCoverageMatch = regexp.MustCompile(`(?m)^coverage: \[no statements\]$`)
Expand Down
2 changes: 2 additions & 0 deletions language/language.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ type Language interface {
ImportPath(projectRootPath string, filePath string) (importPath string)
// TestFilePath returns the file path of a test file given the corresponding file path of the test's source file.
TestFilePath(projectRootPath string, filePath string) (testFilePath string)
// TestFramework returns the human-readable name of the test framework that should be used.
TestFramework() (testFramework string)

// Execute invokes the language specific testing on the given repository.
Execute(logger *log.Logger, repositoryPath string) (coverage float64, err error)
Expand Down
5 changes: 5 additions & 0 deletions language/testing/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ func (m *MockLanguage) TestFilePath(projectRootPath string, filePath string) (te
return m.Called(projectRootPath, filePath).String(0)
}

// TestFramework returns the human-readable name of the test framework that should be used.
func (m *MockLanguage) TestFramework() (testFramework string) {
return m.Called().String(0)
}

// Execute implements language.Language.
func (m *MockLanguage) Execute(logger *log.Logger, repositoryPath string) (coverage float64, err error) {
args := m.Called(logger, repositoryPath)
Expand Down
2 changes: 1 addition & 1 deletion model/llm/llm.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ type llmGenerateTestForFilePromptContext struct {

// llmGenerateTestForFilePromptTemplate is the template for generating an LLM test generation prompt.
var llmGenerateTestForFilePromptTemplate = template.Must(template.New("model-llm-generate-test-for-file-prompt").Parse(bytesutil.StringTrimIndentations(`
Given the following {{ .Language.Name }} code file "{{ .FilePath }}" with package "{{ .ImportPath }}", provide a test file for this code.
Given the following {{ .Language.Name }} code file "{{ .FilePath }}" with package "{{ .ImportPath }}", provide a test file for this code{{ with $testFramework := .Language.TestFramework }} with {{ $testFramework }} as a test framework{{ end }}.
The tests should produce 100 percent code coverage and must compile.
The response must contain only the test code and nothing else.
Expand Down

0 comments on commit dcb7b9b

Please sign in to comment.