|
| 1 | +require 'ant_test_helper' |
| 2 | +require 'tmpdir' |
| 3 | + |
| 4 | +class TestGraph < Minitest::Test |
| 5 | + include Ant::TestHelper |
| 6 | + include Rake::DSL |
| 7 | + |
| 8 | + BUILDFILE = File.expand_path('graph_example.xml', __dir__) |
| 9 | + |
| 10 | + def setup |
| 11 | + @app = Rake.application |
| 12 | + Rake.application = Rake::Application.new |
| 13 | + end |
| 14 | + |
| 15 | + def teardown |
| 16 | + Rake.application = @app |
| 17 | + end |
| 18 | + |
| 19 | + def test_dot_has_an_edge_from_each_dependency_to_its_target |
| 20 | + ant_import BUILDFILE |
| 21 | + dot = Rake::Ant.dot(ant.project) |
| 22 | + |
| 23 | + assert dot.start_with?("digraph ant {\n") |
| 24 | + assert dot.end_with?("}\n") |
| 25 | + edges = dot.lines[1..-2].map(&:chomp) |
| 26 | + assert_equal ["compile -> dist_jar", "compile -> test_unit", "init -> compile", "init -> dist_jar"], edges.sort |
| 27 | + end |
| 28 | + |
| 29 | + def test_ant_graph_task_defines_a_task |
| 30 | + ant_graph_task :graph, BUILDFILE, 'unused.png' |
| 31 | + refute_nil Rake::Task[:graph] |
| 32 | + end |
| 33 | + |
| 34 | + def test_ant_graph_task_writes_a_png |
| 35 | + skip 'Graphviz dot is not installed' unless system('dot', '-V', [:out, :err] => File::NULL) |
| 36 | + |
| 37 | + Dir.mktmpdir do |dir| |
| 38 | + output = File.join(dir, 'build_graph.png') |
| 39 | + ant_graph_task :graph, BUILDFILE, output |
| 40 | + Rake::Task[:graph].invoke |
| 41 | + |
| 42 | + assert_equal "\x89PNG".b, File.binread(output, 4) |
| 43 | + end |
| 44 | + end |
| 45 | +end |
0 commit comments