bc3 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +1,20 @@
1
+ #~ %{
2
+ #~ file
3
+ #~ folder/subfolder2/
4
+ #~ folder/file1
5
+ #~ folder/subfolder/subfile1
6
+ #~ }.each_line{|line|
7
+ #~ p line.strip
8
+ #~ x = line.strip.split(%r{(.+?[\\\/])})
9
+ #~ x.delete('')
10
+ #~ p x
11
+ #~ p '========'
12
+ #~ }
13
+
14
+ #~ __END__
15
+
16
+ $:.unshift('..') if $0 == __FILE__ #only for test
17
+
1
18
  require 'bc3/helper'
2
19
  module BC3
3
20
  =begin rdoc
@@ -14,6 +31,7 @@ Container for a snapshot.
14
31
 
15
32
  $log.debug("Create base folder for snapshot #{path}")
16
33
  @basefolder = Folder.new('SnapshotRoot', @timestamp)
34
+ @index = nil
17
35
  end
18
36
  =begin rdoc
19
37
  Create a snapshot from a hash.
@@ -23,7 +41,7 @@ A snapsot-hash must contain:
23
41
  * content - array of folders (see Folder.newh) and files (File.new)
24
42
  * timestamp (optional)
25
43
  =end
26
- def self.newh( data )
44
+ def self.new_hash( data )
27
45
  $log.info("Build Snapshot from hash")
28
46
  raise ArgumentError, "No hash given" unless data.is_a?(Hash)
29
47
  raise ArgumentError, "snapshot name missing" unless data.has_key?(:snapshot)
@@ -44,9 +62,8 @@ A snapsot-hash must contain:
44
62
  end #newh
45
63
  =begin rdoc
46
64
  Create a snapshot from a directory.
47
-
48
65
  =end
49
- def self.newd( dirname )
66
+ def self.new_filesystem( dirname )
50
67
  $log.info("Build Snapshot from directory #{dirname}")
51
68
 
52
69
  #~ raise ArgumentError, "No hash given" unless data.is_a?(Hash)
@@ -64,9 +81,49 @@ Create a snapshot from a directory.
64
81
  }
65
82
  snapshot
66
83
  end #newh
84
+ =begin rdoc
85
+ Simple interface to create a snapshot.
86
+
87
+ Snapshot structure is a list with a filename (including path) on a line.
88
+
89
+ Empty folders end with a slash.
90
+
91
+ file
92
+ folder/file1
93
+ folder/subfolder/subfile1
94
+ folder/subfolder2/
95
+
96
+ =end
97
+ def self.new_filelist( startpath, filelist )
98
+ snap = self.new( startpath )
99
+ filelist.strip.each_line{|line|
100
+ line.strip!
101
+ basename = ::File.basename(line)
102
+ #Decide, if we add a (empty) folder or a file.
103
+ entry = ( line[-1,1] == '/' ?
104
+ Folder.new(basename)
105
+ : File.new(filename: basename, filesize: 0)
106
+ )
107
+ path = ::File.dirname(line)
108
+ if path == '.'
109
+ snap << entry
110
+ else
111
+ snap.basefolder.add_with_path(path, entry)
112
+ end
113
+ }
114
+ snap
115
+ end #self.new_filelist
116
+
117
+ #Keep old definition
118
+ class << self
119
+ alias :newd :new_filesystem
120
+ alias :newh :new_hash
121
+ end
67
122
 
68
123
  #homepath of the snapshot
69
124
  attr_reader :path
125
+ #Content of the snapshot
126
+ attr_reader :basefolder
70
127
  #Time stamp from snapshot. Default 'now'
71
128
  attr_reader :timestamp
72
129
 
@@ -74,32 +131,127 @@ Create a snapshot from a directory.
74
131
  Add content (folders/files) to snapshot.
75
132
  =end
76
133
  def << (content)
134
+ reset_index
77
135
  @basefolder << content
78
136
  end
79
137
  =begin rdoc
138
+ Get content of the folder.
139
+
140
+ If you request a folder, the path must end with a '/'
141
+ =end
142
+ def [](path)
143
+ build_index() unless @index
144
+ @index[path]
145
+ end
146
+ =begin rdoc
80
147
  Loop on content of the folder.
81
148
 
82
- Options see BC3::Folder#each
149
+ Options:
150
+ * :files (default)
151
+ * :folders
152
+ * :rootonly - only root, no subdirectories
153
+ See also BC3::Folder#each (in combination with BC3::Snapshot#basefolder).
83
154
  =end
84
155
  def each(*options)
156
+ build_index() unless @index
157
+ options = [:files] if options.empty?
158
+ if options.include?(:flat)
159
+ $log.warn("each-option :flat should be rootonly")
160
+ options << :rootonly
161
+ end
162
+
163
+ result = {}
164
+ @index.each{|key,content|
165
+ next if options.include?(:rootonly) and key =~ %r{/.} #no subdirectory
166
+ case content
167
+ when File
168
+ result[key] = content if options.include?(:files)
169
+ when Folder
170
+ result[key] = content if options.include?(:folders)
171
+ else
172
+ raise "Internal error"
173
+ end
174
+ }
175
+
85
176
  if block_given?
86
- @basefolder.each(*options){|key, content| yield key, content }
177
+ result.each{|key, content| yield key, content }
87
178
  else
88
- @basefolder.each
179
+ result
89
180
  end
181
+ end #each
182
+ =begin rdoc
183
+ Reset the index.
184
+ The index will be regenerated when needed
185
+ (See BC3::Snapshot#build_index)
186
+
187
+ Called from folders of the snapshot, when they get new content.
188
+ =end
189
+ def reset_index(rebuild = false)
190
+ $log.debug("Delete index")
191
+ @index = nil
192
+ build_index() if rebuild
193
+ end
194
+ =begin rdoc
195
+ Build an index.
196
+
197
+ The index allows a faster process on each.
198
+
199
+ When the content changes (or content of one of the folders
200
+ in the snapshot) then the index is deleted.
201
+ See BC3::Snapshot#reset_index
202
+
203
+
204
+ =end
205
+ def build_index()
206
+ $log.debug("Build index")
207
+ @index = {}
208
+ @basefolder.each(:recursive,:folders, :files){|key, content|
209
+ @index[key] = content
210
+ content.snapshotpath[self] = key
211
+ }
212
+ @index
90
213
  end
91
214
 
92
215
  =begin rdoc
216
+ Save the snapshot.
217
+
218
+ Depending on extension you get different results:
219
+ * *.bcss Beyond compare snapshot format
220
+ * *.yaml Yaml file.
221
+
222
+ You may save the snapshot as a yaml file, modify the data and
223
+ create a new bcss-file.
224
+
225
+ bc3 = BC3::Snapshot.new()
226
+ ...
227
+ bc3.save('my_snapshot.yaml')
228
+
229
+ ... modify the yaml file
230
+
231
+ bc3 = BC3::Snapshot.new_hash(YAML.load(File.read('my_snapshot.yaml'))
232
+ bc3.save('my_snapshot.bcss')
233
+
93
234
  =end
94
235
  def save( filename, compressed = nil )
95
236
  $log.debug("Prepare snapshot for #{filename}")
96
- #Check if compressed or uncompressed output wanted
97
- compressed = ( filename =~ /\.bcssx/ ) if compressed.nil?
98
- #Must be binary, else a \n get's \r\n under windows.
99
- ::File.open(filename,'wb'){|f|
100
- f << bcss( compressed )
101
- }
102
- $log.info("Saved snapshot as #{filename}")
237
+
238
+ case filename
239
+ when /\.ya?ml/
240
+ ::File.open(filename,'w'){|f|
241
+ f << to_hash.to_yaml
242
+ }
243
+ $log.info("Saved snapshot as #{filename}")
244
+ when /\.bcss/
245
+ #Check if compressed or uncompressed output wanted
246
+ compressed = ( filename =~ /\.bcssx/ ) if compressed.nil?
247
+ #Must be binary, else a \n get's \r\n under windows.
248
+ ::File.open(filename,'wb'){|f|
249
+ f << bcss( compressed )
250
+ }
251
+ $log.info("Saved snapshot as #{filename}")
252
+ else
253
+ raise ArgumentError, "Undefined filetype #{::File.extname(filename)}"
254
+ end
103
255
  end
104
256
  =begin rdoc
105
257
  Collect the data in a hash.
@@ -260,5 +412,81 @@ This part may be packed.
260
412
  }
261
413
  data
262
414
  end
415
+ =begin rdoc
416
+ Create a little statistic.
417
+
418
+ * Count of files and folders
419
+ * Collection of duplicates, grouped by crc
420
+ =end
421
+ def statistic()
422
+ count = Hash.new(0)
423
+ crc = Hash.new()
424
+ #feature idea: duplicates_by_name . Better: duplicates_by_filename , duplicates_by_dirname ?
425
+
426
+
427
+ @basefolder.each(:recursive,:folders, :files){|key, element|
428
+ case element
429
+ when Folder
430
+ count['folders'] += 1
431
+ when File
432
+ count['files'] += 1
433
+ (crc[element.crc] ||= [] ) << key unless element.crc.nil?
434
+ else
435
+ raise "Internal error #{element}"
436
+ end
437
+ }
438
+
439
+ count['duplicates_by_crc'] = {}
440
+ crc.each{|key, values|
441
+ count['duplicates_by_crc'][key] = values if values.size > 1
442
+ }
443
+ count.delete('duplicates_by_crc') if count['duplicates_by_crc'].empty?
444
+ count
445
+ end
263
446
  end #Snapshot
264
447
  end #module BC3
448
+
449
+
450
+ #testcode for immediate test
451
+ if $0 == __FILE__
452
+ $:.unshift('..')
453
+ require 'bc3'
454
+ require 'yaml'
455
+ bc3 = BC3::Snapshot.new_filelist( 'dir', %{
456
+ file
457
+ folder/subfolder2/
458
+ folder/file1
459
+ folder/subfolder/subfile1
460
+ }
461
+ )
462
+ puts bc3.each(:files, :folders ).keys
463
+ exit
464
+ #~ bc3 = BC3::Snapshot.new_filesystem('.')
465
+ bc3 << folder = BC3::Folder.new('test')
466
+
467
+ bc3 = BC3::Snapshot.new_filelist( 'dir', %{
468
+ file
469
+ folder/file1
470
+ folder/subfolder/subfile1
471
+ folder/subfolder2/
472
+ } )
473
+ #extend object
474
+ class << bc3; attr_reader :index; end
475
+ bc3.build_index
476
+
477
+
478
+ puts "hash: #{bc3.index.inspect}"
479
+ #Check changes in root
480
+ folder = ( bc3 << BC3::Folder.new('folder') )
481
+ puts "nil: #{bc3.index.inspect}"
482
+ puts "fnil: #{folder.snapshotpath}"
483
+
484
+ bc3.build_index
485
+ puts "hash: #{bc3.index.inspect}"
486
+ puts "fhash: #{folder.snapshotpath}"
487
+
488
+ #check changes in subdirectories
489
+ folder << BC3::Folder.new('folder')
490
+ puts "nil: #{bc3.index.inspect}"
491
+
492
+ end
@@ -24,6 +24,12 @@ class Test_file < Test::Unit::TestCase
24
24
  assert_raise(ArgumentError){ BC3::File.new( 'f' )}
25
25
  assert_raise(ArgumentError){ BC3::File.new( 1 )}
26
26
  end
27
+ def test_basename()
28
+ file = BC3::File.new( filename: 'x', filesize: 5)
29
+ assert_equal('x', file.filename )
30
+ assert_equal('x', file.basename )
31
+ assert_equal(file.filename, file.basename )
32
+ end
27
33
  def test_hash()
28
34
  assert_equal( { filename: 'f', filesize: 5, timestamp: $timestamp, attributes: BC3::Attrib::Archive, crc: nil},
29
35
  BC3::File.new( filename: 'f', filesize: 5, timestamp: $timestamp ).to_hash
@@ -10,11 +10,19 @@ $log.level = Log4r::FATAL
10
10
  $timestamp= Time.local(2010,1,1)
11
11
 
12
12
  class Test_folder < Test::Unit::TestCase
13
+ def test_basename()
14
+ folder = BC3::Folder.new('x')
15
+ assert_equal('x', folder.dirname )
16
+ assert_equal('x', folder.basename )
17
+ assert_equal(folder.dirname, folder.basename )
18
+ end
13
19
  def test_add_content()
14
20
  folder = BC3::Folder.new('x')
15
21
  assert_nothing_raised{ folder << BC3::Folder.new('dir1')}
16
22
  assert_nothing_raised{ folder << BC3::File.new( filename: 'file1', filesize: 1) }
23
+
17
24
  assert_raise(ArgumentError){ folder << 1 }
25
+ assert_raise(ArgumentError){ folder << BC3::Snapshot.new('x')}
18
26
 
19
27
  assert_equal(2, folder.each.size)
20
28
  end
@@ -134,18 +142,18 @@ class Test_folder < Test::Unit::TestCase
134
142
  assert_equal(2, folder.each(:files).size)
135
143
  assert_equal(1, folder.each(:folders).size)
136
144
 
137
- assert_equal(%w{subdir file1 file2}, folder.each.keys)
145
+ assert_equal(%w{subdir/ file1 file2}, folder.each.keys)
138
146
  assert_equal(%w{file1 file2}, folder.each(:files).keys)
139
- assert_equal(%w{subdir}, folder.each(:folders).keys)
147
+ assert_equal(%w{subdir/}, folder.each(:folders).keys)
140
148
 
141
149
  assert_equal(1, folder.each(:folders, :recursive).size)
142
150
  assert_equal(3, folder.each(:files, :recursive).size)
143
151
  assert_equal(4, folder.each(:folders,:files, :recursive).size)
144
152
 
145
153
 
146
- assert_equal(%w{subdir}, folder.each(:folders, :recursive).keys)
154
+ assert_equal(%w{subdir/}, folder.each(:folders, :recursive).keys)
147
155
  assert_equal(%w{subdir/subfile file1 file2}, folder.each(:files, :recursive).keys)
148
- assert_equal(%w{subdir subdir/subfile file1 file2}, folder.each(:folders,:files, :recursive).keys)
156
+ assert_equal(%w{subdir/ subdir/subfile file1 file2}, folder.each(:folders,:files, :recursive).keys)
149
157
 
150
158
  end
151
159
 
@@ -170,10 +178,28 @@ class Test_folder < Test::Unit::TestCase
170
178
  assert_equal(3, folder.each(:files, :recursive).size)
171
179
  assert_equal(5, folder.each(:folders,:files, :recursive).size)
172
180
 
173
- assert_equal(%w{subdir subdir/subsubdir}, folder.each(:folders, :recursive).keys)
181
+ assert_equal(%w{subdir/ subdir/subsubdir/}, folder.each(:folders, :recursive).keys)
174
182
  assert_equal(%w{subdir/subsubdir/subsubfile subdir/subfile file}, folder.each(:files, :recursive).keys)
175
- assert_equal(%w{subdir subdir/subsubdir subdir/subsubdir/subsubfile subdir/subfile file}, folder.each(:folders,:files, :recursive).keys)
183
+ assert_equal(%w{subdir/ subdir/subsubdir/ subdir/subsubdir/subsubfile subdir/subfile file}, folder.each(:folders,:files, :recursive).keys)
184
+
185
+ end
186
+
187
+ def test_add_with_path()
188
+ folder = BC3::Folder.new('base')
189
+ assert_equal( %w{},folder.each(:recursive,:files).keys )
190
+
191
+ folder.add_with_path('dir2', BC3::File.new(filename: 'test.txt', filesize: 5 ))
192
+ assert_equal( %w{dir2/test.txt},folder.each(:recursive,:files).keys )
193
+
194
+ folder.add_with_path('dir2/subdir', BC3::File.new(filename: 'test.txt', filesize: 5 ))
195
+ assert_equal( %w{dir2/test.txt dir2/subdir/test.txt},folder.each(:recursive,:files).keys )
196
+
197
+ folder.add_with_path('dir4/subdir', BC3::File.new(filename: 'test.txt', filesize: 5 ))
198
+ assert_equal( %w{dir2/test.txt dir2/subdir/test.txt dir4/subdir/test.txt},folder.each(:recursive,:files).keys )
176
199
 
200
+ #Added at end - sorting not necessary.
201
+ folder.add_with_path('dir0', BC3::File.new(filename: 'test.txt', filesize: 5 ))
202
+ assert_equal( %w{dir2/test.txt dir2/subdir/test.txt dir4/subdir/test.txt dir0/test.txt},folder.each(:recursive,:files).keys )
177
203
  end
178
204
  end
179
205
 
@@ -46,13 +46,16 @@ class Test_merge < Test::Unit::TestCase
46
46
  }
47
47
  ],
48
48
  }
49
- TestFiles = %w{snap1.bcss snap2.bcss
49
+ TestFiles = %w{
50
+ snap1.bcss snap2.bcss
51
+ snap1.yaml
50
52
  merge_i.bcss merge_b_1.bcss merge_b_2.bcss merge_r.bcss
51
53
  }
52
54
 
53
55
  def self.startup
54
56
  TestFiles.each{|f| File.delete(f) if File.exist?(f)}
55
57
  BC3::Snapshot.newh(Snap1).save('snap1.bcss')
58
+ #~ BC3::Snapshot.newh(Snap1).save('snap1.yaml')
56
59
  BC3::Snapshot.newh(Snap2).save('snap2.bcss')
57
60
  end
58
61
 
@@ -0,0 +1,231 @@
1
+ gem 'test-unit'
2
+ require 'test/unit'
3
+
4
+ $:.unshift('../lib')
5
+ require 'bc3'
6
+ $log.level = Log4r::WARN
7
+
8
+ #Start with local sources
9
+ $call_bc3_search = 'ruby -I ../lib ../bin/bc3_search.rb'
10
+ class String
11
+ #clean String from time dependend output.
12
+ def clean
13
+ self.strip.gsub(/\d{4,4}-\d{2,2}-\d{2,2} \d{2,2}:\d{2,2}:\d{2,2}\.\d+ \+\d\d:\d\d/, '2011-01-01 00:00:00 +01:00')
14
+ #~ :timestamp: 2011-01-28 21:37:05.265625 +01:00
15
+ end
16
+ end
17
+ #~ puts ":timestamp: 2011-01-28 21:37:05.265625 +01:00".clean
18
+
19
+
20
+ class Test_search < Test::Unit::TestCase
21
+ Testdata = YAML.load(%{
22
+ :snapshot: c:/my_dir
23
+ :content:
24
+ - :dirname: dir
25
+ :timestamp: 2011-01-01 12:00:00 +01:00
26
+ :content:
27
+ - :filename: file_15.txt
28
+ :filesize: 1
29
+ :crc: 15
30
+ :timestamp: 2011-01-01 12:00:00 +01:00
31
+ - :filename: file_with_crc_16.txt
32
+ :filesize: 1
33
+ :crc: 16
34
+ :timestamp: 2011-01-01 12:00:00 +01:00
35
+ - :filename: file_with_crc_15.txt
36
+ :filesize: 1
37
+ :crc: 15
38
+ :timestamp: 2011-01-01 12:00:00 +01:00
39
+ })
40
+
41
+ TestFiles = %w{test_search.bcss test_search_2.bcss test_search_extract.bcss}
42
+
43
+ def self.startup
44
+ TestFiles.each{|f| File.delete(f) if File.exist?(f)}
45
+ Dir['*.bcss'].each{|bcssfile|
46
+ raise "Snapshot exists before test run"
47
+ }
48
+ BC3::Snapshot.new_hash(Testdata).save('test_search.bcss')
49
+ Testdata[:content].first[:content].pop #delete file_with_crc_16.txt
50
+ BC3::Snapshot.new_hash(Testdata).save('test_search_2.bcss')
51
+ end
52
+
53
+ def self.shutdown
54
+ TestFiles.each{|f| File.delete(f) if File.exist?(f)}
55
+ end
56
+
57
+ def test_search_no_bcss()
58
+ assert_equal(%{
59
+ Start bc3_search for pattern <aa>
60
+ No Snapshot found
61
+ }.strip, `#{$call_bc3_search} 'aa' `.strip)
62
+
63
+ assert_equal(%{
64
+ Start bc3_search for pattern <aa>
65
+ Snapshot x.bcss not found
66
+ }.strip, `#{$call_bc3_search} 'aa' x.bcss`.strip)
67
+
68
+ end
69
+ #
70
+ #Check pattern to regexp conversion
71
+ def test_pattern()
72
+ assert_equal(%{
73
+ Start bc3_search for pattern <xx.x\\.txt>
74
+ Analyse test_search.bcss (c:/my_dir)
75
+ }.strip, `#{$call_bc3_search} 'xx?x.txt' test_search.bcss`.strip)
76
+
77
+ assert_equal(%{
78
+ Start bc3_search for pattern <xx.*\\.txt>
79
+ Analyse test_search.bcss (c:/my_dir)
80
+ }.strip, `#{$call_bc3_search} 'xx*.txt' test_search.bcss`.strip)
81
+ end
82
+ #No regexp-conversion with parameter -r
83
+ def test_regexp()
84
+ assert_equal(%{
85
+ Start bc3_search for pattern <xx*.txt>
86
+ Analyse test_search.bcss (c:/my_dir)
87
+ }.strip, `#{$call_bc3_search} -r 'xx*.txt' test_search.bcss`.strip)
88
+
89
+ assert_equal(%{
90
+ Start bc3_search for pattern <crc_[1]\\d\\.txt>
91
+ Analyse test_search.bcss (c:/my_dir)
92
+ dir/file_with_crc_16.txt
93
+ file_with_crc_15.txt
94
+ Found 2 files in test_search.bcss
95
+
96
+ }.strip, `#{$call_bc3_search} -r 'crc_[1]\\d\\.txt' test_search.bcss`.strip)
97
+
98
+ end
99
+
100
+ def test_search_dir()
101
+ assert_equal(%{
102
+ Start bc3_search for pattern <dir>
103
+ Analyse test_search.bcss (c:/my_dir)
104
+ dir/
105
+ Found 1 folder in test_search.bcss
106
+ }.strip, `#{$call_bc3_search} 'dir' test_search.bcss`.strip)
107
+ end
108
+ def test_search_file()
109
+ assert_equal(%{
110
+ Start bc3_search for pattern <file_15>
111
+ Analyse test_search.bcss (c:/my_dir)
112
+ dir/file_15.txt
113
+ Found 1 file in test_search.bcss
114
+
115
+ }.strip, `#{$call_bc3_search} 'file_15' test_search.bcss`.strip)
116
+ assert_equal(%{
117
+ Start bc3_search for pattern <file.*15>
118
+ Analyse test_search.bcss (c:/my_dir)
119
+ dir/file_15.txt
120
+ file_with_crc_15.txt
121
+ Found 2 files in test_search.bcss
122
+
123
+ }.strip, `#{$call_bc3_search} 'file*15' test_search.bcss`.strip)
124
+ end
125
+ def test_yaml()
126
+ assert_equal(%{Start bc3_search for pattern <.*>
127
+ Analyse test_search.bcss (c:/my_dir)
128
+ ---
129
+ :snapshot: c:/my_dir_extract
130
+ :timestamp: 2011-01-01 00:00:00 +01:00
131
+ :content:
132
+ - :dirname: dir
133
+ :timestamp: 2011-01-01 12:00:00 +01:00
134
+ :attributes: 16
135
+ :content:
136
+ - :filename: file_15.txt
137
+ :filesize: 1
138
+ :crc: 15
139
+ :attributes: 32
140
+ :timestamp: 2011-01-01 12:00:00 +01:00
141
+ - :filename: file_with_crc_16.txt
142
+ :filesize: 1
143
+ :crc: 16
144
+ :attributes: 32
145
+ :timestamp: 2011-01-01 12:00:00 +01:00
146
+ - :filename: file_with_crc_15.txt
147
+ :filesize: 1
148
+ :crc: 15
149
+ :attributes: 32
150
+ :timestamp: 2011-01-01 12:00:00 +01:00},
151
+ `#{$call_bc3_search} -y '*' test_search.bcss`.clean)
152
+ end
153
+ def test_duplicates()
154
+ #Duplicate search, pattern must be '*'
155
+ assert_equal(%{
156
+ Start bc3_search for pattern <.*>
157
+ Analyse test_search.bcss (c:/my_dir)
158
+ dir/file_15.txt
159
+ file_with_crc_15.txt
160
+ Found 2 files in test_search.bcss
161
+
162
+ }.strip, `#{$call_bc3_search} -d '*' test_search.bcss`.strip)
163
+
164
+ #Duplicate search in combination with pattern
165
+ assert_equal(%{
166
+ Start bc3_search for pattern <xx.*\\.txt>
167
+ Analyse test_search.bcss (c:/my_dir)
168
+
169
+ }.strip, `#{$call_bc3_search} -d 'xx*.txt' test_search.bcss`.strip)
170
+ end
171
+
172
+ def test_duplicates_global()
173
+ assert_equal(%{
174
+ Start bc3_search for pattern <.*>
175
+ Restrict on global duplicates
176
+ Analyse test_search.bcss (c:/my_dir)
177
+ dir/file_15.txt
178
+ file_with_crc_15.txt
179
+ Found 2 files in test_search.bcss
180
+
181
+ Analyse test_search_2.bcss (c:/my_dir)
182
+ dir/file_15.txt
183
+ file_with_crc_15.txt
184
+ Found 2 files in test_search_2.bcss
185
+
186
+ }.strip, `#{$call_bc3_search} '*' test_search*.bcss -D`.strip)
187
+ end
188
+
189
+ def test_result_as_snapshot()
190
+ assert_false(File.exist?('test_search_extract.bcss'))
191
+ assert_equal(%{
192
+ Start bc3_search for pattern <xx.*>
193
+ Analyse test_search.bcss (c:/my_dir)
194
+ Save result in test_search_extract.bcss
195
+
196
+ }.strip, `#{$call_bc3_search} -b extract 'xx*' test_search.bcss`.strip)
197
+ assert_true(File.exist?('test_search_extract.bcss'))
198
+
199
+ call_result = `#{$call_bc3_search} 'xx*' test_search.bcss -b`
200
+ regex = %r{Start bc3_search for pattern <xx\.\*>
201
+ Analyse test_search.bcss \(c:/my_dir\)
202
+ Save result in (test_search_extract_\d\d\d\d-\d\d-\d\d_\d\d\d\d.bcss)
203
+ }m
204
+ assert_match(regex, call_result)
205
+ regex =~ call_result
206
+ assert_true(File.exist?($1))
207
+
208
+ #delete snapshots, else other test will get problems
209
+ File.delete($1)
210
+ File.delete('test_search_extract.bcss')
211
+ end
212
+ end
213
+
214
+ def mk_test(name, options)
215
+ output = `#{$call_bc3_search} #{options}`
216
+ puts <<xx
217
+ ====Neuer Test #{name} ====
218
+ !#{options}
219
+ #{output}
220
+
221
+ def test_#{name}()
222
+ assert_equal(%{
223
+ #{output}}.strip, `\#{$call_bc3_search} #{options}`.strip)
224
+ end
225
+ ====Neuer Test #{name} ====
226
+ xx
227
+ end
228
+ #~ Test_search.startup
229
+ #~ mk_test('bcss_result', "-b result.bcss 'xx*.txt' test_search.bcss") if false
230
+ #~ mk_test('duplicates_global', "'*' test_search*.bcss -D")
231
+ #~ exit #no tests