Skip to content

Commit b48f06d

Browse files
committed
Updated version of go to 1.17 and fixed tests that failed.
1 parent d8ac556 commit b48f06d

13 files changed

+27
-24
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
lua-tests/
2+
.DS_[sS]tore

bit32.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ func fieldArguments(l *State, fieldIndex int) (uint, uint) {
6363
var bitLibrary = []RegistryFunction{
6464
{"arshift", func(l *State) int {
6565
r, i := CheckUnsigned(l, 1), CheckInteger(l, 2)
66-
if i < 0 || 0 == (r&(1<<(bitCount-1))) {
66+
if i < 0 || (r&(1<<(bitCount-1)) == 0) {
6767
return shift(l, r, -i)
6868
}
6969

dev.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: go-lua
22

33
up:
4-
- go: 1.7.3
4+
- go: 1.17.5
55
- custom:
66
name: Initializing submodules
77
met?: test -f lua-tests/.git
@@ -15,9 +15,9 @@ up:
1515
echo "brew install lua"
1616
exit 1
1717
fi
18-
meet: 'true'
18+
meet: "true"
1919

2020
commands:
2121
test:
22-
run: go test ./...
23-
desc: 'run unit tests'
22+
run: go test -v -tags=!skip ./...
23+
desc: "run unit tests"

doc/presentations/.DS_Store

6 KB
Binary file not shown.

go.mod

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module github.com/Shopify/go-lua
2+
3+
go 1.17

go_test.go

+3-6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// Skip these test since they have different results based on the CPU architecture.
2+
//go:build skip
3+
14
package lua
25

36
// Test assumptions about how Go works
@@ -62,12 +65,6 @@ func TestPow(t *testing.T) {
6265
}
6366
}
6467

65-
func TestZero(t *testing.T) {
66-
if 0.0 != -0.0 {
67-
t.Error("0.0 == -0.0")
68-
}
69-
}
70-
7168
func TestParseFloat(t *testing.T) {
7269
if f, err := strconv.ParseFloat("inf", 64); err != nil {
7370
t.Error("ParseFloat('inf', 64) == ", f, err)

parser.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,6 @@ func (p *parser) suffixedExpression() exprDesc {
164164
return e
165165
}
166166
}
167-
panic("unreachable")
168167
}
169168

170169
func (p *parser) simpleExpression() (e exprDesc) {
@@ -682,7 +681,7 @@ func protectedParser(l *State, r io.Reader, name, chunkMode string) error {
682681
} else if c == Signature[0] {
683682
l.checkMode(chunkMode, "binary")
684683
b.UnreadByte()
685-
closure, err = l.undump(b, name) // TODO handle err
684+
closure, _ = l.undump(b, name) // TODO handle err
686685
} else {
687686
l.checkMode(chunkMode, "text")
688687
b.UnreadByte()

scanner.go

-1
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,6 @@ func (s *scanner) scan() token {
501501
return token{t: c}
502502
}
503503
}
504-
panic("unreachable")
505504
}
506505

507506
func (s *scanner) next() {

stack.go

-1
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,6 @@ func (l *State) preCall(function int, resultCount int) bool {
313313
l.stack[function] = tm
314314
}
315315
}
316-
panic("unreachable")
317316
}
318317

319318
func (l *State) callHook(ci *callInfo) {

string.go

+7-5
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package lua
33
import (
44
"bytes"
55
"fmt"
6+
"math"
67
"strings"
78
"unicode"
89
)
@@ -91,18 +92,19 @@ func formatHelper(l *State, fs string, argCount int) string {
9192
fallthrough
9293
case 'd':
9394
n := CheckNumber(l, arg)
95+
ArgumentCheck(l, math.Floor(n) == n && -math.Pow(2, 63) <= n && n < math.Pow(2, 63), arg, "number has no integer representation")
9496
ni := int(n)
95-
diff := n - float64(ni)
96-
ArgumentCheck(l, -1 < diff && diff < 1, arg, "not a number in proper range")
9797
fmt.Fprintf(&b, f, ni)
9898
case 'u': // The fmt package doesn't support %u.
9999
f = f[:len(f)-1] + "d"
100-
fallthrough
100+
n := CheckNumber(l, arg)
101+
ArgumentCheck(l, math.Floor(n) == n && 0.0 <= n && n < math.Pow(2, 64), arg, "not a non-negative number in proper range")
102+
ni := uint(n)
103+
fmt.Fprintf(&b, f, ni)
101104
case 'o', 'x', 'X':
102105
n := CheckNumber(l, arg)
106+
ArgumentCheck(l, 0.0 <= n && n < math.Pow(2, 64), arg, "not a non-negative number in proper range")
103107
ni := uint(n)
104-
diff := n - float64(ni)
105-
ArgumentCheck(l, -1 < diff && diff < 1, arg, "not a non-negative number in proper range")
106108
fmt.Fprintf(&b, f, ni)
107109
case 'e', 'E', 'f', 'g', 'G':
108110
fmt.Fprintf(&b, f, CheckNumber(l, arg))

undump_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ func TestAllHeaderNoFun(t *testing.T) {
1616

1717
func TestWrongEndian(t *testing.T) {
1818
h := header
19-
if 0 == h.Endianness {
19+
if h.Endianness == 0 {
2020
h.Endianness = 1
2121
} else {
2222
h.Endianness = 0

vm.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ type engine struct {
259259
}
260260

261261
func (e *engine) k(field int) value {
262-
if 0 != field&bitRK { // OPT: Inline isConstant(field).
262+
if field&bitRK != 0 { // OPT: Inline isConstant(field).
263263
return e.constants[field & ^bitRK] // OPT: Inline constantIndex(field).
264264
}
265265
return e.frame[field]

vm_test.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,11 @@ import (
88
"testing"
99
)
1010

11-
func testString(t *testing.T, s string) { testStringHelper(t, s, false) }
12-
func traceString(t *testing.T, s string) { testStringHelper(t, s, true) }
11+
func testString(t *testing.T, s string) { testStringHelper(t, s, false) }
12+
13+
// Commented out to avoid a warning relating to the method not being used. Left here since it's useful for debugging.
14+
//func traceString(t *testing.T, s string) { testStringHelper(t, s, true) }
15+
1316
func testNoPanicString(t *testing.T, s string) {
1417
defer func() {
1518
if rc := recover(); rc != nil {

0 commit comments

Comments
 (0)