github.com/lmorg/murex@v0.0.0-20240217211045-e081c89cd4ef/builtins/core/processes/bgfg_test.go (about) 1 package processes_test 2 3 import ( 4 "testing" 5 6 _ "github.com/lmorg/murex/builtins" 7 "github.com/lmorg/murex/test" 8 ) 9 10 func TestBg(t *testing.T) { 11 tests := []test.MurexTest{ 12 { 13 Block: `bg { out "bg" }; sleep 3; out "fg"`, 14 Stdout: "bg\nfg\n", 15 }, 16 { 17 Block: `bg { sleep 3; out "bg" }; out "fg"; sleep 6`, 18 Stdout: "fg\nbg\n", 19 }, 20 } 21 22 test.RunMurexTests(tests, t) 23 } 24 25 /*func TestBgFg(t *testing.T) { 26 count.Tests(t, 2) 27 sleep := 10 28 block := fmt.Sprintf(`bg { sleep %d }`, sleep) 29 30 lang.InitEnv() 31 32 go func() { 33 fork := lang.ShellProcess.Fork(lang.F_NO_STDIN | lang.F_NO_STDOUT | lang.F_NO_STDERR) 34 i, err := fork.Execute([]rune(block)) 35 if i != 0 || err != nil { 36 t.Error("Error executing block:") 37 t.Logf(" Block: %s", block) 38 t.Logf(" Exit num: %d", i) 39 t.Logf(" Error: %v", err) 40 } 41 }() 42 43 time.Sleep(2 * time.Second) 44 45 var p *lang.Process 46 fids := lang.GlobalFIDs.ListAll() 47 48 for i := range fids { 49 50 if fids[i].Name.String() == "exec" { 51 name, err := fids[i].Parameters.String(0) 52 if err != nil && name != "sleep" { 53 continue 54 } 55 duration, err := fids[i].Parameters.Int(1) 56 if err != nil && duration != sleep { 57 continue 58 } 59 60 p = fids[i] 61 goto next 62 } 63 } 64 65 t.Fatalf("Cannot find FID attached to `sleep %d`\n", sleep) 66 67 next: 68 69 if !p.Background.Get() { 70 t.Fatalf("`sleep %d` isn't set to background: p.Background == %v", sleep, p.Background.Get()) 71 } 72 73 if runtime.GOOS == "windows" || runtime.GOOS == "plan9" || runtime.GOOS == "js" { 74 // skip `fg` tests on systems that don't support foregrounding 75 return 76 } 77 78 count.Tests(t, 2) 79 block = fmt.Sprintf(`fg %d`, p.Id) 80 81 fork := lang.ShellProcess.Fork(lang.F_NO_STDIN | lang.F_NO_STDOUT | lang.F_NO_STDERR) 82 i, err := fork.Execute([]rune(block)) 83 if i != 0 || err != nil { 84 t.Error("Error executing block:") 85 t.Logf(" Block: %s", block) 86 t.Logf(" Exit num: %d", i) 87 t.Logf(" Error: %v", err) 88 } 89 90 time.Sleep(4 * time.Second) 91 92 if p.Background.Get() { 93 t.Fatalf("`sleep %d` hasn't been set to foreground: p.Background == %v", sleep, p.Background.Get()) 94 } 95 }*/