ruby-graphviz 1.0.9 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,105 +0,0 @@
1
- require 'rubygems'
2
- require 'test/unit'
3
- begin
4
- require 'ruby-debug'
5
- rescue LoadError
6
- end
7
- require 'stringio'
8
-
9
- root = File.expand_path('../../lib',__FILE__)
10
- $:.unshift(root) unless $:.include?(root)
11
-
12
- require 'graphviz'
13
-
14
- # hack so that the example scripts don't unnecessarily unshift @todo
15
- class << $:
16
- def unshift path
17
- include?(path) ? self : super # super will return self, too
18
- end
19
- end
20
-
21
- module TestSupport
22
- extend self
23
-
24
- # @todo move to app?
25
- def windows?
26
- /mswin|mingw/ =~ RUBY_PLATFORM
27
- end
28
-
29
- def dev_null
30
- windows? ? 'NUL' : '/dev/null'
31
- end
32
- end
33
-
34
- module IoHack
35
-
36
- #
37
- # this is a ridiculous hack to capture what was written to $stdout/$stderr for testing
38
- # an alternative is to use Open3.popen3 on external calls which has overhead
39
- # and OS dependencies.
40
- #
41
- # This hack would apparently not be as bad on 1.9, which would allow you to simply
42
- # set $stdout and $stderr to instances of StringIO
43
- #
44
- # I don't know what is the 'right way' to test this kind of thing
45
- #
46
-
47
- class IoHackStream < File
48
- #
49
- # pre 1.9 you can't assign $stdout and $stderr to anything other than
50
- # an IO::File instance. what we *want* is to have them be StringIOs that
51
- # we can read from like strings for testing. So this is a crazy proxy
52
- # around StringIO. Note it makes *all* methods except a few protected,
53
- # which for me was failing silently when i forgot to make the appropriate
54
- # ones public. hack!
55
- #
56
-
57
- except = %w(inspect kind_of?)
58
- except += except.map{|x| x.to_sym } # for Ruby 1.9
59
- these = ancestors[0].instance_methods
60
- # these = [1,2,3].map{|x| ancestors[x].instance_methods(false)}.flatten
61
- eraseme = (these - except)
62
- eraseme.each{ |name| protected name }
63
- attr_reader :io
64
- def initialize()
65
- @io = StringIO.new
66
- super(TestSupport.dev_null, 'r+') # probably doesn't matter the mode
67
- end
68
- these = %w(write << puts)
69
- these.each do |name|
70
- define_method(name) do |*a|
71
- @io.send(name, *a)
72
- end
73
- end
74
- end
75
-
76
- def fake_popen2 path
77
- push_io
78
- require path # caller assumes responsibility for exceptions vis-a-vis stack
79
- pop_io
80
- end
81
-
82
- def io_stack
83
- @io_stack ||= []
84
- end
85
-
86
- def push_io
87
- io_stack.push [$stdout, $stderr]
88
- $stdout = IoHackStream.new
89
- $stderr = IoHackStream.new
90
- nil
91
- end
92
-
93
- def pop_io
94
- fail('stack empty') unless io_stack.any?
95
- result = [$stdout, $stderr]
96
- $stdout, $stderr = io_stack.pop
97
- result.each_with_index do |io,idx|
98
- if io.kind_of? IoHackStream
99
- io.io.seek(0)
100
- result[idx] = io.io.read
101
- end
102
- end
103
- result
104
- end
105
- end