File: test_notimp.rb

package info (click to toggle)
ruby2.1 2.1.5-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie-kfreebsd
  • size: 59,972 kB
  • sloc: ruby: 625,579; ansic: 295,220; xml: 25,445; yacc: 9,155; lisp: 2,433; tcl: 949; makefile: 535; sh: 402; perl: 62; python: 47; awk: 36; asm: 35; sed: 31
file content (84 lines) | stat: -rw-r--r-- 1,924 bytes parent folder | download | duplicates (2)
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
require 'test/unit'
require 'timeout'
require 'tmpdir'

class TestNotImplement < Test::Unit::TestCase
  def test_respond_to_fork
    assert_include(Process.methods, :fork)
    if /linux/ =~ RUBY_PLATFORM
      assert_equal(true, Process.respond_to?(:fork))
    end
  end

  def test_respond_to_lchmod
    assert_include(File.methods, :lchmod)
    if /linux/ =~ RUBY_PLATFORM
      assert_equal(false, File.respond_to?(:lchmod))
    end
    if /freebsd/ =~ RUBY_PLATFORM
      assert_equal(true, File.respond_to?(:lchmod))
    end
  end

  def test_call_fork
    GC.start
    pid = nil
    ps =
      case RUBY_PLATFORM
      when /linux/ # assume Linux Distribution uses procps
        proc {`ps -eLf #{pid}`}
      when /freebsd/
        proc {`ps -lH #{pid}`}
      when /darwin/
        proc {`ps -lM #{pid}`}
      else
        proc {`ps -l #{pid}`}
      end
    assert_nothing_raised(Timeout::Error, ps) do
      Timeout.timeout(5) {
        pid = fork {}
        Process.wait pid
        pid = nil
      }
    end
  ensure
    if pid
      Process.kill(:KILL, pid)
      Process.wait pid
    end
  end if Process.respond_to?(:fork)

  def test_call_lchmod
    if File.respond_to?(:lchmod)
      Dir.mktmpdir {|d|
        f = "#{d}/f"
        g = "#{d}/g"
        File.open(f, "w") {}
        File.symlink f, g
        newmode = 0444
        File.lchmod newmode, "#{d}/g"
        snew = File.lstat(g)
        assert_equal(newmode, snew.mode & 0777)
      }
    end
  end

  def test_method_inspect_fork
    m = Process.method(:fork)
    if Process.respond_to?(:fork)
      assert_not_match(/not-implemented/, m.inspect)
    else
      assert_match(/not-implemented/, m.inspect)
    end
  end

  def test_method_inspect_lchmod
    m = File.method(:lchmod)
    if File.respond_to?(:lchmod)
      assert_not_match(/not-implemented/, m.inspect)
    else
      assert_match(/not-implemented/, m.inspect)
    end
  end

end