summaryrefslogtreecommitdiffhomepage
path: root/mrbgems/mruby-sleep/test/sleep_test.rb
blob: e5ea5f69e393cc1b8b89a059bbd039f81dfe056a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
def run_with_catching_error &b
  e = nil
  begin
    b.call
  rescue => _e
    e = _e
  end

  return e
end

assert("sleep works") do
  e = run_with_catching_error { sleep 1 }

  assert_nil e
end

assert("sleep would not accept negative value") do
  e = run_with_catching_error { sleep -1 }

  assert_not_equal e, nil
  assert_equal e.class, ArgumentError
end

assert("usleep works") do
  e = run_with_catching_error { usleep 100 }

  assert_nil e
end

assert("usleep would not accept negative value") do
  e = run_with_catching_error { usleep -100 }

  assert_not_equal e, nil
  assert_equal e.class, ArgumentError
end