github.com/lmorg/murex@v0.0.0-20240217211045-e081c89cd4ef/builtins/core/time/time_test.go (about) 1 package time 2 3 import ( 4 "testing" 5 "time" 6 7 _ "github.com/lmorg/murex/builtins/core/expressions" 8 _ "github.com/lmorg/murex/builtins/optional/time" 9 "github.com/lmorg/murex/lang" 10 "github.com/lmorg/murex/lang/types" 11 "github.com/lmorg/murex/test" 12 ) 13 14 func TestTimeParams(t *testing.T) { 15 start := time.Now() 16 17 lang.ShellProcess = lang.NewTestProcess() 18 test.RunMethodRegexTest( 19 t, cmdTime, "time", // method 20 "", types.Null, // stdin 21 []string{"sleep", "3"}, // parameters 22 ``, // output 23 ) 24 25 switch { 26 case start.Add(2 * time.Second).After(time.Now()): 27 t.Error("Process didn't pause") 28 case start.Add(4 * time.Second).Before(time.Now()): 29 t.Error("Process paused for too long") 30 } 31 } 32 33 func TestTimeBlock(t *testing.T) { 34 start := time.Now() 35 36 lang.ShellProcess = lang.NewTestProcess() 37 test.RunMethodRegexTest( 38 t, cmdTime, "time", // method 39 "", types.Null, // stdin 40 []string{"{ sleep 3 }"}, // parameters 41 ``, // output 42 ) 43 44 switch { 45 case start.Add(2 * time.Second).After(time.Now()): 46 t.Error("Process didn't pause") 47 case start.Add(4 * time.Second).Before(time.Now()): 48 t.Error("Process paused for too long") 49 } 50 } 51 52 func TestTimeBlockBg(t *testing.T) { 53 start := time.Now() 54 55 lang.ShellProcess = lang.NewTestProcess() 56 test.RunMethodRegexTest( 57 t, cmdTime, "time", // method 58 "", types.Null, // stdin 59 []string{"{ bg { sleep 3 } }"}, // parameters 60 ``, // output 61 ) 62 63 switch { 64 case start.Add(1 * time.Second).Before(time.Now()): 65 t.Error("PRocess should not have paused") 66 } 67 }