github.com/hirochachacha/plua@v0.0.0-20170217012138-c82f520cc725/plua_test.go (about)

     1  package plua_test
     2  
     3  import (
     4  	"os"
     5  	"testing"
     6  
     7  	"github.com/hirochachacha/plua/compiler"
     8  	"github.com/hirochachacha/plua/object"
     9  	"github.com/hirochachacha/plua/runtime"
    10  	"github.com/hirochachacha/plua/stdlib"
    11  )
    12  
    13  func TestLuaTest(t *testing.T) {
    14  	wd, err := os.Getwd()
    15  	if err != nil {
    16  		t.Fatal(err)
    17  	}
    18  
    19  	err = os.Chdir("testdata/lua-5.3.3-tests")
    20  	if err != nil {
    21  		t.Fatal(err)
    22  	}
    23  	defer func() {
    24  		err = os.Chdir(wd)
    25  		if err != nil {
    26  			t.Fatal(err)
    27  		}
    28  	}()
    29  
    30  	c := compiler.NewCompiler()
    31  
    32  	proto, err := c.CompileFile("all.lua", 0)
    33  	if err != nil {
    34  		t.Fatal(err)
    35  	}
    36  
    37  	p := runtime.NewProcess()
    38  
    39  	p.Require("", stdlib.Open)
    40  
    41  	p.Globals().Set(object.String("_U"), object.True) // set user test flag
    42  
    43  	_, err = p.Exec(proto)
    44  	if err != nil {
    45  		t.Fatal(err)
    46  	}
    47  }