Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test fails to compile on 32-bit architectures #971

Open
siretart opened this issue Jun 27, 2024 · 1 comment
Open

Test fails to compile on 32-bit architectures #971

siretart opened this issue Jun 27, 2024 · 1 comment

Comments

@siretart
Copy link

Hi, I'm packaging this library for use of other packages in Debian.

I noticed that in Debian, the tests fails to build on 32bit architectures, e.g.:

In all cases, the relevant part of the build log looks like this:

132s # github.com/google/cel-go/common/types [github.com/google/cel-go/common/types.test]
132s src/github.com/google/cel-go/common/types/int_test.go:41:17: cannot use math.MaxInt64 (untyped int constant 9223372036854775807) as int value in assignment (overflows)
132s src/github.com/google/cel-go/common/types/int_test.go:44:17: cannot use math.MinInt64 (untyped int constant -9223372036854775808) as int value in assignment (overflows)
132s src/github.com/google/cel-go/common/types/int_test.go:47:17: cannot use math.MaxInt64 - 1 (untyped int constant 9223372036854775806) as int value in assignment (overflows)
132s src/github.com/google/cel-go/common/types/int_test.go:48:63: cannot use math.MaxInt64 (untyped int constant 9223372036854775807) as int value in argument to t.Errorf (overflows)
132s src/github.com/google/cel-go/common/types/int_test.go:50:17: cannot use math.MinInt64 + 1 (untyped int constant -9223372036854775807) as int value in assignment (overflows)
132s src/github.com/google/cel-go/common/types/int_test.go:51:63: cannot use math.MaxInt64 (untyped int constant 9223372036854775807) as int value in argument to t.Errorf (overflows)
132s src/github.com/google/cel-go/common/types/int_test.go:355:17: cannot use math.MinInt64 (untyped int constant -9223372036854775808) as int value in assignment (overflows)
132s src/github.com/google/cel-go/common/types/int_test.go:420:17: cannot use math.MinInt64 (untyped int constant -9223372036854775808) as int value in assignment (overflows)
132s src/github.com/google/cel-go/common/types/int_test.go:432:17: cannot use math.MaxInt64 / 2 (untyped int constant 4611686018427387903) as int value in assignment (overflows)
132s src/github.com/google/cel-go/common/types/int_test.go:435:17: cannot use math.MinInt64 / 2 (untyped int constant -4611686018427387904) as int value in assignment (overflows)
132s src/github.com/google/cel-go/common/types/int_test.go:435:17: too many errors

I suspect the issue is here:

func TestIntAdd(t *testing.T) {
if !Int(4).Add(Int(-3)).Equal(Int(1)).(Bool) {
t.Error("Adding two ints did not match expected value.")
}
if !IsError(Int(-1).Add(String("-1"))) {
t.Error("Adding non-int to int was not an error.")
}
if lhs, rhs := math.MaxInt64, 1; !IsError(Int(lhs).Add(Int(rhs))) {
t.Errorf("Expected adding %d and %d to result in overflow.", lhs, rhs)
}
if lhs, rhs := math.MinInt64, -1; !IsError(Int(lhs).Add(Int(rhs))) {
t.Errorf("Expected adding %d and %d to result in overflow.", lhs, rhs)
}
if lhs, rhs := math.MaxInt64-1, 1; !Int(lhs).Add(Int(rhs)).Equal(Int(math.MaxInt64)).(Bool) {
t.Errorf("Expected adding %d and %d to yield %d", lhs, rhs, math.MaxInt64)
}
if lhs, rhs := math.MinInt64+1, -1; !Int(lhs).Add(Int(rhs)).Equal(Int(math.MinInt64)).(Bool) {
t.Errorf("Expected adding %d and %d to yield %d", lhs, rhs, math.MaxInt64)
}
}

That test code seems to be written with the assumption to run on 64bit architectures only. I'm going to disable this test in Debian for now, but please let me know if you can think of a better way to address this issue.

@TristonianJones
Copy link
Collaborator

My apologies @siretart, I thought I had replied to this thread, but it's possible there are other issues in common/types/int.go and common/types/overflow.go. I'm happy to update reference to these constants where they occur. If I read this right it means type converting the constants, e.g. int64(math.MaxInt64), does that sound right to you?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants