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

     1  package lang_test
     2  
     3  import (
     4  	"testing"
     5  	"time"
     6  
     7  	"github.com/lmorg/murex/lang"
     8  	"github.com/lmorg/murex/test/count"
     9  )
    10  
    11  func TestProcessExecStruct(t *testing.T) {
    12  	count.Tests(t, 2)
    13  
    14  	lang.InitEnv()
    15  
    16  	fork := lang.ShellProcess.Fork(lang.F_NO_STDIN | lang.F_NO_STDOUT | lang.F_NO_STDERR)
    17  
    18  	go fork.Execute([]rune(`exec: sleep 3`))
    19  	time.Sleep(1 * time.Second)
    20  
    21  	p := lang.ForegroundProc.Get()
    22  	name := p.Name.String()
    23  	param, _ := p.Parameters.String(0)
    24  	if name != "exec" || param != "sleep" {
    25  		t.Error("Invalid foreground process!")
    26  		t.Logf("  Expected name:  exec")
    27  		t.Logf("  Actual name:    %s", name)
    28  		t.Logf("  Expected param: sleep")
    29  		t.Logf("  Actual param:   %s", param)
    30  		return
    31  	}
    32  
    33  	pid, cmd := lang.ForegroundProc.Get().Exec.Get()
    34  	if pid == 0 {
    35  		t.Errorf("Expecting a non-zero pid, instead found %d", pid)
    36  	}
    37  	if cmd == nil {
    38  		t.Errorf("Expecting a non-nil cmd, instead got %v", cmd)
    39  	}
    40  }