sh_unix_test.odin (1380B)
1 #+build !windows 2 package sh 3 4 import "core:testing" 5 import "core:time" 6 7 @(test) 8 quote_posix :: proc(t: ^testing.T) { 9 testing.expect_value(t, quote("plain", context.temp_allocator), "plain") 10 testing.expect_value(t, quote("has space", context.temp_allocator), "'has space'") 11 testing.expect_value(t, quote("it's", context.temp_allocator), `'it'\''s'`) 12 testing.expect_value(t, quote("", context.temp_allocator), "''") 13 } 14 15 @(test) 16 stdin_reaches_child :: proc(t: ^testing.T) { 17 s, ok := out("cat", {stdin = "from stdin"}, context.temp_allocator) 18 testing.expect(t, ok) 19 testing.expect_value(t, s, "from stdin") 20 } 21 22 @(test) 23 dir_and_env :: proc(t: ^testing.T) { 24 s, ok := out("pwd", {dir = "/"}, context.temp_allocator) 25 testing.expect(t, ok) 26 testing.expect_value(t, s, "/") 27 s, ok = out( 28 "echo $JM_TEST", 29 {env = {"JM_TEST=set", "PATH=/usr/bin:/bin"}}, 30 context.temp_allocator, 31 ) 32 testing.expect(t, ok) 33 testing.expect_value(t, s, "set") 34 } 35 36 @(test) 37 timeout_kills_a_slow_child :: proc(t: ^testing.T) { 38 r := exec({"sleep", "5"}, {timeout = 200 * time.Millisecond}, context.temp_allocator) 39 testing.expect(t, r.timed_out, "the child was not timed out") 40 testing.expect(t, !r.ok) 41 quick := exec({"echo", "fast"}, {timeout = 5 * time.Second}, context.temp_allocator) 42 testing.expect(t, quick.ok) 43 testing.expect(t, !quick.timed_out) 44 testing.expect_value(t, quick.stdout, "fast\n") 45 }