Skip to content

Commit be97e41

Browse files
Shreyas Balakrishnashreyasbharath
Shreyas Balakrishna
authored andcommitted
fixup! fixup! Blah
1 parent bcacd7e commit be97e41

File tree

5 files changed

+34
-26
lines changed

5 files changed

+34
-26
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
module DirectoryParser
22
def fetch_all_dirs(root_dir)
3-
Find.find(root_dir).select { |e| File.directory?(e) }
3+
Find.find(root_dir).select { |e| File.directory?(e) && e != root_dir }
44
end
55

66
def glob_files(path, extensions)
7-
path = File.join(path, File::SEPARATOR) + '*' + extensions
7+
path = File.join(path, File::SEPARATOR, '**', File::SEPARATOR, '*' + extensions)
88
Dir.glob(path).select { |entry| File.file?(entry) }.compact
99
end
1010
end

lib/cpp_dependency_graph/project.rb

+10-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ def source_component(name)
2424
source_components[name]
2525
end
2626

27+
def project_component
28+
@project_component ||= build_project_component
29+
end
30+
2731
def source_files
2832
@source_files ||= build_source_files
2933
end
@@ -41,12 +45,17 @@ def external_includes(component)
4145

4246
def build_source_files
4347
# TODO: Breaking Demeter's law here
44-
files = source_components.values.flat_map(&:source_files)
48+
files = project_component.values.flat_map(&:source_files)
4549
files.map do |file|
4650
[file.path, file]
4751
end.to_h
4852
end
4953

54+
def build_project_component
55+
c = SourceComponent.new(@path)
56+
{ c.name => c }
57+
end
58+
5059
def build_source_components
5160
# TODO: Dealing with source components with same dir name?
5261
dirs = fetch_all_dirs(@path)

spec/test/component_dependency_graph_spec.rb

+15-21
Original file line numberDiff line numberDiff line change
@@ -8,36 +8,30 @@
88
let(:dependency_graph) { ComponentDependencyGraph.new(project) }
99

1010
it 'returns all links for a project' do
11-
expected_links = {}
12-
expected_links['UI'] = [Link.new('UI', 'Framework', false),
13-
Link.new('UI', 'Engine', true)]
14-
expected_links['DataAccess'] = [Link.new('DataAccess', 'Framework', false)]
15-
expected_links['main'] = [Link.new('main', 'UI', false)]
16-
expected_links['Framework'] = []
17-
expected_links['System'] = []
18-
expected_links['Engine'] = [Link.new('Engine', 'Framework', false),
19-
Link.new('Engine', 'UI', true),
20-
Link.new('Engine', 'DataAccess', false)]
21-
expect(dependency_graph.all_links).to eq(expected_links)
11+
links = dependency_graph.all_links
12+
expect(links['UI']).to contain_exactly(Link.new('UI', 'Engine', true), Link.new('UI', 'Framework', false))
13+
expect(links['DataAccess']).to contain_exactly(Link.new('DataAccess', 'Framework', false))
14+
expect(links['main']).to contain_exactly(Link.new('main', 'UI', false))
15+
expect(links['Framework']).to be_empty
16+
expect(links['System']).to be_empty
17+
expect(links['Engine']).to contain_exactly(Link.new('Engine', 'DataAccess', false), Link.new('Engine', 'Framework', false),
18+
Link.new('Engine', 'UI', true))
2219
end
2320

2421
it 'returns empty links for an unknown component of a project' do
2522
expect(dependency_graph.links('Blah').empty?).to eq(true)
2623
end
2724

2825
it 'returns links for a specified component of a project' do
29-
expected_links = {}
30-
expected_links['UI'] = [Link.new('UI', 'Engine', true)]
31-
expected_links['Engine'] = [Link.new('Engine', 'Framework', false),
32-
Link.new('Engine', 'UI', true),
33-
Link.new('Engine', 'DataAccess', false)]
34-
expect(dependency_graph.links('Engine')).to eq(expected_links)
26+
links = dependency_graph.links('Engine')
27+
expect(links['Engine']).to contain_exactly(Link.new('Engine', 'DataAccess', false), Link.new('Engine', 'Framework', false),
28+
Link.new('Engine', 'UI', true))
29+
expect(links['UI']).to contain_exactly(Link.new('UI', 'Engine', true))
3530
end
3631

3732
it 'returns all cyclic links of a project' do
38-
expected_links = {}
39-
expected_links['Engine'] = [Link.new('Engine', 'UI', true)]
40-
expected_links['UI'] = [Link.new('UI', 'Engine', true)]
41-
expect(dependency_graph.all_cyclic_links).to eq(expected_links)
33+
links = dependency_graph.all_cyclic_links
34+
expect(links['Engine']).to contain_exactly(Link.new('Engine', 'UI', true))
35+
expect(links['UI']).to contain_exactly(Link.new('UI', 'Engine', true))
4236
end
4337
end

spec/test/project_spec.rb

+5
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
require 'cpp_dependency_graph/project'
44

55
RSpec.describe Project do
6+
it 'parses overall project component' do
7+
component_names = Project.new('spec/test/example_project').project_component.values.map(&:name).sort
8+
expect(component_names).to eq(%w[example_project])
9+
end
10+
611
it 'parses all source components' do
712
component_names = Project.new('spec/test/example_project').source_components.values.map(&:name).sort
813
expect(component_names).to eq(%w[DataAccess Engine Framework System UI main])

spec/test/source_component_spec.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
end
1515

1616
it 'parses all source files within it' do
17-
source_file_names = SourceComponent.new('spec/test/example_project/Engine').source_files.map(&:basename)
18-
expect(source_file_names).to eq(['Engine.h', 'OldEngine.h', 'Engine.cpp'])
17+
source_file_names = SourceComponent.new('spec/test/example_project/Engine').source_files.map(&:basename).sort
18+
expect(source_file_names).to eq(['Engine.cpp', 'Engine.h', 'OldEngine.h'])
1919
end
2020

2121
it 'has an includes attribute' do

0 commit comments

Comments
 (0)