Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions interpreter/ruby/ruby.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,9 @@ const (

var (
// regex to identify the Ruby interpreter executable
rubyRegex = regexp.MustCompile(`^(?:.*/)?libruby(?:-.*)?\.so\.(\d)\.(\d)\.(\d)$`)
rubyRegex = regexp.MustCompile(`^(?:.*/)?libruby(?:-.*)?\.so\.(\d+)\.(\d+)\.(\d+)$`)
// regex to extract a version from a string
rubyVersionRegex = regexp.MustCompile(`^(\d)\.(\d)\.(\d)$`)
rubyVersionRegex = regexp.MustCompile(`^(\d+)\.(\d+)\.(\d+)$`)

unknownCfunc = libpf.Intern("<unknown cfunc>")
cfuncDummyFile = libpf.Intern("<cfunc>")
Expand Down
113 changes: 113 additions & 0 deletions interpreter/ruby/ruby_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,119 @@ import (
"github.com/stretchr/testify/assert"
)

func TestRubyRegex(t *testing.T) {
tests := []struct {
name string
input string
match bool
major string
minor string
release string
}{
{
name: "single_digit_version",
input: "libruby.so.3.2.1",
match: true,
major: "3",
minor: "2",
release: "1",
},
{
// https://github.com/ruby/ruby/releases/tag/v3_3_10
name: "multi_digit_release",
input: "libruby.so.3.3.10",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

guessing this is how you discovered this was broken?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep, I was testing your JIT change on a rubi built from the latest 3.3 tag which happened to be 3.3.10

match: true,
major: "3",
minor: "3",
release: "10",
},
{
name: "with_path",
input: "/usr/lib/libruby.so.3.3.10",
match: true,
major: "3",
minor: "3",
release: "10",
},
{
name: "with_suffix",
input: "libruby-3.2.so.3.2.1",
match: true,
major: "3",
minor: "2",
release: "1",
},
{
name: "no_match",
input: "libpython.so.3.9",
match: false,
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
matches := rubyRegex.FindStringSubmatch(tt.input)
if !tt.match {
assert.Nil(t, matches)
return
}
if assert.NotNil(t, matches) {
assert.Equal(t, tt.major, matches[1])
assert.Equal(t, tt.minor, matches[2])
assert.Equal(t, tt.release, matches[3])
}
})
}
}

func TestRubyVersionRegex(t *testing.T) {
tests := []struct {
name string
input string
match bool
major string
minor string
release string
}{
{
name: "single_digit_version",
input: "3.2.1",
match: true,
major: "3",
minor: "2",
release: "1",
},
{
name: "multi_digit_release",
input: "3.3.10",
match: true,
major: "3",
minor: "3",
release: "10",
},
{
name: "no_match_partial",
input: "3.9",
match: false,
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
matches := rubyVersionRegex.FindStringSubmatch(tt.input)
if !tt.match {
assert.Nil(t, matches)
return
}
if assert.NotNil(t, matches) {
assert.Equal(t, tt.major, matches[1])
assert.Equal(t, tt.minor, matches[2])
assert.Equal(t, tt.release, matches[3])
}
})
}
}

func TestQualifiedMethodName(t *testing.T) {
tests := []struct {
name string
Expand Down