github.com/lmorg/murex@v0.0.0-20240217211045-e081c89cd4ef/defaults_test.go (about)

     1  package main
     2  
     3  import (
     4  	"testing"
     5  
     6  	_ "github.com/lmorg/murex/builtins"
     7  	"github.com/lmorg/murex/config"
     8  	"github.com/lmorg/murex/config/defaults"
     9  	"github.com/lmorg/murex/lang"
    10  	"github.com/lmorg/murex/test/count"
    11  )
    12  
    13  // TestDefaultConfigExists tests the Default() function populates *config.Config
    14  func TestDefaultConfigExists(t *testing.T) {
    15  	count.Tests(t, 1)
    16  
    17  	conf := config.InitConf.Copy()
    18  
    19  	defaults.Config(conf, false)
    20  
    21  	m := conf.DumpConfig()
    22  	if len(m) == 0 {
    23  		t.Error("Defaults() not populating *config.Config.")
    24  	}
    25  }
    26  
    27  // TestDefaultProfileCompiles test the builtin murex_profile compiles
    28  func TestDefaultProfileCompiles(t *testing.T) {
    29  	count.Tests(t, 1)
    30  
    31  	defaults.Config(config.InitConf, false)
    32  	lang.InitEnv()
    33  	lang.ShellProcess.Config = config.InitConf
    34  
    35  	var block string
    36  	for _, profile := range defaults.DefaultProfiles {
    37  		block += "\n\n" + string(profile.Block)
    38  	}
    39  
    40  	fork := lang.ShellProcess.Fork(lang.F_NO_STDIN | lang.F_NO_STDOUT | lang.F_CREATE_STDERR)
    41  	exitNum, err := fork.Execute([]rune(block))
    42  
    43  	if err != nil {
    44  		t.Error("Error compiling murex_profile:")
    45  		t.Log(err)
    46  	}
    47  
    48  	b, err := fork.Stderr.ReadAll()
    49  	if err != nil {
    50  		t.Error("Error reading from streams.Stdin (stderr):")
    51  		t.Log(err)
    52  	}
    53  
    54  	if len(b) > 0 {
    55  		t.Error("Uncaptured stderr content:")
    56  		t.Log(string(b))
    57  	}
    58  
    59  	if exitNum != 0 {
    60  		t.Error("Non-zero exit number:")
    61  		t.Log(exitNum)
    62  	}
    63  }