checkm 0.0.4 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,42 @@
1
+ # rcov generated
2
+ coverage
3
+
4
+ # rdoc generated
5
+ rdoc
6
+
7
+ # yard generated
8
+ doc
9
+ .yardoc
10
+
11
+ # bundler
12
+ .bundle
13
+
14
+ # jeweler generated
15
+ pkg
16
+
17
+ # Have editor/IDE/OS specific files you need to ignore? Consider using a global gitignore:
18
+ #
19
+ # * Create a file at ~/.gitignore
20
+ # * Include files you want ignored
21
+ # * Run: git config --global core.excludesfile ~/.gitignore
22
+ #
23
+ # After doing this, these files will be ignored in all your git projects,
24
+ # saving you from having to 'pollute' every project you touch with them
25
+ #
26
+ # Not sure what to needs to be ignored for particular editors/OSes? Here's some ideas to get you started. (Remember, remove the leading # of the line)
27
+ #
28
+ # For MacOS:
29
+ #
30
+ #.DS_Store
31
+ #
32
+ # For TextMate
33
+ #*.tmproj
34
+ #tmtags
35
+ #
36
+ # For emacs:
37
+ #*~
38
+ #\#*
39
+ #.\#*
40
+ #
41
+ # For vim:
42
+ #*.swp
data/Gemfile CHANGED
@@ -1,13 +1,3 @@
1
1
  source "http://rubygems.org"
2
- # Add dependencies required to use your gem here.
3
- # Example:
4
- # gem "activesupport", ">= 2.3.5"
2
+ gemspec
5
3
 
6
- # Add dependencies to develop your gem here.
7
- # Include everything needed to run rake, tests, features, etc.
8
- group :development do
9
- gem "shoulda", ">= 0"
10
- gem "bundler", "~> 1.0.0"
11
- gem "jeweler", "~> 1.5.1"
12
- gem "rcov", ">= 0"
13
- end
@@ -1,20 +1,13 @@
1
- Copyright (c) 2010 Chris Beer
1
+ Copyright (c) 2011 Chris Beer
2
2
 
3
- Permission is hereby granted, free of charge, to any person obtaining
4
- a copy of this software and associated documentation files (the
5
- "Software"), to deal in the Software without restriction, including
6
- without limitation the rights to use, copy, modify, merge, publish,
7
- distribute, sublicense, and/or sell copies of the Software, and to
8
- permit persons to whom the Software is furnished to do so, subject to
9
- the following conditions:
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
10
6
 
11
- The above copyright notice and this permission notice shall be
12
- included in all copies or substantial portions of the Software.
7
+ http://www.apache.org/licenses/LICENSE-2.0
13
8
 
14
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
File without changes
data/Rakefile CHANGED
@@ -1,5 +1,7 @@
1
+ require 'rake'
1
2
  require 'rubygems'
2
3
  require 'bundler'
4
+ require 'rspec/core/rake_task'
3
5
  begin
4
6
  Bundler.setup(:default, :development)
5
7
  rescue Bundler::BundlerError => e
@@ -7,46 +9,35 @@ rescue Bundler::BundlerError => e
7
9
  $stderr.puts "Run `bundle install` to install missing gems"
8
10
  exit e.status_code
9
11
  end
10
- require 'rake'
11
-
12
- require 'jeweler'
13
- Jeweler::Tasks.new do |gem|
14
- # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
15
- gem.name = "checkm"
16
- gem.homepage = "http://github.com/cbeer/checkm"
17
- gem.license = "MIT"
18
- gem.summary = "Checkm is a general-purpose text-based file manifest format"
19
- gem.email = "chris@cbeer.info"
20
- gem.authors = ["Chris Beer"]
21
- # Include your dependencies below. Runtime dependencies are required when using your gem,
22
- # and development dependencies are only needed for development (ie running rake tasks, tests, etc)
23
- # gem.add_runtime_dependency 'jabber4r', '> 0.1'
24
- # gem.add_development_dependency 'rspec', '> 1.2.3'
25
- end
26
- Jeweler::RubygemsDotOrgTasks.new
27
12
 
28
- require 'rake/testtask'
29
- Rake::TestTask.new(:test) do |test|
30
- test.libs << 'lib' << 'test'
31
- test.pattern = 'test/**/test_*.rb'
32
- test.verbose = true
33
- end
34
-
35
- require 'rcov/rcovtask'
36
- Rcov::RcovTask.new do |test|
37
- test.libs << 'test'
38
- test.pattern = 'test/**/test_*.rb'
39
- test.verbose = true
40
- end
13
+ Bundler::GemHelper.install_tasks
41
14
 
42
- task :default => :test
15
+ namespace :namaste do
16
+ RSpec::Core::RakeTask.new(:rspec) do |t|
17
+ t.pattern = "./spec/**/*_spec.rb"
18
+ t.rcov = true
19
+ t.rcov_opts = ["--exclude", "gems\/,spec\/"]
20
+ end
43
21
 
44
- require 'rake/rdoctask'
45
- Rake::RDocTask.new do |rdoc|
46
- version = File.exist?('VERSION') ? File.read('VERSION') : ""
22
+ # Use yard to build docs
23
+ begin
24
+ require 'yard'
25
+ require 'yard/rake/yardoc_task'
26
+ project_root = File.expand_path("#{File.dirname(__FILE__)}")
27
+ doc_destination = File.join(project_root, 'doc')
47
28
 
48
- rdoc.rdoc_dir = 'rdoc'
49
- rdoc.title = "checkm #{version}"
50
- rdoc.rdoc_files.include('README*')
51
- rdoc.rdoc_files.include('lib/**/*.rb')
29
+ YARD::Rake::YardocTask.new(:doc) do |yt|
30
+ yt.files = Dir.glob(File.join(project_root, 'lib', '**', '*.rb')) +
31
+ [ File.join(project_root, 'README.textile') ]
32
+ yt.options = ['--output-dir', doc_destination, '--readme', 'README.textile']
33
+ end
34
+ rescue LoadError
35
+ desc "Generate YARD Documentation"
36
+ task :doc do
37
+ abort "Please install the YARD gem to generate rdoc."
38
+ end
39
+ end
52
40
  end
41
+
42
+ desc "Run the rspec tests, aggregate coverage data, and build the Yard docs"
43
+ task :hudson => ["namaste:rspec","namaste:doc"]
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.4
1
+ 0.0.6
@@ -1,64 +1,28 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
1
  # -*- encoding: utf-8 -*-
5
2
 
3
+ require File.join(File.dirname(__FILE__), "lib/checkm/version")
4
+
6
5
  Gem::Specification.new do |s|
7
6
  s.name = %q{checkm}
8
- s.version = "0.0.4"
7
+ s.version = Checkm::VERSION
8
+ s.summary = "Checkm is a general-purpose text-based file manifest format "
9
+ s.description = "Checkm is a general-purpose text-based file manifest format "
9
10
 
10
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
12
  s.authors = ["Chris Beer"]
12
- s.date = %q{2010-11-27}
13
+ s.date = %q{2011-06-09}
13
14
  s.email = %q{chris@cbeer.info}
14
- s.extra_rdoc_files = [
15
- "LICENSE.txt",
16
- "README.rdoc"
17
- ]
18
- s.files = [
19
- ".document",
20
- "Gemfile",
21
- "Gemfile.lock",
22
- "LICENSE.txt",
23
- "README.rdoc",
24
- "Rakefile",
25
- "VERSION",
26
- "checkm.gemspec",
27
- "lib/checkm.rb",
28
- "test/helper.rb",
29
- "test/test_1/1",
30
- "test/test_checkm.rb"
31
- ]
32
- s.homepage = %q{http://github.com/cbeer/checkm}
33
- s.licenses = ["MIT"]
34
- s.require_paths = ["lib"]
35
- s.rubygems_version = %q{1.3.7}
36
- s.summary = %q{Checkm is a general-purpose text-based file manifest format}
37
- s.test_files = [
38
- "test/helper.rb",
39
- "test/test_checkm.rb"
40
- ]
41
15
 
42
- if s.respond_to? :specification_version then
43
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
44
- s.specification_version = 3
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
45
20
 
46
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
47
- s.add_development_dependency(%q<shoulda>, [">= 0"])
48
- s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
49
- s.add_development_dependency(%q<jeweler>, ["~> 1.5.1"])
50
- s.add_development_dependency(%q<rcov>, [">= 0"])
51
- else
52
- s.add_dependency(%q<shoulda>, [">= 0"])
53
- s.add_dependency(%q<bundler>, ["~> 1.0.0"])
54
- s.add_dependency(%q<jeweler>, ["~> 1.5.1"])
55
- s.add_dependency(%q<rcov>, [">= 0"])
56
- end
57
- else
58
- s.add_dependency(%q<shoulda>, [">= 0"])
59
- s.add_dependency(%q<bundler>, ["~> 1.0.0"])
60
- s.add_dependency(%q<jeweler>, ["~> 1.5.1"])
61
- s.add_dependency(%q<rcov>, [">= 0"])
62
- end
21
+ # Bundler will install these gems too if you've checked this out from source from git and run 'bundle install'
22
+ s.add_development_dependency "rake"
23
+ s.add_development_dependency "bundler"
24
+ s.add_development_dependency "rspec"
25
+ s.add_development_dependency 'rcov'
26
+ s.add_development_dependency 'yard'
63
27
  end
64
28
 
@@ -1,15 +1,23 @@
1
- require 'time'
1
+ require 'checkm/manifest'
2
+ require 'checkm/entry'
2
3
 
3
4
  module Checkm
5
+ # Size (in bytes) to read (in chunks) to compute checksums
4
6
  CHUNK_SIZE = 8*1024*1024
7
+
8
+ # Compute the checksum 'alg' for a file
9
+ # @param [File] file
10
+ # @param [String] alg md5, sha1, sha256, dir
5
11
  def self.checksum file, alg
6
12
  digest_alg = case alg
7
13
  when nil
8
14
  return true
9
15
  when /md5/
10
- Digest::MD5.new if alg == 'md5'
16
+ Digest::MD5.new
11
17
  when /sha1/
18
+ Digest::SHA1.new
12
19
  when /sha256/
20
+ Digest::SHA2.new(256)
13
21
  when /dir/
14
22
  return File.directory? file
15
23
  else
@@ -21,163 +29,4 @@ module Checkm
21
29
  end
22
30
  digest_alg.hexdigest
23
31
  end
24
-
25
- class Manifest
26
- def self.parse str, args = {}
27
- Manifest.new str, args
28
- end
29
-
30
- attr_reader :version
31
- attr_reader :entries
32
- attr_reader :fields
33
- attr_reader :path
34
-
35
- def initialize checkm, args = {}
36
- @args = args
37
- @version = nil
38
- @checkm = checkm
39
- @lines = checkm.split "\n"
40
- @entries = []
41
- @eof = false
42
- @fields= nil
43
- @path = args[:path]
44
- @path ||= Dir.pwd
45
- parse_lines
46
- # xxx error on empty entries?
47
- @lines.unshift('#%checkm_0.7') and @version = '0.7' if @version.nil?
48
-
49
- end
50
-
51
- def valid?
52
- return true if @entries.empty?
53
- not @entries.map { |e| e.valid? }.any? { |b| b == false }
54
- end
55
-
56
- def add path, args = {}
57
- line = Checkm::Entry.create path, args
58
-
59
- Checkm::Manifest.new [@lines, line].flatten.join("\n"), @args
60
- end
61
-
62
- def remove path
63
- Checkm::Manifest.new @lines.reject { |x| x =~ /^@?#{path}/ }.join("\n"), @args
64
- end
65
-
66
- def to_s
67
- @lines.join("\n")
68
- end
69
-
70
- def to_hash
71
- Hash[*@entries.map { |x| [x.sourcefileorurl, x] }.flatten]
72
- end
73
-
74
- private
75
-
76
- def parse_lines
77
- @lines.each do |line|
78
- case line
79
- when /^#%/
80
- parse_header line
81
- when /^#/
82
- parse_comment line
83
- when /^$/
84
-
85
- when /^@/
86
- parse_line line
87
- else
88
- parse_line line
89
- end
90
- end
91
- end
92
-
93
- def parse_header line
94
- case line
95
- when /^#%checkm/
96
- match = /^#%checkm_(\d+)\.(\d+)/.match line
97
- @version = "#{match[1]}.#{match[2]}" if match
98
- when /^#%eof/
99
- @eof = true
100
- when /^#%fields/
101
- list = line.split('|')
102
- list.shift
103
- @fields = list.map { |v| v.strip.downcase }
104
- when /^#%prefix/
105
-
106
- when /^#%profile/
107
-
108
- end
109
- end
110
-
111
- def parse_comment line
112
-
113
- end
114
-
115
- def parse_line line
116
- @entries << Entry.new(line, self)
117
- end
118
-
119
- end
120
-
121
- class Entry
122
- BASE_FIELDS = ['sourcefileorurl', 'alg', 'digest', 'length', 'modtime', 'targetfileorurl']
123
- attr_reader :values
124
-
125
- def self.create path, args = {}
126
- base = args[:base] || Dir.pwd
127
- alg = args[:alg] || 'md5'
128
- file = File.new File.join(base, path)
129
-
130
- "%s | %s | %s | %s | %s | %s" % [path, alg, Checkm.checksum(file, alg), File.size(file.path), file.mtime.utc.xmlschema, nil]
131
- end
132
-
133
- def initialize line, manifest = nil
134
- @line = line.strip
135
- @include = false
136
- @fields = BASE_FIELDS
137
- @fields = manifest.fields if manifest and manifest.fields
138
- @values = line.split('|').map { |s| s.strip }
139
- @manifest = manifest
140
- end
141
-
142
- def method_missing(sym, *args, &block)
143
- @values[@fields.index(sym.to_s.downcase) || BASE_FIELDS.index(sym.to_s.downcase)] rescue nil
144
- end
145
-
146
-
147
- def valid?
148
- return source_exists? && valid_checksum? && valid_multilevel? # xxx && valid_length? && valid_modtime?
149
- end
150
-
151
- private
152
- def source
153
- file = sourcefileorurl
154
- file = file[1..-1] if file =~ /^@/
155
- File.join(@manifest.path, file)
156
- end
157
-
158
- def source_exists?
159
- return File.exists? source
160
- end
161
-
162
- def valid_checksum?
163
- file = File.new source
164
- checksum = Checkm.checksum(file, alg)
165
- checksum === true or checksum == digest
166
- end
167
-
168
-
169
- def valid_length?
170
- throw NotImplementedError
171
- end
172
-
173
- def valid_modtime?
174
- throw NotImplementedError
175
- end
176
-
177
- def valid_multilevel?
178
- return true unless sourcefileorurl =~ /^@/
179
-
180
- return Manifest.parse(open(source).read, File.dirname(source))
181
- end
182
- end
183
32
  end
@@ -0,0 +1,64 @@
1
+ require 'time'
2
+ module Checkm
3
+ class Entry
4
+ BASE_FIELDS = ['sourcefileorurl', 'alg', 'digest', 'length', 'modtime', 'targetfileorurl']
5
+ attr_reader :values
6
+
7
+ def self.create path, args = {}
8
+ base = args[:base] || Dir.pwd
9
+ alg = args[:alg] || 'md5'
10
+ file = File.new File.join(base, path)
11
+
12
+ "%s | %s | %s | %s | %s | %s" % [path, alg, Checkm.checksum(file, alg), File.size(file.path), file.mtime.utc.xmlschema, nil]
13
+ end
14
+
15
+ def initialize line, manifest = nil
16
+ @line = line.strip
17
+ @include = false
18
+ @fields = BASE_FIELDS
19
+ @fields = manifest.fields if manifest and manifest.fields
20
+ @values = line.split('|').map { |s| s.strip }
21
+ @manifest = manifest
22
+ end
23
+
24
+ def method_missing(sym, *args, &block)
25
+ @values[@fields.index(sym.to_s.downcase) || BASE_FIELDS.index(sym.to_s.downcase)] rescue nil
26
+ end
27
+
28
+
29
+ def valid?
30
+ return source_exists? && valid_checksum? && valid_multilevel? # xxx && valid_length? && valid_modtime?
31
+ end
32
+
33
+ private
34
+ def source
35
+ file = sourcefileorurl
36
+ file = file[1..-1] if file =~ /^@/
37
+ File.join(@manifest.path, file)
38
+ end
39
+
40
+ def source_exists?
41
+ return File.exists? source
42
+ end
43
+
44
+ def valid_checksum?
45
+ file = File.new source
46
+ checksum = Checkm.checksum(file, alg)
47
+ checksum === true or checksum == digest
48
+ end
49
+
50
+
51
+ def valid_length?
52
+ throw NotImplementedError
53
+ end
54
+
55
+ def valid_modtime?
56
+ throw NotImplementedError
57
+ end
58
+
59
+ def valid_multilevel?
60
+ return true unless sourcefileorurl =~ /^@/
61
+ return Manifest.parse(open(source).read, File.dirname(source))
62
+ end
63
+ end
64
+ end
File without changes
@@ -0,0 +1,96 @@
1
+ module Checkm
2
+ class Manifest
3
+ def self.parse str, args = {}
4
+ Manifest.new str, args
5
+ end
6
+
7
+ attr_reader :version
8
+ attr_reader :entries
9
+ attr_reader :fields
10
+ attr_reader :path
11
+
12
+ def initialize checkm, args = {}
13
+ @args = args
14
+ @version = nil
15
+ @checkm = checkm
16
+ @lines = checkm.split "\n"
17
+ @entries = []
18
+ @eof = false
19
+ @fields= nil
20
+ @path = args[:path]
21
+ @path ||= Dir.pwd
22
+
23
+ parse_lines
24
+ # xxx error on empty entries?
25
+ @lines.unshift('#%checkm_0.7') and @version = '0.7' if @version.nil?
26
+
27
+ end
28
+
29
+ def valid?
30
+ return true if @entries.empty?
31
+ not @entries.map { |e| e.valid? }.any? { |b| b == false }
32
+ end
33
+
34
+ def add path, args = {}
35
+ line = Checkm::Entry.create path, args
36
+
37
+ Checkm::Manifest.new [@lines, line].flatten.join("\n"), @args
38
+ end
39
+
40
+ def remove path
41
+ Checkm::Manifest.new @lines.reject { |x| x =~ /^@?#{path}/ }.join("\n"), @args
42
+ end
43
+
44
+ def to_s
45
+ @lines.join("\n")
46
+ end
47
+
48
+ def to_hash
49
+ Hash[*@entries.map { |x| [x.sourcefileorurl, x] }.flatten]
50
+ end
51
+
52
+ private
53
+ def parse_lines
54
+ @lines.each do |line|
55
+ case line
56
+ when /^#%/
57
+ parse_header line
58
+ when /^#/
59
+ parse_comment line
60
+ when /^$/
61
+
62
+ when /^@/
63
+ parse_line line
64
+ else
65
+ parse_line line
66
+ end
67
+ end
68
+ end
69
+
70
+ def parse_header line
71
+ case line
72
+ when /^#%checkm/
73
+ match = /^#%checkm_(\d+)\.(\d+)/.match line
74
+ @version = "#{match[1]}.#{match[2]}" if match
75
+ when /^#%eof/
76
+ @eof = true
77
+ when /^#%fields/
78
+ list = line.split('|')
79
+ list.shift
80
+ @fields = list.map { |v| v.strip.downcase }
81
+ when /^#%prefix/
82
+
83
+ when /^#%profile/
84
+
85
+ end
86
+ end
87
+
88
+ def parse_comment line
89
+
90
+ end
91
+
92
+ def parse_line line
93
+ @entries << Entry.new(line, self)
94
+ end
95
+ end
96
+ end
@@ -0,0 +1,10 @@
1
+ module Checkm
2
+ unless Checkm.const_defined? :VERSION
3
+ def self.version
4
+ @version ||= File.read(File.join(File.dirname(__FILE__), '..', '..', 'VERSION')).chomp
5
+ end
6
+
7
+ VERSION = self.version
8
+ end
9
+ end
10
+
@@ -0,0 +1,116 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "checkm" do
4
+ it "should be valid if empty" do
5
+ checkm = ''
6
+ res = Checkm::Manifest.parse(checkm)
7
+ res.entries.should be_empty
8
+ res.should be_valid
9
+ end
10
+
11
+ it "should ignore comments" do
12
+ checkm = '#'
13
+ res = Checkm::Manifest.parse(checkm)
14
+ res.entries.should be_empty
15
+ res.should be_valid
16
+ end
17
+
18
+ it "should parse the checkm version" do
19
+ checkm = '#%checkm_0.7'
20
+ res = Checkm::Manifest.parse(checkm)
21
+ res.entries.should be_empty
22
+ res.should be_valid
23
+ res.version.should == '0.7'
24
+ end
25
+
26
+ describe "simple checkm line" do
27
+ before(:each) do
28
+ @checkm = 'book/Chapter9.xml | md5 | 49afbd86a1ca9f34b677a3f09655eae9'
29
+ @result = Checkm::Manifest.parse(@checkm)
30
+ @line = @result.entries.first
31
+ end
32
+
33
+ it "should parse one entry" do
34
+ @result.should have(1).entries
35
+ end
36
+
37
+ it "should parse a checkm line" do
38
+ @line.values[0].should == 'book/Chapter9.xml'
39
+ @line.values[1].should == 'md5'
40
+ @line.values[2].should == '49afbd86a1ca9f34b677a3f09655eae9'
41
+ end
42
+
43
+ it "should allow name-based lookups" do
44
+ @line.sourcefileorurl.should == 'book/Chapter9.xml'
45
+ @line.alg.should == 'md5'
46
+ @line.digest.should == '49afbd86a1ca9f34b677a3f09655eae9'
47
+ end
48
+ end
49
+
50
+ it "should support custom field names" do
51
+ checkm= '#%fields | testa | test b' + "\n" +
52
+ 'book/Chapter9.xml | md5 | 49afbd86a1ca9f34b677a3f09655eae9'
53
+ res = Checkm::Manifest.parse(checkm)
54
+
55
+ line = res.entries.first
56
+
57
+ line.sourcefileorurl.should == 'book/Chapter9.xml'
58
+ line.testa.should == 'book/Chapter9.xml'
59
+ line.alg.should == 'md5'
60
+ line.send(:'test b').should == 'md5'
61
+ line.digest.should == '49afbd86a1ca9f34b677a3f09655eae9'
62
+ end
63
+
64
+ describe "validity check" do
65
+ it "should be valid if the file exists" do
66
+ checkm = '1 | md5 | b026324c6904b2a9cb4b88d6d61c81d1'
67
+ res = Checkm::Manifest.parse(checkm, :path => File.join(File.dirname(__FILE__), 'fixtures/test_1'))
68
+ res.should have(1).entries
69
+ res.should be_valid
70
+ end
71
+
72
+ it "should be valid if the directory exists" do
73
+ checkm = 'test_1 | dir'
74
+ res = Checkm::Manifest.parse(checkm, :path => File.join(File.dirname(__FILE__), 'fixtures'))
75
+ res.should have(1).entries
76
+ res.should be_valid
77
+ end
78
+
79
+ it "should be invalid if a file is missing" do
80
+ checkm = '2 | md5 | b026324c6904b2a9cb4b88d6d61c81d1'
81
+ res = Checkm::Manifest.parse(checkm, :path => File.join(File.dirname(__FILE__), 'fixtures/test_1'))
82
+ res.should have(1).entries
83
+ res.should_not be_valid
84
+ end
85
+
86
+ it "should be invalid if the checksum is different" do
87
+ checkm = '1 | md5 | zzz'
88
+ res = Checkm::Manifest.parse(checkm, :path => File.join(File.dirname(__FILE__), 'fixtures/test_1'))
89
+ res.should have(1).entries
90
+ res.should_not be_valid
91
+ end
92
+ end
93
+
94
+ describe "manipulate manifest" do
95
+ it "should support simple create" do
96
+ res = Checkm::Entry.create('LICENSE.txt')
97
+ res.should match( /LICENSE\.txt | md5 | 927368f89ca84dbec878a8d017f06443 | 1054 | \d{4}/)
98
+ end
99
+
100
+ it "should allow files to be added to an existing manifest" do
101
+ m = Checkm::Manifest.parse('')
102
+ res = m.add('LICENSE.txt')
103
+ res.should have(1).entries
104
+ res.should be_valid
105
+ end
106
+ end
107
+
108
+ it "should be serializable to a string" do
109
+ m = Checkm::Manifest.parse('')
110
+ n = m.add('LICENSE.txt')
111
+ lines = n.to_s.split "\n"
112
+ lines[0].should == '#%checkm_0.7'
113
+ lines[1].should match(/^LICENSE\.txt/)
114
+ end
115
+ end
116
+
File without changes
@@ -0,0 +1,2 @@
1
+ require "rspec"
2
+ require "checkm"
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: checkm
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
5
- prerelease: false
4
+ hash: 19
5
+ prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 4
10
- version: 0.0.4
9
+ - 6
10
+ version: 0.0.6
11
11
  platform: ruby
12
12
  authors:
13
13
  - Chris Beer
@@ -15,14 +15,13 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-11-27 00:00:00 -05:00
18
+ date: 2011-06-09 00:00:00 -05:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
- type: :development
22
+ name: rake
23
23
  prerelease: false
24
- name: shoulda
25
- version_requirements: &id001 !ruby/object:Gem::Requirement
24
+ requirement: &id001 !ruby/object:Gem::Requirement
26
25
  none: false
27
26
  requirements:
28
27
  - - ">="
@@ -31,44 +30,54 @@ dependencies:
31
30
  segments:
32
31
  - 0
33
32
  version: "0"
34
- requirement: *id001
35
- - !ruby/object:Gem::Dependency
36
33
  type: :development
37
- prerelease: false
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
38
36
  name: bundler
39
- version_requirements: &id002 !ruby/object:Gem::Requirement
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
40
39
  none: false
41
40
  requirements:
42
- - - ~>
41
+ - - ">="
43
42
  - !ruby/object:Gem::Version
44
- hash: 23
43
+ hash: 3
45
44
  segments:
46
- - 1
47
- - 0
48
45
  - 0
49
- version: 1.0.0
50
- requirement: *id002
51
- - !ruby/object:Gem::Dependency
46
+ version: "0"
52
47
  type: :development
48
+ version_requirements: *id002
49
+ - !ruby/object:Gem::Dependency
50
+ name: rspec
53
51
  prerelease: false
54
- name: jeweler
55
- version_requirements: &id003 !ruby/object:Gem::Requirement
52
+ requirement: &id003 !ruby/object:Gem::Requirement
56
53
  none: false
57
54
  requirements:
58
- - - ~>
55
+ - - ">="
59
56
  - !ruby/object:Gem::Version
60
- hash: 1
57
+ hash: 3
61
58
  segments:
62
- - 1
63
- - 5
64
- - 1
65
- version: 1.5.1
66
- requirement: *id003
59
+ - 0
60
+ version: "0"
61
+ type: :development
62
+ version_requirements: *id003
67
63
  - !ruby/object:Gem::Dependency
64
+ name: rcov
65
+ prerelease: false
66
+ requirement: &id004 !ruby/object:Gem::Requirement
67
+ none: false
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ hash: 3
72
+ segments:
73
+ - 0
74
+ version: "0"
68
75
  type: :development
76
+ version_requirements: *id004
77
+ - !ruby/object:Gem::Dependency
78
+ name: yard
69
79
  prerelease: false
70
- name: rcov
71
- version_requirements: &id004 !ruby/object:Gem::Requirement
80
+ requirement: &id005 !ruby/object:Gem::Requirement
72
81
  none: false
73
82
  requirements:
74
83
  - - ">="
@@ -77,33 +86,37 @@ dependencies:
77
86
  segments:
78
87
  - 0
79
88
  version: "0"
80
- requirement: *id004
81
- description:
89
+ type: :development
90
+ version_requirements: *id005
91
+ description: "Checkm is a general-purpose text-based file manifest format "
82
92
  email: chris@cbeer.info
83
93
  executables: []
84
94
 
85
95
  extensions: []
86
96
 
87
- extra_rdoc_files:
88
- - LICENSE.txt
89
- - README.rdoc
97
+ extra_rdoc_files: []
98
+
90
99
  files:
91
100
  - .document
101
+ - .gitignore
92
102
  - Gemfile
93
- - Gemfile.lock
94
103
  - LICENSE.txt
95
- - README.rdoc
104
+ - README.textile
96
105
  - Rakefile
97
106
  - VERSION
98
107
  - checkm.gemspec
99
108
  - lib/checkm.rb
100
- - test/helper.rb
101
- - test/test_1/1
102
- - test/test_checkm.rb
109
+ - lib/checkm/entry.rb
110
+ - lib/checkm/file.rb
111
+ - lib/checkm/manifest.rb
112
+ - lib/checkm/version.rb
113
+ - spec/checkm_spec.rb
114
+ - spec/fixtures/test_1/1
115
+ - spec/spec_helper.rb
103
116
  has_rdoc: true
104
- homepage: http://github.com/cbeer/checkm
105
- licenses:
106
- - MIT
117
+ homepage:
118
+ licenses: []
119
+
107
120
  post_install_message:
108
121
  rdoc_options: []
109
122
 
@@ -130,10 +143,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
130
143
  requirements: []
131
144
 
132
145
  rubyforge_project:
133
- rubygems_version: 1.3.7
146
+ rubygems_version: 1.5.3
134
147
  signing_key:
135
148
  specification_version: 3
136
149
  summary: Checkm is a general-purpose text-based file manifest format
137
150
  test_files:
138
- - test/helper.rb
139
- - test/test_checkm.rb
151
+ - spec/checkm_spec.rb
152
+ - spec/fixtures/test_1/1
153
+ - spec/spec_helper.rb
@@ -1,20 +0,0 @@
1
- GEM
2
- remote: http://rubygems.org/
3
- specs:
4
- git (1.2.5)
5
- jeweler (1.5.1)
6
- bundler (~> 1.0.0)
7
- git (>= 1.2.5)
8
- rake
9
- rake (0.8.7)
10
- rcov (0.9.9)
11
- shoulda (2.11.3)
12
-
13
- PLATFORMS
14
- ruby
15
-
16
- DEPENDENCIES
17
- bundler (~> 1.0.0)
18
- jeweler (~> 1.5.1)
19
- rcov
20
- shoulda
@@ -1,18 +0,0 @@
1
- require 'rubygems'
2
- require 'bundler'
3
- begin
4
- Bundler.setup(:default, :development)
5
- rescue Bundler::BundlerError => e
6
- $stderr.puts e.message
7
- $stderr.puts "Run `bundle install` to install missing gems"
8
- exit e.status_code
9
- end
10
- require 'test/unit'
11
- require 'shoulda'
12
-
13
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
14
- $LOAD_PATH.unshift(File.dirname(__FILE__))
15
- require 'checkm'
16
-
17
- class Test::Unit::TestCase
18
- end
@@ -1,111 +0,0 @@
1
- require 'helper'
2
-
3
- class TestCheckm < Test::Unit::TestCase
4
- def test_empty
5
- checkm = ''
6
- res = Checkm::Manifest.parse(checkm)
7
- assert_equal(res.entries.empty?, true)
8
- assert_equal(res.valid?, true)
9
- end
10
-
11
- def test_comment
12
- checkm = '#'
13
- res = Checkm::Manifest.parse(checkm)
14
- assert_equal(res.entries.empty?, true)
15
- end
16
-
17
- def test_version
18
- checkm = '#%checkm_0.7'
19
- res = Checkm::Manifest.parse(checkm)
20
- assert_equal(res.entries.empty?, true)
21
- assert_equal(res.version, '0.7')
22
- end
23
-
24
- def test_parse_simple
25
- checkm = 'book/Chapter9.xml | md5 | 49afbd86a1ca9f34b677a3f09655eae9'
26
- res = Checkm::Manifest.parse(checkm)
27
- assert_equal(res.entries.length, 1)
28
- assert_equal(res.entries.first.values[0], 'book/Chapter9.xml')
29
- assert_equal(res.entries.first.values[1], 'md5')
30
- assert_equal(res.entries.first.values[2], '49afbd86a1ca9f34b677a3f09655eae9')
31
- end
32
-
33
- def test_parse_named_fields
34
- checkm = 'book/Chapter9.xml | md5 | 49afbd86a1ca9f34b677a3f09655eae9'
35
- res = Checkm::Manifest.parse(checkm)
36
- assert_equal(res.entries.length, 1)
37
- assert_equal(res.entries.first.sourcefileorurl, 'book/Chapter9.xml')
38
- assert_equal(res.entries.first.alg, 'md5')
39
- assert_equal(res.entries.first.digest, '49afbd86a1ca9f34b677a3f09655eae9')
40
- end
41
-
42
- def test_parse_custom_fields
43
- checkm= '#%fields | testa | test b' + "\n" +
44
- 'book/Chapter9.xml | md5 | 49afbd86a1ca9f34b677a3f09655eae9'
45
-
46
-
47
- res = Checkm::Manifest.parse(checkm)
48
- assert_equal(res.entries.length, 1)
49
- assert_equal(res.entries.first.sourcefileorurl, 'book/Chapter9.xml')
50
- assert_equal(res.entries.first.testa, 'book/Chapter9.xml')
51
- assert_equal(res.entries.first.alg, 'md5')
52
- assert_equal(res.entries.first.send(:'test b'), 'md5')
53
- assert_equal(res.entries.first.digest, '49afbd86a1ca9f34b677a3f09655eae9')
54
- end
55
-
56
- def test_valid
57
- checkm = '1 | md5 | b026324c6904b2a9cb4b88d6d61c81d1'
58
- res = Checkm::Manifest.parse(checkm, :path => File.join(File.dirname(__FILE__), 'test_1'))
59
- assert_equal(res.entries.length, 1)
60
- assert_equal(res.entries.first.valid?, true)
61
- end
62
-
63
- def test_valid_dir
64
- checkm = 'test_1 | dir'
65
- res = Checkm::Manifest.parse(checkm, :path => File.join(File.dirname(__FILE__)))
66
-
67
- assert_equal(res.entries.length, 1)
68
- assert_equal(res.entries.first.valid?, true)
69
- end
70
-
71
- def test_invalid_missing_file
72
- checkm = '2 | md5 | b026324c6904b2a9cb4b88d6d61c81d1'
73
- res = Checkm::Manifest.parse(checkm, :path => File.join(File.dirname(__FILE__), 'test_1'))
74
- assert_equal(res.entries.length, 1)
75
- assert_equal(res.entries.first.valid?, false)
76
- end
77
-
78
- def test_invalid_bad_checksum
79
- checkm = '1 | md5 | zzz'
80
- res = Checkm::Manifest.parse(checkm, :path => File.join(File.dirname(__FILE__), 'test_1'))
81
- assert_equal(res.entries.length, 1)
82
- assert_equal(res.entries.first.valid?, false)
83
- end
84
-
85
- def test_create_entry
86
- res = Checkm::Entry.create('LICENSE.txt')
87
- assert_match( /LICENSE\.txt | md5 | 927368f89ca84dbec878a8d017f06443 | 1054 | \d{4}/, res)
88
- end
89
-
90
- def test_manifest_add
91
- m = Checkm::Manifest.parse('')
92
- n = m.add('LICENSE.txt')
93
- assert_equal(n.entries.length, 1)
94
- assert_equal(n.entries.first.valid?, true)
95
- end
96
-
97
- def test_manifest_add
98
- m = Checkm::Manifest.parse('')
99
- n = m.add('LICENSE.txt')
100
- assert_equal(n.entries.length, 1)
101
- assert_equal(n.entries.first.valid?, true)
102
- end
103
-
104
- def test_manifest_to_s
105
- m = Checkm::Manifest.parse('')
106
- n = m.add('LICENSE.txt')
107
- lines = n.to_s.split "\n"
108
- assert_equal(lines[0], '#%checkm_0.7')
109
- assert_match(/^LICENSE\.txt/, lines[1])
110
- end
111
- end