MCPcopy Index your code
hub / github.com/Shopify/go-lua / TestUndump

Function TestUndump

undump_test.go:45–83  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

43}
44
45func TestUndump(t *testing.T) {
46 _, err := exec.LookPath("luac")
47 if err != nil {
48 t.Skipf("testing undump requires luac: %s", err)
49 }
50 source := filepath.Join("lua-tests", "checktable.lua")
51 binary := filepath.Join("lua-tests", "checktable.bin")
52 if err := exec.Command("luac", "-o", binary, source).Run(); err != nil {
53 t.Fatalf("luac failed to compile %s: %s", source, err)
54 }
55 file, err := os.Open(binary)
56 if err != nil {
57 t.Fatal("couldn't open checktable.bin")
58 }
59 l := NewState()
60 closure, err := l.undump(file, "test")
61 if err != nil {
62 offset, _ := file.Seek(0, 1)
63 t.Error("unexpected error", err, "at file offset", offset)
64 }
65 if closure == nil {
66 t.Error("closure was nil")
67 }
68 p := closure.prototype
69 if p == nil {
70 t.Fatal("prototype was nil")
71 }
72 validate("@lua-tests/checktable.lua", p.source, "as source file name", t)
73 validate(23, len(p.code), "instructions", t)
74 validate(8, len(p.constants), "constants", t)
75 validate(4, len(p.prototypes), "prototypes", t)
76 validate(1, len(p.upValues), "upvalues", t)
77 validate(0, len(p.localVariables), "local variables", t)
78 validate(0, p.parameterCount, "parameters", t)
79 validate(4, p.maxStackSize, "stack slots", t)
80 if !p.isVarArg {
81 t.Error("expected main function to be var arg, but wasn't")
82 }
83}
84
85func validate(expected, actual interface{}, description string, t *testing.T) {
86 if expected != actual {

Callers

nothing calls this directly

Calls 4

undumpMethod · 0.95
NewStateFunction · 0.85
validateFunction · 0.85
ErrorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…