From c90c67461be0379deee1bf550b1f31a43b7c3d17 Mon Sep 17 00:00:00 2001 From: "Nicholas E. Rabenau" Date: Fri, 29 Jun 2012 21:26:50 +0200 Subject: [PATCH] First cut of unit test --- .gitignore | 17 +++++++++++++++++ Gemfile | 4 ++++ LICENSE | 22 ++++++++++++++++++++++ README.md | 30 ++++++++++++++++++++++++++++++ Rakefile | 10 ++++++++++ bin/twdeps | 30 ++++++++++++++++++++++++++++++ lib/twdeps.rb | 9 +++++++++ lib/twdeps/version.rb | 5 +++++ test/fixtures/no_deps.json | 7 +++++++ test/fixtures/party.json | 7 +++++++ test/test_helper.rb | 21 +++++++++++++++++++++ test/unit/test_dependencies.rb | 8 ++++++++ twdeps.gemspec | 20 ++++++++++++++++++++ 13 files changed, 190 insertions(+) create mode 100644 .gitignore create mode 100644 Gemfile create mode 100644 LICENSE create mode 100644 README.md create mode 100644 Rakefile create mode 100755 bin/twdeps create mode 100644 lib/twdeps.rb create mode 100644 lib/twdeps/version.rb create mode 100644 test/fixtures/no_deps.json create mode 100644 test/fixtures/party.json create mode 100644 test/test_helper.rb create mode 100644 test/unit/test_dependencies.rb create mode 100644 twdeps.gemspec diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d87d4be --- /dev/null +++ b/.gitignore @@ -0,0 +1,17 @@ +*.gem +*.rbc +.bundle +.config +.yardoc +Gemfile.lock +InstalledFiles +_yardoc +coverage +doc/ +lib/bundler/man +pkg +rdoc +spec/reports +test/tmp +test/version_tmp +tmp diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..b0e54a9 --- /dev/null +++ b/Gemfile @@ -0,0 +1,4 @@ +source 'https://rubygems.org' + +# Specify your gem's dependencies in twdeps.gemspec +gemspec diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..54e1a5a --- /dev/null +++ b/LICENSE @@ -0,0 +1,22 @@ +Copyright (c) 2012 Nicholas E. Rabenau + +MIT License + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..77faf8f --- /dev/null +++ b/README.md @@ -0,0 +1,30 @@ +# TaskWarrior Dependency Visualization + +Visualizes dependencies between TaskWarrior tasks. + +## Installation + + $ gem install twdeps + +## Usage + + # Create a dependency graph as PNG and pipe it to a file + task export rc.json.array=on rc.verbose=nothing | twdeps > deps.png + + # Same but override format. Use the file option to specify the file name to write to + task export rc.json.array=on rc.verbose=nothing | twdeps --format svg --file deps.svg + + # Create a graph from a previously exported file + cat tasks.json | twdeps > deps.png + +## Limitations + +TaskWarrior 2.0 needs the command line options `rc.json.array=on` and `rc.verbose=nothing` due to [two](http://taskwarrior.org/issues/1017) [bugs](http://taskwarrior.org/issues/1013) in JSON export. + +## Contributing + +1. Fork it +2. Create your feature branch (`git checkout -b my-new-feature`) +3. Commit your changes (`git commit -am 'Added some feature'`) +4. Push to the branch (`git push origin my-new-feature`) +5. Create new Pull Request diff --git a/Rakefile b/Rakefile new file mode 100644 index 0000000..8739084 --- /dev/null +++ b/Rakefile @@ -0,0 +1,10 @@ +#!/usr/bin/env rake +require "bundler/gem_tasks" +require 'rake/testtask' + +Rake::TestTask.new(:test) do |test| + test.libs << 'lib' << 'test' << 'test/helpers' + test.test_files = FileList['test/**/test_*.rb'] +end + +task :default => :test diff --git a/bin/twdeps b/bin/twdeps new file mode 100755 index 0000000..b1d54aa --- /dev/null +++ b/bin/twdeps @@ -0,0 +1,30 @@ +#!/usr/bin/env ruby + +require 'bundler' +Bundler.require + +# require output file argument if $stdout.tty?, otherwise it's being piped +outfile = "#{ARGV.shift}.png" + +g = GraphViz::new("G") + +main = g.add_nodes("main") +parse = g.add_nodes("parse") +execute = g.add_nodes("execute") +init = g.add_nodes("init") +cleanup = g.add_nodes("cleanup") +make_string = g.add_nodes("make_string") +printf = g.add_nodes("printf") +compare = g.add_nodes("compare") + +g.add_edges( main, parse ) +g.add_edges( parse, execute ) +g.add_edges( main, init ) +g.add_edges( main, cleanup ) +g.add_edges( execute, make_string ) +g.add_edges( execute, printf ) +g.add_edges( init, make_string ) +g.add_edges( main, printf ) +g.add_edges( execute, compare ) + +g.output(:png => outfile) diff --git a/lib/twdeps.rb b/lib/twdeps.rb new file mode 100644 index 0000000..6da1728 --- /dev/null +++ b/lib/twdeps.rb @@ -0,0 +1,9 @@ +require "twdeps/version" + +require "graphviz" + +module TaskWarrior + module Dependencies + # Your code goes here... + end +end diff --git a/lib/twdeps/version.rb b/lib/twdeps/version.rb new file mode 100644 index 0000000..5c23383 --- /dev/null +++ b/lib/twdeps/version.rb @@ -0,0 +1,5 @@ +module TaskWarrior + module Dependencies + VERSION = "0.0.1" + end +end diff --git a/test/fixtures/no_deps.json b/test/fixtures/no_deps.json new file mode 100644 index 0000000..d944d90 --- /dev/null +++ b/test/fixtures/no_deps.json @@ -0,0 +1,7 @@ +[{"id":1,"description":"Select a free weekend in November","entry":"20120629T191421Z","priority":"H","project":"party","status":"pending","uuid":"6fd0ba4a-ab67-49cd-ac69-64aa999aff8a","annotations":[{"entry":"20120629T191534Z","description":"the 13th looks good"}]}, +{"id":2,"description":"Select and book a venue","entry":"20120629T191634Z","priority":"H","project":"party","status":"pending","uuid":"c992448a-f1ea-4982-8461-47f0705ff509"}, +{"id":3,"description":"Mail invitations","entry":"20120629T191919Z","project":"party","status":"pending","uuid":"3b53178e-d5a4-45e0-afc2-1292db58a59a"}, +{"id":4,"description":"Select a caterer","entry":"20120629T191919Z","project":"party","status":"pending","uuid":"c590941b-eb10-4569-bdc9-0e339f79305e"}, +{"id":5,"description":"Design invitations","entry":"20120629T191919Z","priority":"H","project":"party","status":"pending","tags":["mall"],"uuid":"e5a867b7-0116-457d-ba43-9ac2bee6ad2a"}, +{"id":6,"description":"Print invitations","entry":"20120629T191920Z","project":"party","status":"pending","tags":["mall"],"uuid":"9f6f3738-1c08-4f45-8eb4-1e90864c7588"} +] \ No newline at end of file diff --git a/test/fixtures/party.json b/test/fixtures/party.json new file mode 100644 index 0000000..6e730c1 --- /dev/null +++ b/test/fixtures/party.json @@ -0,0 +1,7 @@ +[{"id":1,"description":"Select a free weekend in November","entry":"20120629T191421Z","priority":"H","project":"party","status":"pending","uuid":"6fd0ba4a-ab67-49cd-ac69-64aa999aff8a","annotations":[{"entry":"20120629T191534Z","description":"the 13th looks good"}]}, +{"id":2,"depends":"6fd0ba4a-ab67-49cd-ac69-64aa999aff8a","description":"Select and book a venue","entry":"20120629T191634Z","priority":"H","project":"party","status":"pending","uuid":"c992448a-f1ea-4982-8461-47f0705ff509"}, +{"id":3,"depends":"9f6f3738-1c08-4f45-8eb4-1e90864c7588","description":"Mail invitations","entry":"20120629T191919Z","project":"party","status":"pending","uuid":"3b53178e-d5a4-45e0-afc2-1292db58a59a"}, +{"id":4,"depends":"6fd0ba4a-ab67-49cd-ac69-64aa999aff8a","description":"Select a caterer","entry":"20120629T191919Z","project":"party","status":"pending","uuid":"c590941b-eb10-4569-bdc9-0e339f79305e"}, +{"id":5,"depends":"c992448a-f1ea-4982-8461-47f0705ff509","description":"Design invitations","entry":"20120629T191919Z","priority":"H","project":"party","status":"pending","tags":["mall"],"uuid":"e5a867b7-0116-457d-ba43-9ac2bee6ad2a"}, +{"id":6,"depends":"e5a867b7-0116-457d-ba43-9ac2bee6ad2a","description":"Print invitations","entry":"20120629T191920Z","project":"party","status":"pending","tags":["mall"],"uuid":"9f6f3738-1c08-4f45-8eb4-1e90864c7588"} +] \ No newline at end of file diff --git a/test/test_helper.rb b/test/test_helper.rb new file mode 100644 index 0000000..a753167 --- /dev/null +++ b/test/test_helper.rb @@ -0,0 +1,21 @@ +# require 'bundler' +# Bundler.require + +require 'twtest' +require 'twdeps' + +module TaskWarrior + module Test + module Integration + class TestCase + def tasks + export_tasks + end + + def fixture(name) + File.join(File.dirname(__FILE__), 'fixtures', name) + end + end + end + end +end \ No newline at end of file diff --git a/test/unit/test_dependencies.rb b/test/unit/test_dependencies.rb new file mode 100644 index 0000000..ec708b2 --- /dev/null +++ b/test/unit/test_dependencies.rb @@ -0,0 +1,8 @@ +require 'test_helper' + +class DependencyBuilderTest < TaskWarrior::Test::Integration::TestCase + def test_no_dependencies + exec("import #{fixture('no_deps.json')}") + assert_equal(6, tasks.size) + end +end \ No newline at end of file diff --git a/twdeps.gemspec b/twdeps.gemspec new file mode 100644 index 0000000..475049d --- /dev/null +++ b/twdeps.gemspec @@ -0,0 +1,20 @@ +# -*- encoding: utf-8 -*- +require File.expand_path('../lib/twdeps/version', __FILE__) + +Gem::Specification.new do |gem| + gem.authors = ["Nicholas E. Rabenau"] + gem.email = ["nerab@gmx.net"] + gem.description = %q{TODO: Write a gem description} + gem.summary = %q{TODO: Write a gem summary} + gem.homepage = "" + + gem.files = `git ls-files`.split($\) + gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) } + gem.test_files = gem.files.grep(%r{^(test|spec|features)/}) + gem.name = "twdeps" + gem.require_paths = ["lib"] + gem.version = TaskWarrior::Dependencies::VERSION + + gem.add_dependency 'ruby-graphviz', '~> 1.0' + gem.add_development_dependency 'twtest' +end