Permalink
Browse files

Added DependencyGrapher.

  • Loading branch information...
1 parent 6d87ade commit affb3f0622ac3f2a70f7f0a1b20e67aa693a5d31 Brian Ford committed Oct 2, 2009

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -0,0 +1 @@
+// This file has no dependencies
@@ -0,0 +1 @@
+#include "b.hpp"
@@ -0,0 +1 @@
+#include "c.hpp"
@@ -0,0 +1 @@
+#include "d.hpp"
@@ -0,0 +1,2 @@
+#include "d.hpp"
+#include "e.hpp"
@@ -0,0 +1,3 @@
+#include "c.hpp"
+#include "e.hpp"
+#include "f.hpp"
@@ -0,0 +1,3 @@
+#ifdef F
+#include "f.hpp"
+#endif
@@ -0,0 +1,3 @@
+#ifndef E
+#include "g.hpp"
+#endif
@@ -0,0 +1,3 @@
+#if 1
+#include "h.hpp"
+#endif
@@ -0,0 +1,5 @@
+#if 0
+#include "h.hpp"
+#elif 1
+#include "i.hpp"
+#endif
@@ -0,0 +1,3 @@
+#if 0
+#include "j.hpp"
+#endif
@@ -0,0 +1,5 @@
+#if 0
+#include "j.hpp"
+#elif 0
+#include "k.hpp"
+#endif
@@ -0,0 +1,2 @@
+#include "c.hpp"
+#include "d.hpp"
@@ -0,0 +1 @@
+#include "m.hpp"
@@ -0,0 +1 @@
+#include "n.hpp"
@@ -0,0 +1 @@
+#include "p.hpp"
@@ -0,0 +1 @@
+#include "m.hpp"
@@ -0,0 +1 @@
+#include "q.hpp"
@@ -0,0 +1,31 @@
+require File.dirname(__FILE__) + '/../../spec_helper'
+require 'rakelib/dependency_grapher'
+
+describe "DependencyGrapher#print_dependencies" do
+ before :each do
+ @stdout, $stdout = $stdout, IOStub.new
+
+ @grapher = DependencyGrapher.new []
+ @grapher.should_receive(:get_system_defines)
+ end
+
+ it "prints the dependencies for all object files" do
+ @grapher.file_names = [fixture(__FILE__, "c.cpp"), fixture(__FILE__, "d.cpp")]
+ @grapher.directories = [fixture(__FILE__)]
+ @grapher.process
+
+ @grapher.print_dependencies $stdout
+
+ path = fixture(__FILE__)
+ $stdout.should == <<EOS
+#{path}/c.o: \\
+ #{path}/c.cpp \\
+ #{path}/c.hpp \\
+ #{path}/d.hpp
+#{path}/d.o: \\
+ #{path}/d.cpp \\
+ #{path}/d.hpp \\
+ #{path}/e.hpp
+EOS
+ end
+end
@@ -0,0 +1,186 @@
+require File.dirname(__FILE__) + '/../../spec_helper'
+require 'rakelib/dependency_grapher'
+
+describe "DependencyGrapher#process" do
+ before :each do
+ @grapher = DependencyGrapher.new []
+ @grapher.should_receive(:get_system_defines)
+ end
+
+ it "maps zero dependencies" do
+ @grapher.file_names = [fixture(__FILE__, "a.cpp")]
+ @grapher.process
+
+ dep = @grapher.sources.first
+ dep.dependencies.should == [fixture(__FILE__, "a.cpp")]
+ end
+
+ it "maps one dependency" do
+ @grapher.file_names = [fixture(__FILE__, "b.cpp")]
+ @grapher.directories = [fixture(__FILE__)]
+ @grapher.process
+
+ dep = @grapher.sources.first
+ dep.dependencies.should == [
+ fixture(__FILE__, "b.cpp"),
+ fixture(__FILE__, "b.hpp")
+ ]
+ end
+
+ it "maps one transitive dependency" do
+ @grapher.file_names = [fixture(__FILE__, "c.cpp")]
+ @grapher.directories = [fixture(__FILE__)]
+ @grapher.process
+
+ dep = @grapher.sources.first
+ dep.dependencies.should == [
+ fixture(__FILE__, "c.cpp"),
+ fixture(__FILE__, "c.hpp"),
+ fixture(__FILE__, "d.hpp")
+ ]
+ end
+
+ it "maps two direct dependencies" do
+ @grapher.file_names = [fixture(__FILE__, "d.cpp")]
+ @grapher.directories = [fixture(__FILE__)]
+ @grapher.process
+
+ dep = @grapher.sources.first
+ dep.dependencies.should == [
+ fixture(__FILE__, "d.cpp"),
+ fixture(__FILE__, "d.hpp"),
+ fixture(__FILE__, "e.hpp")
+ ]
+ end
+
+ it "maps direct and transitive dependencies" do
+ @grapher.file_names = [fixture(__FILE__, "e.cpp")]
+ @grapher.directories = [fixture(__FILE__)]
+ @grapher.process
+
+ dep = @grapher.sources.first
+ dep.dependencies.should == [
+ fixture(__FILE__, "c.hpp"),
+ fixture(__FILE__, "d.hpp"),
+ fixture(__FILE__, "e.cpp"),
+ fixture(__FILE__, "e.hpp"),
+ fixture(__FILE__, "f.hpp")
+ ]
+ end
+
+ it "includes a file in an \#ifdef that evaluates to true" do
+ @grapher.file_names = [fixture(__FILE__, "f.cpp")]
+ @grapher.directories = [fixture(__FILE__)]
+ @grapher.system_defines = { "F" => "1" }
+ @grapher.process
+
+ dep = @grapher.sources.first
+ dep.dependencies.should == [
+ fixture(__FILE__, "f.cpp"),
+ fixture(__FILE__, "f.hpp")
+ ]
+ end
+
+ it "includes a file in an \#ifndef that evaluates to true" do
+ @grapher.file_names = [fixture(__FILE__, "g.cpp")]
+ @grapher.directories = [fixture(__FILE__)]
+ @grapher.system_defines = { }
+ @grapher.process
+
+ dep = @grapher.sources.first
+ dep.dependencies.should == [
+ fixture(__FILE__, "g.cpp"),
+ fixture(__FILE__, "g.hpp")
+ ]
+ end
+
+ it "includes a file in an \#if that evaluates to true" do
+ @grapher.file_names = [fixture(__FILE__, "h.cpp")]
+ @grapher.directories = [fixture(__FILE__)]
+ @grapher.process
+
+ dep = @grapher.sources.first
+ dep.dependencies.should == [
+ fixture(__FILE__, "h.cpp"),
+ fixture(__FILE__, "h.hpp")
+ ]
+ end
+
+ it "includes a file in an \#elif that evaluates to true" do
+ @grapher.file_names = [fixture(__FILE__, "i.cpp")]
+ @grapher.directories = [fixture(__FILE__)]
+ @grapher.process
+
+ dep = @grapher.sources.first
+ dep.dependencies.should == [
+ fixture(__FILE__, "i.cpp"),
+ fixture(__FILE__, "i.hpp")
+ ]
+ end
+
+ it "does not include a file in an \#ifdef that evaluates to false" do
+ @grapher.file_names = [fixture(__FILE__, "f.cpp")]
+ @grapher.directories = [fixture(__FILE__)]
+ @grapher.system_defines = { }
+ @grapher.process
+
+ dep = @grapher.sources.first
+ dep.dependencies.should == [
+ fixture(__FILE__, "f.cpp")
+ ]
+ end
+
+ it "does not include a file in an \#ifndef that evaluates to false" do
+ @grapher.file_names = [fixture(__FILE__, "g.cpp")]
+ @grapher.directories = [fixture(__FILE__)]
+ @grapher.system_defines = { "E" => "1" }
+ @grapher.process
+
+ dep = @grapher.sources.first
+ dep.dependencies.should == [
+ fixture(__FILE__, "g.cpp")
+ ]
+ end
+
+ it "does not include a file in an \#if that evaluates to false" do
+ @grapher.file_names = [fixture(__FILE__, "j.cpp")]
+ @grapher.directories = [fixture(__FILE__)]
+ @grapher.process
+
+ dep = @grapher.sources.first
+ dep.dependencies.should == [
+ fixture(__FILE__, "j.cpp")
+ ]
+ end
+
+ it "does not include a file in an \#elif that evaluates to false" do
+ @grapher.file_names = [fixture(__FILE__, "k.cpp")]
+ @grapher.directories = [fixture(__FILE__)]
+ @grapher.process
+
+ dep = @grapher.sources.first
+ dep.dependencies.should == [
+ fixture(__FILE__, "k.cpp")
+ ]
+ end
+
+ it "only includes one entry for a file that occurs multiple times" do
+ @grapher.file_names = [fixture(__FILE__, "l.cpp")]
+ @grapher.directories = [fixture(__FILE__)]
+ @grapher.process
+
+ dep = @grapher.sources.first
+ dep.dependencies.should == [
+ fixture(__FILE__, "c.hpp"),
+ fixture(__FILE__, "d.hpp"),
+ fixture(__FILE__, "l.cpp")
+ ]
+ end
+
+ it "raises an Errno::ENOENT if an included file is not found" do
+ @grapher.file_names = [fixture(__FILE__, "q.cpp")]
+ @grapher.directories = [fixture(__FILE__)]
+
+ lambda { @grapher.process }.should raise_error(Errno::ENOENT)
+ end
+end

0 comments on commit affb3f0

Please sign in to comment.