glark 1.9.0 → 1.10.0
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/glark +2 -2
- data/lib/glark.rb +1 -1
- data/lib/glark/app/app.rb +48 -0
- data/lib/glark/app/help.rb +103 -0
- data/lib/glark/app/info/options.rb +84 -0
- data/lib/glark/app/options.rb +201 -0
- data/lib/glark/app/rcfile.rb +49 -0
- data/lib/glark/app/runner.rb +140 -0
- data/lib/glark/app/spec.rb +19 -0
- data/lib/glark/input/filter/criteria_opts.rb +41 -0
- data/lib/glark/input/filter/dir_criteria_opts.rb +37 -0
- data/lib/glark/input/filter/file_criteria_opts.rb +33 -0
- data/lib/glark/input/filter/filter.rb +59 -0
- data/lib/glark/input/filter/options.rb +171 -0
- data/lib/glark/input/options.rb +120 -0
- data/lib/glark/input/range.rb +104 -0
- data/lib/glark/input/spec.rb +39 -0
- data/lib/glark/io/file/archive_file.rb +64 -0
- data/lib/glark/io/file/binary_file.rb +19 -0
- data/lib/glark/io/file/file.rb +57 -0
- data/lib/glark/io/file/gz_file.rb +21 -0
- data/lib/glark/io/file/tar_file.rb +35 -0
- data/lib/glark/io/file/tar_gz_file.rb +52 -0
- data/lib/glark/io/file/zip_file.rb +39 -0
- data/lib/glark/match/and.rb +83 -0
- data/lib/glark/match/and_distance.rb +58 -0
- data/lib/glark/match/compound.rb +34 -0
- data/lib/glark/match/expression.rb +63 -0
- data/lib/glark/match/factory.rb +173 -0
- data/lib/glark/match/ior.rb +20 -0
- data/lib/glark/match/options.rb +74 -0
- data/lib/glark/match/or.rb +41 -0
- data/lib/glark/match/re.rb +81 -0
- data/lib/glark/match/re_factory.rb +44 -0
- data/lib/glark/match/spec.rb +59 -0
- data/lib/glark/match/xor.rb +20 -0
- data/lib/glark/output/binary_file_summary.rb +17 -0
- data/lib/glark/output/common.rb +43 -0
- data/lib/glark/output/context.rb +57 -0
- data/lib/glark/output/count.rb +26 -0
- data/lib/glark/output/file_header.rb +20 -0
- data/lib/glark/output/file_name_only.rb +35 -0
- data/lib/glark/output/formatted.rb +22 -0
- data/lib/glark/output/glark_count.rb +23 -0
- data/lib/glark/output/glark_format.rb +62 -0
- data/lib/glark/output/glark_lines.rb +36 -0
- data/lib/glark/output/grep_count.rb +18 -0
- data/lib/glark/output/grep_lines.rb +42 -0
- data/lib/glark/output/line_status.rb +46 -0
- data/lib/glark/output/lines.rb +100 -0
- data/lib/glark/output/match_list.rb +15 -0
- data/lib/glark/output/options.rb +103 -0
- data/lib/glark/output/results.rb +23 -0
- data/lib/glark/output/spec.rb +105 -0
- data/lib/glark/output/unfiltered_lines.rb +28 -0
- data/lib/glark/util/colors/options.rb +143 -0
- data/lib/glark/util/colors/spec.rb +21 -0
- data/lib/glark/util/highlight.rb +108 -0
- data/lib/glark/util/io/depth.rb +29 -0
- data/lib/glark/util/io/fileset.rb +162 -0
- data/lib/glark/util/io/filter/criteria.rb +49 -0
- data/lib/glark/util/io/filter/filter.rb +10 -0
- data/lib/glark/util/io/lines.rb +117 -0
- data/lib/glark/util/option.rb +34 -0
- data/lib/glark/util/options.rb +12 -0
- data/lib/glark/util/optutil.rb +69 -0
- data/lib/glark/util/timestamper.rb +18 -0
- data/man/glark.1 +1134 -0
- data/test/glark/app/and_test.rb +82 -0
- data/test/glark/app/compound_test.rb +33 -0
- data/test/glark/app/context_test.rb +43 -0
- data/test/glark/app/count_test.rb +89 -0
- data/test/glark/app/dump_test.rb +16 -0
- data/test/glark/app/expression_file_test.rb +22 -0
- data/test/glark/app/extended_regexp_test.rb +17 -0
- data/test/glark/app/extract_matches_test.rb +27 -0
- data/test/glark/app/files_with_match_test.rb +32 -0
- data/test/glark/app/files_without_match_test.rb +26 -0
- data/test/glark/app/filter_test.rb +118 -0
- data/test/glark/app/highlight_test.rb +78 -0
- data/test/glark/app/ignore_case_test.rb +22 -0
- data/test/glark/app/invert_test.rb +49 -0
- data/test/glark/app/ior_test.rb +21 -0
- data/test/glark/app/label_test.rb +28 -0
- data/test/glark/app/line_number_color_test.rb +42 -0
- data/test/glark/app/line_numbers_test.rb +42 -0
- data/test/glark/app/match_limit_test.rb +49 -0
- data/test/glark/app/options_test.rb +722 -0
- data/test/glark/app/range_test.rb +101 -0
- data/test/glark/app/rcfile_test.rb +113 -0
- data/test/glark/app/record_separator_test.rb +32 -0
- data/test/glark/app/regexp_test.rb +48 -0
- data/test/glark/app/tc.rb +92 -0
- data/test/glark/app/text_color_test.rb +31 -0
- data/test/glark/app/whole_lines_test.rb +17 -0
- data/test/glark/app/whole_words_test.rb +42 -0
- data/test/glark/app/xor_test.rb +19 -0
- data/test/glark/input/binary_file_test.rb +0 -0
- data/test/glark/input/directory_test.rb +202 -0
- data/test/glark/input/dirname_test.rb +69 -0
- data/test/glark/input/exclude_matching_test.rb +20 -0
- data/test/glark/input/ext_test.rb +65 -0
- data/test/glark/input/filter/criteria_test.rb +91 -0
- data/test/glark/input/filter/filter_spec_test.rb +27 -0
- data/test/glark/input/filter/filter_test.rb +21 -0
- data/test/glark/input/name_test.rb +75 -0
- data/test/glark/input/path_test.rb +72 -0
- data/test/glark/input/range_test.rb +82 -0
- data/test/glark/input/size_limit_test.rb +51 -0
- data/test/glark/input/split_as_path_test.rb +28 -0
- data/test/glark/match_test.rb +192 -0
- data/test/glark/resources.rb +21 -0
- data/test/glark/tc.rb +37 -0
- data/test/resources/add.rb +10 -0
- data/test/resources/echo.rb +2 -0
- data/test/resources/greet.rb +13 -0
- metadata +198 -28
- data/README +0 -0
- data/bin/jlark +0 -63
- data/lib/glark/expression.rb +0 -440
- data/lib/glark/exprfactory.rb +0 -248
- data/lib/glark/glark.rb +0 -297
- data/lib/glark/help.rb +0 -85
- data/lib/glark/input.rb +0 -183
- data/lib/glark/options.rb +0 -757
- data/lib/glark/output.rb +0 -266
- data/test/lib/glark/glark_test.rb +0 -317
- data/test/lib/glark/options_test.rb +0 -891
@@ -0,0 +1,101 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# -*- ruby -*-
|
3
|
+
|
4
|
+
require 'glark/app/tc'
|
5
|
+
|
6
|
+
module Glark
|
7
|
+
class RangeAppTestCase < AppTestCase
|
8
|
+
def test_range_no_context
|
9
|
+
fname = '/proj/org/incava/glark/test/resources/textfile.txt'
|
10
|
+
expected = [
|
11
|
+
" 8 -rw-r--r-- 1 jpace jpace 22754 2010-12-04 15:24 07-[30m[43mTheFriarsTale[0m.txt",
|
12
|
+
" 9 -rw-r--r-- 1 jpace jpace 35994 2010-12-04 15:24 08-[30m[43mTheSompnoursTale[0m.txt",
|
13
|
+
" 10 -rw-r--r-- 1 jpace jpace 64791 2010-12-04 15:24 09-[30m[43mTheClerksTale[0m.txt",
|
14
|
+
" 11 -rw-r--r-- 1 jpace jpace 65852 2010-12-04 15:24 10-[30m[43mTheMerchantsTale[0m.txt",
|
15
|
+
" 12 -rw-r--r-- 1 jpace jpace 42282 2010-12-04 15:24 11-[30m[43mTheSquiresTale[0m.txt",
|
16
|
+
" 13 -rw-r--r-- 1 jpace jpace 51996 2010-12-04 15:24 12-[30m[43mTheFranklinsTale[0m.txt",
|
17
|
+
" 14 -rw-r--r-- 1 jpace jpace 15615 2010-12-04 15:24 13-[30m[43mTheDoctorsTale[0m.txt",
|
18
|
+
" 15 -rw-r--r-- 1 jpace jpace 39546 2010-12-04 15:24 14-[30m[43mThePardonersTale[0m.txt",
|
19
|
+
" 16 -rw-r--r-- 1 jpace jpace 25163 2010-12-04 15:24 15-[30m[43mTheShipmansTale[0m.txt",
|
20
|
+
" 17 -rw-r--r-- 1 jpace jpace 14979 2010-12-04 15:24 16-[30m[43mThePrioresssTale[0m.txt",
|
21
|
+
" 20 -rw-r--r-- 1 jpace jpace 49747 2010-12-04 15:24 19-[30m[43mTheMonksTale[0m.txt",
|
22
|
+
]
|
23
|
+
run_app_test expected, [ '-R', '25%,20', 'The\w+Tale' ], fname
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_range_with_context
|
27
|
+
fname = '/proj/org/incava/glark/test/resources/textfile.txt'
|
28
|
+
expected = [
|
29
|
+
" 5 - -rw-r--r-- 1 jpace jpace 6525 2010-12-04 15:24 04-TheCooksTale.txt",
|
30
|
+
" 6 - -rw-r--r-- 1 jpace jpace 63290 2010-12-04 15:24 05-TheManOfLawsTale.txt",
|
31
|
+
" 7 - -rw-r--r-- 1 jpace jpace 71054 2010-12-04 15:24 06-TheWifeOfBathsTale.txt",
|
32
|
+
" 8 : -rw-r--r-- 1 jpace jpace 22754 2010-12-04 15:24 07-[30m[43mTheFriarsTale[0m.txt",
|
33
|
+
" 9 : -rw-r--r-- 1 jpace jpace 35994 2010-12-04 15:24 08-[30m[43mTheSompnoursTale[0m.txt",
|
34
|
+
" 10 : -rw-r--r-- 1 jpace jpace 64791 2010-12-04 15:24 09-[30m[43mTheClerksTale[0m.txt",
|
35
|
+
" 11 : -rw-r--r-- 1 jpace jpace 65852 2010-12-04 15:24 10-[30m[43mTheMerchantsTale[0m.txt",
|
36
|
+
" 12 : -rw-r--r-- 1 jpace jpace 42282 2010-12-04 15:24 11-[30m[43mTheSquiresTale[0m.txt",
|
37
|
+
" 13 : -rw-r--r-- 1 jpace jpace 51996 2010-12-04 15:24 12-[30m[43mTheFranklinsTale[0m.txt",
|
38
|
+
" 14 : -rw-r--r-- 1 jpace jpace 15615 2010-12-04 15:24 13-[30m[43mTheDoctorsTale[0m.txt",
|
39
|
+
" 15 : -rw-r--r-- 1 jpace jpace 39546 2010-12-04 15:24 14-[30m[43mThePardonersTale[0m.txt",
|
40
|
+
" 16 : -rw-r--r-- 1 jpace jpace 25163 2010-12-04 15:24 15-[30m[43mTheShipmansTale[0m.txt",
|
41
|
+
" 17 : -rw-r--r-- 1 jpace jpace 14979 2010-12-04 15:24 16-[30m[43mThePrioresssTale[0m.txt",
|
42
|
+
" 18 + -rw-r--r-- 1 jpace jpace 14834 2010-12-04 15:24 17-ChaucersTaleOfSirThopas.txt",
|
43
|
+
" 19 + -rw-r--r-- 1 jpace jpace 43249 2010-12-04 15:24 18-ChaucersTaleOfMeliboeus.txt",
|
44
|
+
" 20 : -rw-r--r-- 1 jpace jpace 49747 2010-12-04 15:24 19-[30m[43mTheMonksTale[0m.txt",
|
45
|
+
" 21 + -rw-r--r-- 1 jpace jpace 45326 2010-12-04 15:24 20-TheNunsPriestsTale.txt",
|
46
|
+
" 22 + -rw-r--r-- 1 jpace jpace 30734 2010-12-04 15:24 21-TheSecondNunsTale.txt",
|
47
|
+
" 23 + -rw-r--r-- 1 jpace jpace 52953 2010-12-04 15:24 22-TheCanonsYeomansTale.txt",
|
48
|
+
]
|
49
|
+
run_app_test expected, [ '-3', '-R', '25%,20', 'The\w+Tale' ], fname
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_after_no_context
|
53
|
+
fname = '/proj/org/incava/glark/test/resources/textfile.txt'
|
54
|
+
expected = [
|
55
|
+
" 8 -rw-r--r-- 1 jpace jpace 22754 2010-12-04 15:24 07-[30m[43mTheFriarsTale[0m.txt",
|
56
|
+
" 9 -rw-r--r-- 1 jpace jpace 35994 2010-12-04 15:24 08-[30m[43mTheSompnoursTale[0m.txt",
|
57
|
+
" 10 -rw-r--r-- 1 jpace jpace 64791 2010-12-04 15:24 09-[30m[43mTheClerksTale[0m.txt",
|
58
|
+
" 11 -rw-r--r-- 1 jpace jpace 65852 2010-12-04 15:24 10-[30m[43mTheMerchantsTale[0m.txt",
|
59
|
+
" 12 -rw-r--r-- 1 jpace jpace 42282 2010-12-04 15:24 11-[30m[43mTheSquiresTale[0m.txt",
|
60
|
+
" 13 -rw-r--r-- 1 jpace jpace 51996 2010-12-04 15:24 12-[30m[43mTheFranklinsTale[0m.txt",
|
61
|
+
" 14 -rw-r--r-- 1 jpace jpace 15615 2010-12-04 15:24 13-[30m[43mTheDoctorsTale[0m.txt",
|
62
|
+
" 15 -rw-r--r-- 1 jpace jpace 39546 2010-12-04 15:24 14-[30m[43mThePardonersTale[0m.txt",
|
63
|
+
" 16 -rw-r--r-- 1 jpace jpace 25163 2010-12-04 15:24 15-[30m[43mTheShipmansTale[0m.txt",
|
64
|
+
" 17 -rw-r--r-- 1 jpace jpace 14979 2010-12-04 15:24 16-[30m[43mThePrioresssTale[0m.txt",
|
65
|
+
" 20 -rw-r--r-- 1 jpace jpace 49747 2010-12-04 15:24 19-[30m[43mTheMonksTale[0m.txt",
|
66
|
+
" 21 -rw-r--r-- 1 jpace jpace 45326 2010-12-04 15:24 20-[30m[43mTheNunsPriestsTale[0m.txt",
|
67
|
+
" 22 -rw-r--r-- 1 jpace jpace 30734 2010-12-04 15:24 21-[30m[43mTheSecondNunsTale[0m.txt",
|
68
|
+
" 23 -rw-r--r-- 1 jpace jpace 52953 2010-12-04 15:24 22-[30m[43mTheCanonsYeomansTale[0m.txt",
|
69
|
+
" 24 -rw-r--r-- 1 jpace jpace 21141 2010-12-04 15:24 23-[30m[43mTheManciplesTale[0m.txt",
|
70
|
+
" 25 -rw-r--r-- 1 jpace jpace 58300 2010-12-04 15:24 24-[30m[43mTheParsonsTale[0m.txt",
|
71
|
+
]
|
72
|
+
run_app_test expected, [ '--after', '25%', 'The\w+Tale' ], fname
|
73
|
+
end
|
74
|
+
|
75
|
+
def test_before_no_context
|
76
|
+
fname = '/proj/org/incava/glark/test/resources/textfile.txt'
|
77
|
+
expected = [
|
78
|
+
" 2 -rw-r--r-- 1 jpace jpace 126084 2010-12-04 15:24 01-[30m[43mTheKnightsTale[0m.txt",
|
79
|
+
" 3 -rw-r--r-- 1 jpace jpace 45450 2010-12-04 15:24 02-[30m[43mTheMillersTale[0m.txt",
|
80
|
+
" 4 -rw-r--r-- 1 jpace jpace 29296 2010-12-04 15:24 03-[30m[43mTheReevesTale[0m.txt",
|
81
|
+
" 5 -rw-r--r-- 1 jpace jpace 6525 2010-12-04 15:24 04-[30m[43mTheCooksTale[0m.txt",
|
82
|
+
" 6 -rw-r--r-- 1 jpace jpace 63290 2010-12-04 15:24 05-[30m[43mTheManOfLawsTale[0m.txt",
|
83
|
+
" 7 -rw-r--r-- 1 jpace jpace 71054 2010-12-04 15:24 06-[30m[43mTheWifeOfBathsTale[0m.txt",
|
84
|
+
" 8 -rw-r--r-- 1 jpace jpace 22754 2010-12-04 15:24 07-[30m[43mTheFriarsTale[0m.txt",
|
85
|
+
" 9 -rw-r--r-- 1 jpace jpace 35994 2010-12-04 15:24 08-[30m[43mTheSompnoursTale[0m.txt",
|
86
|
+
" 10 -rw-r--r-- 1 jpace jpace 64791 2010-12-04 15:24 09-[30m[43mTheClerksTale[0m.txt",
|
87
|
+
" 11 -rw-r--r-- 1 jpace jpace 65852 2010-12-04 15:24 10-[30m[43mTheMerchantsTale[0m.txt",
|
88
|
+
" 12 -rw-r--r-- 1 jpace jpace 42282 2010-12-04 15:24 11-[30m[43mTheSquiresTale[0m.txt",
|
89
|
+
" 13 -rw-r--r-- 1 jpace jpace 51996 2010-12-04 15:24 12-[30m[43mTheFranklinsTale[0m.txt",
|
90
|
+
]
|
91
|
+
run_app_test expected, [ '--before', '50%', 'The\w+Tale' ], fname
|
92
|
+
end
|
93
|
+
|
94
|
+
def test_no_matches_in_range
|
95
|
+
fname = '/proj/org/incava/glark/test/resources/textfile.txt'
|
96
|
+
expected = [
|
97
|
+
]
|
98
|
+
run_app_test expected, [ '-R', '55%,90%', 'TheD\w+Tale' ], fname
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
@@ -0,0 +1,113 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# -*- ruby -*-
|
3
|
+
|
4
|
+
require 'pathname'
|
5
|
+
require 'tempfile'
|
6
|
+
require 'glark/app/tc'
|
7
|
+
require 'glark/app/options'
|
8
|
+
|
9
|
+
module Glark
|
10
|
+
class RcfileTestCase < AppTestCase
|
11
|
+
def run_option_test args, exp, &blk
|
12
|
+
gopt = Glark::AppOptions.new
|
13
|
+
gopt.run args
|
14
|
+
|
15
|
+
exp.each do |name, expval|
|
16
|
+
val = gopt.method(name).call
|
17
|
+
assert_equal expval, val
|
18
|
+
end
|
19
|
+
|
20
|
+
blk.call(gopt) if blk
|
21
|
+
end
|
22
|
+
|
23
|
+
def read_rcfile opts, basename
|
24
|
+
opts.read_rcfile Pathname.new('/proj/org/incava/glark/test/resources') + basename
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_simple
|
28
|
+
run_option_test(%w{ foo }, []) do |opts|
|
29
|
+
# default values
|
30
|
+
assert_equal "multi", opts.colors.text_color_style
|
31
|
+
assert_equal false, opts.local_config_files
|
32
|
+
|
33
|
+
read_rcfile opts, 'rcfile.txt'
|
34
|
+
|
35
|
+
assert_equal "single", opts.colors.text_color_style
|
36
|
+
assert_equal true, opts.local_config_files
|
37
|
+
###$$$ assert_equal %w{ bold red }, opts.colors.line_number_highlight.colors
|
38
|
+
assert opts.match_spec.ignorecase
|
39
|
+
|
40
|
+
assert_file_filter_eq 1000, opts, :size, :negative, SizeLimitFilter, :max_size
|
41
|
+
###$$$ assert_equal %w{ underline magenta }, opts.match_spec.text_highlights[3].colors
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_grep
|
46
|
+
run_option_test(%w{ foo }, []) do |opts|
|
47
|
+
# default values
|
48
|
+
assert_equal "glark", opts.output_options.style
|
49
|
+
read_rcfile opts, 'rcgrep.txt'
|
50
|
+
assert_equal "grep", opts.output_options.style
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def assert_has_filter_pattern exppat, filters, cls
|
55
|
+
clsfilters = filters.select { |pf| pf.kind_of? cls }
|
56
|
+
expre = Regexp.new exppat
|
57
|
+
assert clsfilters.detect { |filter| filter.pattern == expre }, "exppat: #{exppat}; cls: #{cls}"
|
58
|
+
end
|
59
|
+
|
60
|
+
def assert_filters opts, filttype, posneg, cls, *patterns
|
61
|
+
filtmeth = filttype.to_s + '_filters'
|
62
|
+
spec = opts.input_options.send filtmeth.to_sym
|
63
|
+
filters = spec.send posneg
|
64
|
+
patterns.each do |pat|
|
65
|
+
assert_has_filter_pattern pat, filters, cls
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def assert_file_filters opts, posneg, cls, *patterns
|
70
|
+
assert_filters opts, :file, posneg, cls, *patterns
|
71
|
+
end
|
72
|
+
|
73
|
+
def assert_directory_filters opts, posneg, cls, *patterns
|
74
|
+
assert_filters opts, :directory, posneg, cls, *patterns
|
75
|
+
end
|
76
|
+
|
77
|
+
def test_name
|
78
|
+
run_option_test(%w{ foo }, []) do |opts|
|
79
|
+
read_rcfile opts, 'rcmatch.txt'
|
80
|
+
|
81
|
+
[ '\w+.java', '\w+.rb' ].each do |pat|
|
82
|
+
assert_file_filter_pattern_eq pat, opts, :name, :positive, BaseNameFilter
|
83
|
+
end
|
84
|
+
|
85
|
+
assert_file_filter_pattern_eq 'zxcdjlk', opts, :name, :negative, BaseNameFilter
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def test_path
|
90
|
+
run_option_test(%w{ foo }, []) do |opts|
|
91
|
+
read_rcfile opts, 'rcpath.txt'
|
92
|
+
|
93
|
+
assert_directory_filter_pattern_eq 'src/main/java', opts, :dirpath, :positive, FullNameFilter
|
94
|
+
|
95
|
+
[ 'src/main/java', 'src/test/ruby' ].each do |pat|
|
96
|
+
assert_directory_filter_pattern_eq pat, opts, :dirpath, :positive, FullNameFilter
|
97
|
+
end
|
98
|
+
|
99
|
+
assert_directory_filter_pattern_eq 'org/incava/util', opts, :dirpath, :negative, FullNameFilter
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
def test_ext
|
104
|
+
run_option_test(%w{ foo }, []) do |opts|
|
105
|
+
read_rcfile opts, 'rcext.txt'
|
106
|
+
|
107
|
+
assert_file_filter_pattern_eq 'rb', opts, :ext, :positive, ExtFilter
|
108
|
+
assert_file_filter_pattern_eq 'pl', opts, :ext, :positive, ExtFilter
|
109
|
+
assert_file_filter_pattern_eq 'txt', opts, :ext, :negative, ExtFilter
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# -*- ruby -*-
|
3
|
+
|
4
|
+
require 'glark/app/tc'
|
5
|
+
|
6
|
+
module Glark
|
7
|
+
class RecordSeparatorTestCase < AppTestCase
|
8
|
+
def test_default
|
9
|
+
fname = '/proj/org/incava/glark/test/resources/04-TheCooksTale.txt'
|
10
|
+
expected = [
|
11
|
+
" 2 For of [30m[43mthy parsley yet fare they the[0m worse.",
|
12
|
+
]
|
13
|
+
run_app_test expected, [ 'thy.*the' ], fname
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_paragraph
|
17
|
+
fname = '/proj/org/incava/glark/test/resources/04-TheCooksTale.txt'
|
18
|
+
expected = [
|
19
|
+
" 1 Of many a pilgrim hast thou Christe's curse,",
|
20
|
+
" 2 For of [30m[43mthy[0m parsley yet fare [30m[42mthe[0my [30m[42mthe[0m worse.",
|
21
|
+
" 3 ",
|
22
|
+
" 4 That [30m[42mthe[0my have eaten in [30m[43mthy[0m stubble goose:",
|
23
|
+
" 5 For in [30m[43mthy[0m shop doth many a fly go loose.",
|
24
|
+
" 6 ",
|
25
|
+
" 7 Now tell on, gentle Roger, by [30m[43mthy[0m name,",
|
26
|
+
" 8 But yet I pray [30m[42mthe[0me be not wroth for game;",
|
27
|
+
" 9 A man may say full sooth in game and play.",
|
28
|
+
]
|
29
|
+
run_app_test expected, [ '-0', '--and=2', 'thy', 'the' ], fname
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# -*- ruby -*-
|
3
|
+
|
4
|
+
require 'glark/app/tc'
|
5
|
+
|
6
|
+
module Glark
|
7
|
+
class RegexpTestCase < AppTestCase
|
8
|
+
def test_regexp_no_context
|
9
|
+
fname = '/proj/org/incava/glark/test/resources/textfile.txt'
|
10
|
+
expected = [
|
11
|
+
" 2 -rw-r--r-- 1 jpace jpace 126084 2010-12-04 15:24 01-[30m[43mTheKnightsTale[0m.txt",
|
12
|
+
" 3 -rw-r--r-- 1 jpace jpace 45450 2010-12-04 15:24 02-[30m[43mTheMillersTale[0m.txt",
|
13
|
+
" 4 -rw-r--r-- 1 jpace jpace 29296 2010-12-04 15:24 03-[30m[43mTheReevesTale[0m.txt",
|
14
|
+
" 5 -rw-r--r-- 1 jpace jpace 6525 2010-12-04 15:24 04-[30m[43mTheCooksTale[0m.txt",
|
15
|
+
" 6 -rw-r--r-- 1 jpace jpace 63290 2010-12-04 15:24 05-[30m[43mTheManOfLawsTale[0m.txt",
|
16
|
+
" 7 -rw-r--r-- 1 jpace jpace 71054 2010-12-04 15:24 06-[30m[43mTheWifeOfBathsTale[0m.txt",
|
17
|
+
" 8 -rw-r--r-- 1 jpace jpace 22754 2010-12-04 15:24 07-[30m[43mTheFriarsTale[0m.txt",
|
18
|
+
" 9 -rw-r--r-- 1 jpace jpace 35994 2010-12-04 15:24 08-[30m[43mTheSompnoursTale[0m.txt",
|
19
|
+
" 10 -rw-r--r-- 1 jpace jpace 64791 2010-12-04 15:24 09-[30m[43mTheClerksTale[0m.txt",
|
20
|
+
" 11 -rw-r--r-- 1 jpace jpace 65852 2010-12-04 15:24 10-[30m[43mTheMerchantsTale[0m.txt",
|
21
|
+
" 12 -rw-r--r-- 1 jpace jpace 42282 2010-12-04 15:24 11-[30m[43mTheSquiresTale[0m.txt",
|
22
|
+
" 13 -rw-r--r-- 1 jpace jpace 51996 2010-12-04 15:24 12-[30m[43mTheFranklinsTale[0m.txt",
|
23
|
+
" 14 -rw-r--r-- 1 jpace jpace 15615 2010-12-04 15:24 13-[30m[43mTheDoctorsTale[0m.txt",
|
24
|
+
" 15 -rw-r--r-- 1 jpace jpace 39546 2010-12-04 15:24 14-[30m[43mThePardonersTale[0m.txt",
|
25
|
+
" 16 -rw-r--r-- 1 jpace jpace 25163 2010-12-04 15:24 15-[30m[43mTheShipmansTale[0m.txt",
|
26
|
+
" 17 -rw-r--r-- 1 jpace jpace 14979 2010-12-04 15:24 16-[30m[43mThePrioresssTale[0m.txt",
|
27
|
+
" 20 -rw-r--r-- 1 jpace jpace 49747 2010-12-04 15:24 19-[30m[43mTheMonksTale[0m.txt",
|
28
|
+
" 21 -rw-r--r-- 1 jpace jpace 45326 2010-12-04 15:24 20-[30m[43mTheNunsPriestsTale[0m.txt",
|
29
|
+
" 22 -rw-r--r-- 1 jpace jpace 30734 2010-12-04 15:24 21-[30m[43mTheSecondNunsTale[0m.txt",
|
30
|
+
" 23 -rw-r--r-- 1 jpace jpace 52953 2010-12-04 15:24 22-[30m[43mTheCanonsYeomansTale[0m.txt",
|
31
|
+
" 24 -rw-r--r-- 1 jpace jpace 21141 2010-12-04 15:24 23-[30m[43mTheManciplesTale[0m.txt",
|
32
|
+
" 25 -rw-r--r-- 1 jpace jpace 58300 2010-12-04 15:24 24-[30m[43mTheParsonsTale[0m.txt",
|
33
|
+
]
|
34
|
+
run_app_test expected, [ 'The\w+Tale' ], fname
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_one_line_grep
|
38
|
+
fname = '/proj/org/incava/glark/test/resources/textfile.txt'
|
39
|
+
expected = [
|
40
|
+
" -rw-r--r-- 1 jpace jpace 35994 2010-12-04 15:24 08-TheSompnoursTale.txt",
|
41
|
+
" -rw-r--r-- 1 jpace jpace 42282 2010-12-04 15:24 11-TheSquiresTale.txt",
|
42
|
+
" -rw-r--r-- 1 jpace jpace 25163 2010-12-04 15:24 15-TheShipmansTale.txt",
|
43
|
+
" -rw-r--r-- 1 jpace jpace 30734 2010-12-04 15:24 21-TheSecondNunsTale.txt",
|
44
|
+
]
|
45
|
+
run_app_test expected, [ '-g', 'TheS.*Tale' ], fname
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,92 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# -*- ruby -*-
|
3
|
+
|
4
|
+
require 'pathname'
|
5
|
+
require 'tempfile'
|
6
|
+
require 'stringio'
|
7
|
+
require 'glark/tc'
|
8
|
+
require 'glark/app/options'
|
9
|
+
require 'glark/util/timestamper'
|
10
|
+
|
11
|
+
module Glark
|
12
|
+
class AppTestCase < Glark::TestCase
|
13
|
+
include TimeStamper
|
14
|
+
|
15
|
+
def setup
|
16
|
+
# ignore what they have in ENV[HOME]
|
17
|
+
ENV['HOME'] = '/this/should/not/exist'
|
18
|
+
super
|
19
|
+
end
|
20
|
+
|
21
|
+
def teardown
|
22
|
+
super
|
23
|
+
end
|
24
|
+
|
25
|
+
def run_glark args, *files
|
26
|
+
gopt = AppOptions.new
|
27
|
+
sio = StringIO.new
|
28
|
+
gopt.run(args + files)
|
29
|
+
gopt.output_options.out = sio
|
30
|
+
|
31
|
+
Log.verbose = true
|
32
|
+
|
33
|
+
glark = Runner.new gopt, gopt.fileset
|
34
|
+
|
35
|
+
sio.close
|
36
|
+
|
37
|
+
if true
|
38
|
+
puts "....."
|
39
|
+
puts sio.string
|
40
|
+
puts "....."
|
41
|
+
end
|
42
|
+
|
43
|
+
sio.string
|
44
|
+
end
|
45
|
+
|
46
|
+
def run_app_test expected, args, *files
|
47
|
+
result = run_glark args, *files
|
48
|
+
actual = result.split "\n"
|
49
|
+
( 0 ... [ expected.length, actual.length ].max ).each do |idx|
|
50
|
+
assert_equal expected[idx], actual[idx], "idx: #{idx}"
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def run_app_test_exact_output expected, args, *files
|
55
|
+
result = run_glark args, *files
|
56
|
+
assert_equal expected, result
|
57
|
+
end
|
58
|
+
|
59
|
+
def assert_file_filter_pattern_eq exppat, opts, field, posneg, cls
|
60
|
+
expre = Regexp.new exppat
|
61
|
+
assert_file_filter_eq expre, opts, field, posneg, cls, :pattern
|
62
|
+
end
|
63
|
+
|
64
|
+
def assert_file_filter_eq expval, opts, field, posneg, cls, matchfield
|
65
|
+
criteria = opts.input_spec.file_criteria
|
66
|
+
assert_filter_eq expval, criteria, field, posneg, cls, matchfield
|
67
|
+
end
|
68
|
+
|
69
|
+
def assert_directory_filter_pattern_eq exppat, opts, field, posneg, cls
|
70
|
+
expre = Regexp.new exppat
|
71
|
+
assert_directory_filter_eq expre, opts, field, posneg, cls, :pattern
|
72
|
+
end
|
73
|
+
|
74
|
+
def assert_directory_filter_eq expval, opts, field, posneg, cls, matchfield
|
75
|
+
criteria = opts.input_spec.dir_criteria
|
76
|
+
assert_filter_eq expval, criteria, field, posneg, cls, matchfield
|
77
|
+
end
|
78
|
+
|
79
|
+
def assert_filter_eq expval, criteria, field, posneg, cls, matchfield
|
80
|
+
pncrit = criteria.get field, posneg
|
81
|
+
pncrit.each do |crit|
|
82
|
+
matchval = crit.send matchfield
|
83
|
+
if expval == matchval
|
84
|
+
assert true
|
85
|
+
return
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
assert false, "no match: #{matchfield}; #{expval}"
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# -*- ruby -*-
|
3
|
+
|
4
|
+
require 'glark/app/tc'
|
5
|
+
|
6
|
+
module Glark
|
7
|
+
class TextColorTestCase < AppTestCase
|
8
|
+
def test_single
|
9
|
+
fname = '/proj/org/incava/glark/test/resources/textfile.txt'
|
10
|
+
expected = [
|
11
|
+
" 9 -rw-r--r-- 1 jpace jpace 35994 2010-12-04 15:24 08-[1mTheSompnoursTale[0m.txt",
|
12
|
+
" 12 -rw-r--r-- 1 jpace jpace 42282 2010-12-04 15:24 11-[1mTheSquiresTale[0m.txt",
|
13
|
+
" 16 -rw-r--r-- 1 jpace jpace 25163 2010-12-04 15:24 15-[1mTheShipmansTale[0m.txt",
|
14
|
+
" 22 -rw-r--r-- 1 jpace jpace 30734 2010-12-04 15:24 21-[1mTheSecondNunsTale[0m.txt",
|
15
|
+
]
|
16
|
+
run_app_test expected, [ '--text-color', 'bold', 'TheS.*Tale' ], fname
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_multi
|
20
|
+
fname = '/proj/org/incava/glark/test/resources/textfile.txt'
|
21
|
+
expected = [
|
22
|
+
# go IU!
|
23
|
+
" 9 -rw-r--r-- 1 jpace jpace 35994 2010-12-04 15:24 08-[4m[31m[47mTheSompnoursTale[0m.txt",
|
24
|
+
" 12 -rw-r--r-- 1 jpace jpace 42282 2010-12-04 15:24 11-[4m[31m[47mTheSquiresTale[0m.txt",
|
25
|
+
" 16 -rw-r--r-- 1 jpace jpace 25163 2010-12-04 15:24 15-[4m[31m[47mTheShipmansTale[0m.txt",
|
26
|
+
" 22 -rw-r--r-- 1 jpace jpace 30734 2010-12-04 15:24 21-[4m[31m[47mTheSecondNunsTale[0m.txt",
|
27
|
+
]
|
28
|
+
run_app_test expected, [ '--text-color', 'underline red on white', 'TheS.*Tale' ], fname
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# -*- ruby -*-
|
3
|
+
|
4
|
+
require 'glark/app/tc'
|
5
|
+
|
6
|
+
module Glark
|
7
|
+
class WholeLinesTestCase < AppTestCase
|
8
|
+
def test_
|
9
|
+
fname = '/proj/org/incava/glark/test/resources/filelist.txt'
|
10
|
+
expected = [
|
11
|
+
" 12 [30m[43m11-The_Squires_Tale.txt[0m",
|
12
|
+
" 16 [30m[43m15-The_Shipmans_Tale.txt[0m",
|
13
|
+
]
|
14
|
+
run_app_test expected, [ '--line-regexp', '1.*The_S\w+.txt' ], fname
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# -*- ruby -*-
|
3
|
+
|
4
|
+
require 'glark/app/tc'
|
5
|
+
|
6
|
+
module Glark
|
7
|
+
class WholeWordsTestCase < AppTestCase
|
8
|
+
def test_no
|
9
|
+
fname = '/proj/org/incava/glark/test/resources/spaces.txt'
|
10
|
+
expected = [
|
11
|
+
" 6 05 The Man Of [30m[43mLaws[0m Tale.txt",
|
12
|
+
" 7 06 The Wife Of [30m[43mBaths[0m Tale.txt",
|
13
|
+
" 8 07 The Fr[30m[43miars[0m Tale.txt",
|
14
|
+
" 11 10 The Merc[30m[43mhants[0m Tale.txt",
|
15
|
+
" 13 12 The F[30m[43mranklins[0m Tale.txt",
|
16
|
+
" 15 14 The [30m[43mPardoners[0m Tale.txt",
|
17
|
+
" 16 15 The Ship[30m[43mmans[0m Tale.txt",
|
18
|
+
" 18 17 C[30m[43mhaucers[0m Tale Of Sir Thopas.txt",
|
19
|
+
" 19 18 C[30m[43mhaucers[0m Tale Of Meliboeus.txt",
|
20
|
+
" 23 22 The [30m[43mCanons[0m Yeo[30m[43mmans[0m Tale.txt",
|
21
|
+
" 24 23 The [30m[43mManciples[0m Tale.txt",
|
22
|
+
" 25 24 The [30m[43mParsons[0m Tale.txt",
|
23
|
+
" 26 25 Preces De C[30m[43mhauceres[0m.txt",
|
24
|
+
]
|
25
|
+
run_app_test expected, [ '\wa\w+s' ], fname
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_yes
|
29
|
+
fname = '/proj/org/incava/glark/test/resources/spaces.txt'
|
30
|
+
expected = [
|
31
|
+
" 6 05 The Man Of [30m[43mLaws[0m Tale.txt",
|
32
|
+
" 7 06 The Wife Of [30m[43mBaths[0m Tale.txt",
|
33
|
+
" 15 14 The [30m[43mPardoners[0m Tale.txt",
|
34
|
+
" 23 22 The [30m[43mCanons[0m Yeomans Tale.txt",
|
35
|
+
" 24 23 The [30m[43mManciples[0m Tale.txt",
|
36
|
+
" 25 24 The [30m[43mParsons[0m Tale.txt",
|
37
|
+
]
|
38
|
+
run_app_test expected, [ '-w', '\wa\w+s' ], fname
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|