Skip to content

Commit

Permalink
Introduce the Ruby language
Browse files Browse the repository at this point in the history
Part of #300
  • Loading branch information
ruiAzevedo19 committed Aug 2, 2024
1 parent 4684a6f commit c7ae56a
Show file tree
Hide file tree
Showing 2 changed files with 138 additions and 0 deletions.
74 changes: 74 additions & 0 deletions language/ruby/language.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package ruby

import (
"path/filepath"
"strings"

"github.com/symflower/eval-dev-quality/language"
"github.com/symflower/eval-dev-quality/log"
)

// Language holds a Ruby language to evaluate a repository.
type Language struct{}

func init() {
language.Register(&Language{})
}

var _ language.Language = (*Language)(nil)

// ID returns the unique ID of this language.
func (l *Language) ID() (id string) {
return "ruby"
}

// Name is the prose name of this language.
func (l *Language) Name() (id string) {
return "Ruby"
}

// Files returns a list of relative file paths of the repository that should be evaluated.
func (l *Language) Files(logger *log.Logger, repositoryPath string) (filePaths []string, err error) {
return language.Files(logger, l, repositoryPath)
}

// ImportPath returns the import path of the given source file.
func (l *Language) ImportPath(projectRootPath string, filePath string) (importPath string) {
return "../lib/" + strings.TrimSuffix(filepath.Base(filePath), l.DefaultFileExtension())
}

// TestFilePath returns the file path of a test file given the corresponding file path of the test's source file.
func (l *Language) TestFilePath(projectRootPath string, filePath string) (testFilePath string) {
filePath = strings.ReplaceAll(filePath, "lib", "test")

return strings.TrimSuffix(filePath, l.DefaultFileExtension()) + l.DefaultTestFileSuffix()
}

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

// DefaultFileExtension returns the default file extension.
func (l *Language) DefaultFileExtension() string {
return ".rb"
}

// DefaultTestFileSuffix returns the default test file suffix.
func (l *Language) DefaultTestFileSuffix() string {
return "_test.rb"
}

// ExecuteTests invokes the language specific testing on the given repository.
func (l *Language) ExecuteTests(logger *log.Logger, repositoryPath string) (testResult *language.TestResult, problems []error, err error) {
logger.Panic("not implemented")

return testResult, problems, nil
}

// Mistakes builds a Ruby repository and returns the list of mistakes found.
func (l *Language) Mistakes(logger *log.Logger, repositoryPath string) (mistakes []string, err error) {
logger.Panic("not implemented")

return nil, nil
}
64 changes: 64 additions & 0 deletions language/ruby/language_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package ruby

import (
"path/filepath"
"testing"

"github.com/stretchr/testify/assert"
)

func TestLanguageTestFilePath(t *testing.T) {
type testCase struct {
Name string

ProjectRootPath string
FilePath string

ExpectedTestFilePath string
}

validate := func(t *testing.T, tc *testCase) {
t.Run(tc.Name, func(t *testing.T) {
ruby := Language{}
actualTestFilePath := ruby.TestFilePath(tc.ProjectRootPath, tc.FilePath)

assert.Equal(t, tc.ExpectedTestFilePath, actualTestFilePath)
})
}

validate(t, &testCase{
Name: "Source file",

FilePath: filepath.Join("testdata", "ruby", "plain", "lib", "plain.rb"),

ExpectedTestFilePath: filepath.Join("testdata", "ruby", "plain", "test", "plain_test.rb"),
})
}

func TestLanguageImportPath(t *testing.T) {
type testCase struct {
Name string

ProjectRootPath string
FilePath string

ExpectedImportPath string
}

validate := func(t *testing.T, tc *testCase) {
t.Run(tc.Name, func(t *testing.T) {
ruby := Language{}
actualImportPath := ruby.ImportPath(tc.ProjectRootPath, tc.FilePath)

assert.Equal(t, tc.ExpectedImportPath, actualImportPath)
})
}

validate(t, &testCase{
Name: "Source file",

FilePath: filepath.Join("testdata", "ruby", "plain", "lib", "plain.rb"),

ExpectedImportPath: "../lib/plain",
})
}

0 comments on commit c7ae56a

Please sign in to comment.