github.com/xyproto/orbiton/v2@v2.65.12-0.20240516144430-e10a419274ec/build_test.go (about)

     1  package main
     2  
     3  import (
     4  	"fmt"
     5  	"os"
     6  	"testing"
     7  
     8  	"github.com/xyproto/files"
     9  	"github.com/xyproto/mode"
    10  )
    11  
    12  func ExampleEditor_BuildOrExport_goError() {
    13  	e := NewSimpleEditor(80)
    14  	e.mode = mode.Detect("err.go")
    15  
    16  	os.Chdir("test")
    17  	// The rename is so that "err.go" is not picked up by the CI tests
    18  	os.Rename("err_go", "err.go")
    19  	outputExecutable, err := e.BuildOrExport(nil, nil, nil, "err.go", false)
    20  	os.Rename("err.go", "err_go")
    21  	os.Chdir("..")
    22  	fmt.Printf("err.go [compilation error: %v] %s\n", err, outputExecutable)
    23  	// Output:
    24  	// err.go [compilation error:  undefined: asdfasdf]
    25  }
    26  
    27  func TestBuildOrExport(t *testing.T) {
    28  	e := NewSimpleEditor(80)
    29  	e.mode = mode.Detect("err.rs")
    30  
    31  	os.Chdir("test")
    32  	_, err := e.BuildOrExport(nil, nil, nil, "err.rs", false)
    33  
    34  	os.Chdir("..")
    35  
    36  	// fmt.Printf("err.rs [compilation error: %v] %s\n", err, outputExecutable)
    37  
    38  	if files.Which("rustc") != "" {
    39  		// fmt.Println(err)
    40  		if err == nil { // expected to fail, fail on success
    41  			t.Fail()
    42  		}
    43  	} else {
    44  		// fmt.Println(err)
    45  		if err == nil { // expected to fail, fail on success
    46  			t.Fail()
    47  		}
    48  	}
    49  }