github.com/kintar/etxt@v0.0.9/init_test.go (about)

     1  //go:build gtxt
     2  
     3  package etxt
     4  
     5  import "log"
     6  import "io/fs"
     7  import "errors"
     8  
     9  var testFont *Font
    10  var testFont2 *Font
    11  
    12  func init() {
    13  	var err error
    14  	var fontName1, fontName2 string
    15  	testFont, fontName1, err = ParseFontFrom("test_font.ttf")
    16  	if err != nil {
    17  		if !errors.Is(err, fs.ErrNotExist) {
    18  			log.Fatal(err)
    19  		}
    20  		log.Fatal("etxt requires a test_font.ttf file to run tests")
    21  	}
    22  	testFont2, fontName2, err = ParseFontFrom("test_font2.ttf")
    23  	if err != nil {
    24  		if !errors.Is(err, fs.ErrNotExist) {
    25  			log.Fatal(err)
    26  		}
    27  		log.Fatal("etxt requires a test_font2.ttf file to run tests")
    28  	}
    29  
    30  	if fontName1 == fontName2 {
    31  		log.Fatal("etxt requires a test_font.ttf and test_font2.ttf to be different fonts")
    32  	}
    33  }
    34  
    35  func doesNotPanic(function func()) (didNotPanic bool) {
    36  	didNotPanic = true
    37  	defer func() { didNotPanic = (recover() == nil) }()
    38  	function()
    39  	return
    40  }