DepGraph 0.8.0 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + "/spec_helper"
1
+ require File.dirname(__FILE__) + "/../spec_helper"
2
2
  require 'rubygems'
3
3
  gem 'filetesthelper'
4
4
  require 'filetesthelper'
@@ -7,7 +7,7 @@ include FileTestHelper
7
7
 
8
8
  default_graph_file = 'dependency_graph.png'
9
9
  tool_name = 'depgraph'
10
- tool_path = File.expand_path(File.join(File.dirname(__FILE__), '..', 'bin', tool_name))
10
+ tool_path = File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'bin', tool_name))
11
11
 
12
12
  describe "#{tool_name} (integration tests)" do
13
13
 
@@ -27,6 +27,7 @@ describe "#{tool_name} (integration tests)" do
27
27
  end
28
28
  end
29
29
 
30
+ three_files_with_chained_dependencies_from_file1_to_file2_to_file3 = {'file1.csproj' => '"file2.csproj"', 'file2.csproj' => '"file3.csproj"', 'file3.csproj' => ''}
30
31
  two_files_with_one_dependency_from_file1_to_file2 = {'file1.csproj' => '"file2.csproj"', 'file2.csproj' => ''}
31
32
  it 'should not create a file when the "-from" filter does not find matches' do
32
33
  with_files(two_files_with_one_dependency_from_file1_to_file2) do
@@ -59,6 +60,31 @@ describe "#{tool_name} (integration tests)" do
59
60
  File.exist?(default_graph_file).should be_true
60
61
  end
61
62
  end
63
+
64
+ it 'should exclude nodes when the "-exc" filter is used' do
65
+ with_files(three_files_with_chained_dependencies_from_file1_to_file2_to_file3) do
66
+ system "ruby #{tool_path} -type csproj -exc \"file2, ile3\""
67
+
68
+ File.exist?(default_graph_file).should be_false #because only file1 exists
69
+ end
70
+ end
71
+
72
+ it 'should be possible to load the test node finder found in the nodefinders directory' do
73
+ with_files() do
74
+ system "ruby #{tool_path} -type test"
75
+
76
+ File.exist?(default_graph_file).should be_true
77
+ end
78
+ end
79
+
80
+ it 'should be possible apply a transitive reduction to the output graph' do
81
+ with_files() do
82
+ system "ruby #{tool_path} -type test -trans"
83
+
84
+ File.exist?(default_graph_file).should be_true
85
+ File.exist?('temp.dot').should be_false
86
+ end
87
+ end
62
88
  end
63
89
 
64
90
 
@@ -0,0 +1,57 @@
1
+ require File.dirname(__FILE__) + "/../spec_helper"
2
+ require 'file_system_node_finder'
3
+ require 'rubygems'
4
+ gem 'filetesthelper'
5
+ require 'filetesthelper'
6
+ require 'spec'
7
+
8
+ include FileTestHelper
9
+ include DepGraph
10
+
11
+ describe FileSystemNodeFinder, '(integration tests)' do
12
+ it 'should remove extensions from node names' do
13
+ with_files('directory1/directory2/file.name.ext' => '') do
14
+ node_finder = FileSystemNodeFinder.new(non_existent_filter_type)
15
+ node_finder.file_name_pattern = '*ext'
16
+ nodes = node_finder.get_nodes
17
+ nodes.should == ['file.name']
18
+ end
19
+ end
20
+
21
+ it 'should search only in the specified directories' do
22
+ with_files('good1/file1' => '', 'good2/file2' => '', 'bad/file3' => '') do
23
+ node_finder = FileSystemNodeFinder.new(non_existent_filter_type)
24
+ node_finder.location = ['good1', 'good2']
25
+
26
+ nodes = node_finder.get_nodes
27
+ nodes.should == ['file1', 'file2']
28
+ end
29
+ end
30
+ end
31
+
32
+ #To setup the test files for each filter type, include three sample node files
33
+ #and make the first file, named 'a' depend on the next two, named 'b' and 'c'
34
+ test_set = {
35
+ :ruby_requires => {'a.rb' => 'require "b"\nrequire "c"', 'dir/b.rb' => '', 'dir/c.rb' => '', 'not_a_ruby_file' => ''},
36
+ :csproj => {'a.csproj' => '"b.csproj"\n"c.csproj"', 'dir/b.csproj' => '', 'dir/c.csproj' => '', 'not_a_csproj_file' => ''}
37
+ }
38
+
39
+ dependency_types.each do |filter_type|
40
+ test_files = test_set[filter_type]
41
+
42
+ describe FileSystemNodeFinder, "for #{filter_type.to_s} (integration tests)" do
43
+ it "should find the correct number of nodes" do
44
+ with_files(test_files) do
45
+ nodes = FileSystemNodeFinder.new(filter_type).get_nodes
46
+ nodes.should == ['a', 'b', 'c']
47
+ end
48
+ end
49
+ it "should correctly find the dependencies from each file" do
50
+ with_files(test_files) do
51
+ node = FileSystemNodeFinder.new(filter_type).get_nodes[0]
52
+ node.should_not be_nil
53
+ node.dependencies.should == ['b', 'c']
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,32 @@
1
+ require File.dirname(__FILE__) + "/../spec_helper"
2
+ require 'graph_creator'
3
+ require 'rubygems'
4
+ gem 'filetesthelper'
5
+ require 'spec'
6
+ require 'filetesthelper'
7
+ include DepGraph
8
+ include FileTestHelper
9
+
10
+ test_data = {
11
+ :csproj => {'file1.csproj'=>'"file2.csproj"', 'dir/file2.csproj'=>'"file1.csproj"' },
12
+ :ruby_requires => {'file1.rb'=>'require "file2"', 'dir/file2.rb'=>'require "file1"' }
13
+ }
14
+
15
+ describe GraphCreator, '(integration tests)' do
16
+ dependency_types.each do |filter_type|
17
+ it "should create a png image from the #{filter_type} dependencies found in the current directory tree" do
18
+ with_files(test_data[filter_type]) do
19
+ GraphCreator.new(filter_type).create_image('test.png')
20
+
21
+ non_empty_file_created('test.png').should be_true
22
+ end
23
+ end
24
+ end
25
+ end
26
+
27
+
28
+
29
+
30
+
31
+
32
+
@@ -0,0 +1,53 @@
1
+ require File.dirname(__FILE__) + "/../spec_helper"
2
+ require 'graph'
3
+ require 'rubygems'
4
+ gem 'filetesthelper'
5
+ require 'spec'
6
+ require 'filetesthelper'
7
+ include FileTestHelper
8
+ include DepGraph
9
+
10
+ describe GraphImageCreator, '(integration tests)' do
11
+ it "should create a file with the graph image" do
12
+ with_files do
13
+ graph = create_graph_with_2_nodes_and_1_edge
14
+ graph.create_image('graph.png')
15
+
16
+ non_empty_file_created('graph.png').should be_true
17
+ end
18
+ end
19
+
20
+ it "should not create an image file from an empty graph" do
21
+ with_files do
22
+ create_empty_graph.create_image('graph.png')
23
+ non_empty_file_created('graph.png').should be_false
24
+ end
25
+ end
26
+
27
+ it "should not create an image file from a graph with no edges" do
28
+ with_files do
29
+ create_graph_with_2_nodes_and_0_edges.create_image('graph.png')
30
+
31
+ non_empty_file_created('graph.png').should be_false
32
+ end
33
+ end
34
+
35
+ it 'can change output generation behaviour'do
36
+ graph = create_graph_with_2_nodes_and_1_edge
37
+ graph.output_generation = no_output_generation
38
+ with_files do
39
+ graph.create_image('test.png')
40
+ File.exist?('test.png').should be_false
41
+ end
42
+ end
43
+
44
+ it 'can generate dot script'do
45
+ graph = create_graph_with_2_nodes_and_1_edge
46
+ with_files do
47
+ graph.create_image('test.dot')
48
+ File.exist?('test.dot').should be_true
49
+ File.read('test.dot').match('digraph G').should_not be_nil
50
+ end
51
+ end
52
+ end
53
+
@@ -1,13 +1,13 @@
1
- require File.dirname(__FILE__) + "/spec_helper"
1
+ require File.dirname(__FILE__) + "/../spec_helper"
2
2
  require 'rubygems'
3
3
  require 'spec'
4
- require 'dependable_filter_manager'
4
+ require 'dependency_types_manager'
5
5
  include DepGraph
6
6
 
7
- describe DependableFilterManager do
7
+ describe DependencyTypesManager do
8
8
 
9
9
  it "should return the available filter types" do
10
- dependency_types_in_file = YAML.load_file(DependableFilterManager.dependency_types_file).map do |filter_type_in_file, _|
10
+ dependency_types_in_file = YAML.load_file(DependencyTypesManager.dependency_types_file).map do |filter_type_in_file, _|
11
11
  filter_type_in_file
12
12
  end
13
13
 
@@ -15,7 +15,7 @@ describe DependableFilterManager do
15
15
  end
16
16
 
17
17
  it "should use default values if the specified filter type is not found" do
18
- dependable_filter_manager = DependableFilterManager.new non_existent_filter_type
18
+ dependable_filter_manager = DependencyTypesManager.new non_existent_filter_type
19
19
 
20
20
  dependable_filter_manager.dependable_regexp.should == /.+/
21
21
  dependable_filter_manager.dependable_regexp_capture_group_index.should == 0
@@ -35,7 +35,7 @@ describe DependableFilterManager do
35
35
 
36
36
  dependency_types.each do |filter_type|
37
37
  it "should have a #{filter_type} filter type" do
38
- dependable_filter_manager = DependableFilterManager.new filter_type
38
+ dependable_filter_manager = DependencyTypesManager.new filter_type
39
39
 
40
40
  capture_index = dependable_filter_manager.dependable_regexp_capture_group_index
41
41
  sample_contents[filter_type][:content].each do |sample_dependency|
@@ -0,0 +1,64 @@
1
+ require File.dirname(__FILE__) + "/../spec_helper"
2
+ require 'file_system_node_finder'
3
+ require 'rubygems'
4
+ require 'spec'
5
+
6
+ include DepGraph
7
+
8
+ describe FileSystemNodeFinder do
9
+ it 'should be able to get the dependencies to csproj and dll files from a string' do
10
+ node_finder = FileSystemNodeFinder.new(:csproj)
11
+ node = Node.new('a')
12
+ dependencies_string = 'from this string the dependable to "\\a.dir\\node1.csproj", \n"\\tgg.hyhy\\node2.dll" and "node3.csproj" should be found'
13
+
14
+ node_finder.load_dependencies_from_string(node, dependencies_string)
15
+
16
+ node.dependencies.should == ["node1", "node2", "node3"]
17
+ end
18
+
19
+ it 'should be able to use a custom regexp filter to get the node dependencies from a string' do
20
+ node_finder = FileSystemNodeFinder.new(non_existent_filter_type)
21
+ dependencies_string = 'from this string the dependable to node.csproj \n and node1.dll should be found'
22
+ node_finder.dependable_filter = /\s([^\s]+)\.(csproj|dll)[^\w]/
23
+ node_finder.dependable_filter_capture_group_index = 0
24
+ node = Node.new('a')
25
+
26
+ node_finder.load_dependencies_from_string(node, dependencies_string)
27
+
28
+ node.dependencies.should == ["node", "node1"]
29
+ end
30
+
31
+ it 'should be able to use a capture group in the dependable regexp filter' do
32
+ node_finder = FileSystemNodeFinder.new(non_existent_filter_type)
33
+ dependencies_string = 'from this string the dependable to prefix.node.csproj \n and prefix.node1.dll should be found'
34
+ node_finder.dependable_filter = /\s(prefix\.)([^\s]+)\.(csproj|dll)[^\w]/
35
+ node_finder.dependable_filter_capture_group_index = 1
36
+ node = Node.new('a')
37
+
38
+ node_finder.load_dependencies_from_string(node, dependencies_string)
39
+
40
+ node.dependencies.should == ["node", "node1"]
41
+ end
42
+
43
+ it 'should ignore repeated dependencies in the string' do
44
+ node_finder = FileSystemNodeFinder.new(:csproj)
45
+ node = Node.new('a')
46
+ dependencies_string = 'this string has only one dependable that is repeated 3 times: "\\a.dir\\node.csproj", \n"\\tgg.hyhy\\node.dll" and "node.csproj"'
47
+
48
+ node_finder.load_dependencies_from_string(node, dependencies_string)
49
+
50
+ node.dependencies.should == ["node"]
51
+ end
52
+
53
+ it 'should ignore the capture group index if the dependable filter regexp has no capture groups' do
54
+ node_finder = FileSystemNodeFinder.new(non_existent_filter_type)
55
+ node_finder.dependable_filter = /dep[0-9]/
56
+ node_finder.dependable_filter_capture_group_index = 1
57
+ node = Node.new('a')
58
+
59
+ node_finder.load_dependencies_from_string(node, 'dep1 is in the first line \n in the second dep2')
60
+
61
+ node.dependencies.size.should == 2
62
+ end
63
+ end
64
+
@@ -0,0 +1,141 @@
1
+ require File.dirname(__FILE__) + "/../spec_helper"
2
+ require 'graph_creator'
3
+ require 'rubygems'
4
+ require 'spec'
5
+ include DepGraph
6
+
7
+ describe GraphCreator do
8
+ it 'should not create a file if the graph is empty' do
9
+ create_graph_creator_with_no_nodes.create_image.should be_false
10
+ end
11
+
12
+ it 'should return an empty graph if an empty set of nodes is specified' do
13
+ graph = create_graph_creator_with_two_nodes_and_no_dependencies.create_graph
14
+
15
+ graph.node_count.should == 0
16
+ graph.edge_count.should == 0
17
+
18
+ end
19
+
20
+ it 'should return an empty graph if only one node is specified' do
21
+ graph = create_graph_creator_with_two_nodes_and_no_dependencies.create_graph
22
+
23
+ graph.node_count.should == 0
24
+ graph.edge_count.should == 0
25
+
26
+ end
27
+
28
+ it 'should return an empty graph if all nodes specified are equal' do
29
+ graph = create_graph_creator_with_two_nodes_and_no_dependencies.create_graph
30
+
31
+ graph.node_count.should == 0
32
+ graph.edge_count.should == 0
33
+
34
+ end
35
+
36
+ it 'should ignore disconnected nodes' do
37
+ graph = create_2_connected_and_1_disconnected_node_with_an_orphan_dependency_graph_creator.create_graph
38
+
39
+ graph.node_count.should == 2
40
+ graph.edge_count.should == 1
41
+ end
42
+
43
+ it 'should ignore dependencies to non existent nodes' do
44
+ graph = create_2_node_graph_creator_with_1_normal_and_1_orphan_dependency.create_graph
45
+
46
+ graph.node_count.should == 2
47
+ graph.edge_count.should == 1
48
+ end
49
+
50
+ it 'should return a graph with one edge if two nodes with one dependable are specified' do
51
+ graph = create_graph_creator_with_two_nodes_and_one_dependency.create_graph
52
+
53
+ graph.node_count.should == 2
54
+ graph.edge_count.should == 1
55
+ end
56
+
57
+ it 'should be possible to filter dependent nodes with a regular expression' do
58
+ graph_creator = create_dependency_chain_graph_creator('node1', 'node2', 'node3', 'node4')
59
+ graph_creator.from = 'e2$'
60
+ graph = graph_creator.create_graph
61
+
62
+ graph.node_count.should == 2
63
+ graph.edge_count.should == 1
64
+ dependency_exists?(graph, 'node2', 'node3').should be_true
65
+ end
66
+
67
+ it 'should be possible to filter dependable nodes with a regular expression' do
68
+ graph_creator = create_dependency_chain_graph_creator('node1', 'node2', 'node3', 'node4')
69
+ graph_creator.to = 'e4$'
70
+ graph = graph_creator.create_graph
71
+
72
+ graph.node_count.should == 2
73
+ graph.edge_count.should == 1
74
+ dependency_exists?(graph, 'node3', 'node4').should be_true
75
+ end
76
+
77
+ it 'should exclude user selected nodes' do
78
+ graph_creator = create_dependency_chain_graph_creator('node1', 'node2', 'anode3', 'node4isthisone')
79
+ graph_creator.excluded_nodes = ['node3', 'node4', 'node6']
80
+ graph = graph_creator.create_graph
81
+
82
+ graph.node_count.should == 2
83
+ graph.edge_count.should == 1
84
+ dependency_exists?(graph, 'node1', 'node2').should be_true
85
+ end
86
+
87
+ it 'should not show disconnected nodes' do
88
+ graph = create_2_connected_plus_2_disconnected_nodes_graph_creator.create_graph
89
+ graph.node_count.should == 2
90
+ graph.edge_count.should == 1
91
+ end
92
+
93
+ it 'should not show nodes that are only connected to excluded nodes' do
94
+ graph_creator = create_dependency_chain_graph_creator('node1', 'node2', 'node3', 'node4')
95
+ graph_creator.excluded_nodes = ['node3']
96
+ graph = graph_creator.create_graph
97
+
98
+ graph.node_count.should == 2
99
+ graph.edge_count.should == 1
100
+ dependency_exists?(graph, 'node1', 'node2').should be_true
101
+ end
102
+
103
+ it 'should notify sucessful image creation' do
104
+ graph_creator = create_graph_creator_with_two_nodes_and_one_dependency
105
+ graph_creator.graph_image_creator_class = NoOutputGraph
106
+ graph_creator.create_image('graph.png').should be_true
107
+ end
108
+
109
+ it 'should notify failed image creation' do
110
+ graph_creator = create_graph_creator_with_no_nodes
111
+ graph_creator.graph_image_creator_class = NoOutputGraph
112
+ graph_creator.create_image('graph.png').should be_false
113
+ end
114
+
115
+ it 'should dynamically load node finders based on the dependency type' do
116
+ module DepGraph::NodeFinders
117
+ class FakeNodeFinder
118
+ def location=(d) end
119
+ def get_nodes
120
+ d1 = Node.new('node1')
121
+ d2 = Node.new('node2')
122
+ d1.depends_on(d2)
123
+ [d1, d2]
124
+ end
125
+ end
126
+ end
127
+
128
+ graph = GraphCreator.new(:fake).create_graph
129
+
130
+ graph.node_count.should == 2
131
+ graph.edge_count.should == 1
132
+ dependency_exists?(graph, 'node1', 'node2').should be_true
133
+ end
134
+
135
+ invalid_graph_creators.each do |invalid_graph_creator_description, invalid_graph_creator|
136
+ it "should return false when trying to create an image from a #{invalid_graph_creator_description}" do
137
+ invalid_graph_creator.graph_image_creator_class = NoOutputGraph
138
+ invalid_graph_creator.create_image('graph.png').should be_false
139
+ end
140
+ end
141
+ end
@@ -0,0 +1,58 @@
1
+ require File.dirname(__FILE__) + "/../spec_helper"
2
+ require 'graph_image_creator'
3
+ require 'rubygems'
4
+ require 'spec'
5
+ include DepGraph
6
+
7
+ describe GraphImageCreator do
8
+
9
+ it "should start with no nodes" do
10
+ create_empty_graph.node_count.should == 0
11
+ end
12
+
13
+ it "should be possible to add nodes" do
14
+ graph = create_graph_with_2_nodes_and_0_edges
15
+
16
+ graph.node_count.should == 2
17
+ graph.edge_count.should == 0
18
+ end
19
+
20
+ it "should not be allowed to add a node without a name" do
21
+ lambda {create_empty_graph.add_node('')}.should raise_error
22
+ end
23
+
24
+ it "should start with no edges" do
25
+ create_empty_graph.edge_count.should == 0
26
+ end
27
+
28
+ it "should be possible to add an edge" do
29
+ graph = create_graph_with_2_nodes_and_1_edge
30
+
31
+ graph.node_count.should == 2
32
+ graph.edge_count.should == 1
33
+ end
34
+
35
+ it "can be reset" do
36
+ graph = create_graph_with_2_nodes_and_1_edge
37
+
38
+ graph.reset
39
+ graph.node_count.should == 0
40
+ graph.edge_count.should == 0
41
+ end
42
+
43
+ it "should not be allowed to add edges between non existent nodes" do
44
+ lambda {create_empty_graph.add_edge('no node 1', 'no node 2')}.should raise_error
45
+ end
46
+
47
+ it "should return true when a new image file is created" do
48
+ graph = create_graph_with_2_nodes_and_1_edge
49
+ graph.output_generation = no_output_generation
50
+ graph.create_image('graph.png').should be_true
51
+ end
52
+
53
+ it "should return false when trying to create an empty graph" do
54
+ graph = create_empty_graph
55
+ graph.output_generation = no_output_generation
56
+ graph.create_image('graph.png').should be_false
57
+ end
58
+ end
@@ -0,0 +1,47 @@
1
+ require File.dirname(__FILE__) + "/../spec_helper"
2
+ require 'stringio'
3
+ require 'node'
4
+ require 'rubygems'
5
+ require 'spec'
6
+ include DepGraph
7
+
8
+ describe Node do
9
+ it 'should not accept empty uris in the constructor' do
10
+ lambda{Node.new('')}.should raise_error
11
+ end
12
+
13
+ it 'should have a non empty name' do
14
+ node = Node.new('a')
15
+ node.name.should_not be_empty
16
+ end
17
+
18
+ it 'should be equal to another node with the same name' do
19
+ node1 = Node.new('abc')
20
+ node2 = Node.new('abc')
21
+ node3 = Node.new('abd')
22
+
23
+ node1.should == node2
24
+ node1.should be_eql(node2)
25
+
26
+ node1.should_not == node3
27
+ node1.should_not be_eql(node3)
28
+
29
+ node2.should_not == node3
30
+ node2.should_not be_eql(node3)
31
+ end
32
+
33
+ it 'should allow setting node dependencies' do
34
+ node = Node.new('a')
35
+ node.depends_on('b')
36
+
37
+ node.dependencies.size.should == 1
38
+ end
39
+
40
+ it 'should allow querying for a node' do
41
+ node = Node.new('a')
42
+ node.depends_on('b')
43
+
44
+ node.depends_on?('b').should be_true
45
+ node.depends_on?('c').should be_false
46
+ end
47
+ end
@@ -0,0 +1,5 @@
1
+ --format
2
+ specdoc
3
+ --timeout
4
+ 20
5
+ --diff