glark 1.9.0 → 1.10.0
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.
- 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,78 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# -*- ruby -*-
|
3
|
+
|
4
|
+
require 'glark/app/tc'
|
5
|
+
|
6
|
+
module Glark
|
7
|
+
class HighlightTestCase < AppTestCase
|
8
|
+
def test_file_names_no_highlight
|
9
|
+
files = [ '/proj/org/incava/glark/test/resources/textfile.txt', '/proj/org/incava/glark/test/resources/filelist.txt' ]
|
10
|
+
expected = [
|
11
|
+
"[1m/proj/org/incava/glark/test/resources/textfile.txt[0m",
|
12
|
+
" 3 -rw-r--r-- 1 jpace jpace 45450 2010-12-04 15:24 02-[30m[43mTheMillersTale[0m.txt",
|
13
|
+
" 6 -rw-r--r-- 1 jpace jpace 63290 2010-12-04 15:24 05-[30m[43mTheManOfLawsTale[0m.txt",
|
14
|
+
" 11 -rw-r--r-- 1 jpace jpace 65852 2010-12-04 15:24 10-[30m[43mTheMerchantsTale[0m.txt",
|
15
|
+
" 20 -rw-r--r-- 1 jpace jpace 49747 2010-12-04 15:24 19-[30m[43mTheMonksTale[0m.txt",
|
16
|
+
" 24 -rw-r--r-- 1 jpace jpace 21141 2010-12-04 15:24 23-[30m[43mTheManciplesTale[0m.txt",
|
17
|
+
"[1m/proj/org/incava/glark/test/resources/filelist.txt[0m",
|
18
|
+
" 3 02-[30m[43mThe_Millers_Tale[0m.txt",
|
19
|
+
" 6 05-[30m[43mThe_Man_Of_Laws_Tale[0m.txt",
|
20
|
+
" 11 10-[30m[43mThe_Merchants_Tale[0m.txt",
|
21
|
+
" 20 19-[30m[43mThe_Monks_Tale[0m.txt",
|
22
|
+
" 24 23-[30m[43mThe_Manciples_Tale[0m.txt",
|
23
|
+
]
|
24
|
+
run_app_test expected, [ 'The.?M.*Tale' ], *files
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_file_names_highlight
|
28
|
+
files = [ '/proj/org/incava/glark/test/resources/textfile.txt', '/proj/org/incava/glark/test/resources/filelist.txt' ]
|
29
|
+
expected = [
|
30
|
+
"[33m/proj/org/incava/glark/test/resources/textfile.txt[0m",
|
31
|
+
" 3 -rw-r--r-- 1 jpace jpace 45450 2010-12-04 15:24 02-[30m[43mTheMillersTale[0m.txt",
|
32
|
+
" 6 -rw-r--r-- 1 jpace jpace 63290 2010-12-04 15:24 05-[30m[43mTheManOfLawsTale[0m.txt",
|
33
|
+
" 11 -rw-r--r-- 1 jpace jpace 65852 2010-12-04 15:24 10-[30m[43mTheMerchantsTale[0m.txt",
|
34
|
+
" 20 -rw-r--r-- 1 jpace jpace 49747 2010-12-04 15:24 19-[30m[43mTheMonksTale[0m.txt",
|
35
|
+
" 24 -rw-r--r-- 1 jpace jpace 21141 2010-12-04 15:24 23-[30m[43mTheManciplesTale[0m.txt",
|
36
|
+
"[33m/proj/org/incava/glark/test/resources/filelist.txt[0m",
|
37
|
+
" 3 02-[30m[43mThe_Millers_Tale[0m.txt",
|
38
|
+
" 6 05-[30m[43mThe_Man_Of_Laws_Tale[0m.txt",
|
39
|
+
" 11 10-[30m[43mThe_Merchants_Tale[0m.txt",
|
40
|
+
" 20 19-[30m[43mThe_Monks_Tale[0m.txt",
|
41
|
+
" 24 23-[30m[43mThe_Manciples_Tale[0m.txt",
|
42
|
+
]
|
43
|
+
run_app_test expected, [ '--file-color', 'yellow', 'The.?M.*Tale' ], *files
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_highlight_multi
|
47
|
+
fname = '/proj/org/incava/glark/test/resources/04-TheCooksTale.txt'
|
48
|
+
expected = [
|
49
|
+
" 1 Of many a p[30m[43mi[0mlgr[30m[43mi[0mm hast thou Chr[30m[43mi[0mste's curse,",
|
50
|
+
" 2 For of [30m[45mthy[0m parsley yet fare [30m[42mthe[0my [30m[42mthe[0m worse.",
|
51
|
+
" 3 ",
|
52
|
+
" 4 That [30m[42mthe[0my have eaten [30m[43mi[0mn [30m[45mthy[0m stubble goose:",
|
53
|
+
" 5 For [30m[43mi[0mn [30m[45mthy[0m shop doth many a fly go loose.",
|
54
|
+
" 6 ",
|
55
|
+
" 7 Now tell on, gentle Roger, by [30m[45mthy[0m name,",
|
56
|
+
" 8 But yet I pray [30m[42mthe[0me be not wroth for game;",
|
57
|
+
" 9 A man may say full sooth [30m[43mi[0mn game and play.",
|
58
|
+
]
|
59
|
+
run_app_test expected, [ '--and=3', 'i', '--or', 'the', 'thy' ], fname
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_highlight_single
|
63
|
+
fname = '/proj/org/incava/glark/test/resources/04-TheCooksTale.txt'
|
64
|
+
expected = [
|
65
|
+
" 1 Of many a p[30m[43mi[0mlgr[30m[43mi[0mm hast thou Chr[30m[43mi[0mste's curse,",
|
66
|
+
" 2 For of [30m[43mthy[0m parsley yet fare [30m[43mthe[0my [30m[43mthe[0m worse.",
|
67
|
+
" 3 ",
|
68
|
+
" 4 That [30m[43mthe[0my have eaten [30m[43mi[0mn [30m[43mthy[0m stubble goose:",
|
69
|
+
" 5 For [30m[43mi[0mn [30m[43mthy[0m shop doth many a fly go loose.",
|
70
|
+
" 6 ",
|
71
|
+
" 7 Now tell on, gentle Roger, by [30m[43mthy[0m name,",
|
72
|
+
" 8 But yet I pray [30m[43mthe[0me be not wroth for game;",
|
73
|
+
" 9 A man may say full sooth [30m[43mi[0mn game and play.",
|
74
|
+
]
|
75
|
+
run_app_test expected, [ '--highlight=single', '--and=3', 'i', '--or', 'the', 'thy' ], fname
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# -*- ruby -*-
|
3
|
+
|
4
|
+
require 'glark/app/tc'
|
5
|
+
|
6
|
+
module Glark
|
7
|
+
class IgnoreCaseTestCase < AppTestCase
|
8
|
+
def test_simple
|
9
|
+
fname = '/proj/org/incava/glark/test/resources/spaces.txt'
|
10
|
+
expected = [
|
11
|
+
" 6 05 [30m[43mThe Man[0m Of Laws Tale.txt",
|
12
|
+
" 9 08 [30m[43mThe Sompn[0mours Tale.txt",
|
13
|
+
" 11 10 [30m[43mThe Merchan[0mts Tale.txt",
|
14
|
+
" 16 15 [30m[43mThe Shipman[0ms Tale.txt",
|
15
|
+
" 20 19 [30m[43mThe Mon[0mks Tale.txt",
|
16
|
+
" 23 22 [30m[43mThe Canons Yeoman[0ms Tale.txt",
|
17
|
+
" 24 23 [30m[43mThe Man[0mciples Tale.txt",
|
18
|
+
]
|
19
|
+
run_app_test expected, [ '-i', 'the.*m.*n' ], fname
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# -*- ruby -*-
|
3
|
+
|
4
|
+
require 'glark/app/tc'
|
5
|
+
|
6
|
+
module Glark
|
7
|
+
class InvertTestCase < AppTestCase
|
8
|
+
def test_simple
|
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-TheKnightsTale.txt",
|
12
|
+
" 4 -rw-r--r-- 1 jpace jpace 29296 2010-12-04 15:24 03-TheReevesTale.txt",
|
13
|
+
" 7 -rw-r--r-- 1 jpace jpace 71054 2010-12-04 15:24 06-TheWifeOfBathsTale.txt",
|
14
|
+
" 8 -rw-r--r-- 1 jpace jpace 22754 2010-12-04 15:24 07-TheFriarsTale.txt",
|
15
|
+
" 9 -rw-r--r-- 1 jpace jpace 35994 2010-12-04 15:24 08-TheSompnoursTale.txt",
|
16
|
+
" 12 -rw-r--r-- 1 jpace jpace 42282 2010-12-04 15:24 11-TheSquiresTale.txt",
|
17
|
+
" 13 -rw-r--r-- 1 jpace jpace 51996 2010-12-04 15:24 12-TheFranklinsTale.txt",
|
18
|
+
" 14 -rw-r--r-- 1 jpace jpace 15615 2010-12-04 15:24 13-TheDoctorsTale.txt",
|
19
|
+
" 16 -rw-r--r-- 1 jpace jpace 25163 2010-12-04 15:24 15-TheShipmansTale.txt",
|
20
|
+
" 18 -rw-r--r-- 1 jpace jpace 14834 2010-12-04 15:24 17-ChaucersTaleOfSirThopas.txt",
|
21
|
+
" 19 -rw-r--r-- 1 jpace jpace 43249 2010-12-04 15:24 18-ChaucersTaleOfMeliboeus.txt",
|
22
|
+
" 22 -rw-r--r-- 1 jpace jpace 30734 2010-12-04 15:24 21-TheSecondNunsTale.txt",
|
23
|
+
" 26 -rw-r--r-- 1 jpace jpace 3650 2010-12-04 15:24 25-PrecesDeChauceres.txt",
|
24
|
+
]
|
25
|
+
run_app_test expected, %w{ --invert-match The.*[MCP] }, fname
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_compound_expression
|
29
|
+
fname = '/proj/org/incava/glark/test/resources/textfile.txt'
|
30
|
+
expected = [
|
31
|
+
" 1 -rw-r--r-- 1 jpace jpace [30m[43m52183[0m 2010-12-04 15:24 00-ThePrologue.txt",
|
32
|
+
" 2 -rw-r--r-- 1 jpace jpace 126084 2010-12-04 15:24 01-TheKnightsTale.txt",
|
33
|
+
" 3 -rw-r--r-- 1 jpace jpace 45450 2010-12-04 15:24 02-TheMillersTale.txt",
|
34
|
+
" 4 -rw-r--r-- 1 jpace jpace 29296 2010-12-04 15:24 03-TheReevesTale.txt",
|
35
|
+
" 5 -rw-r--r-- 1 jpace jpace 6525 2010-12-04 15:24 04-TheCooksTale.txt",
|
36
|
+
" 6 -rw-r--r-- 1 jpace jpace 63290 2010-12-04 15:24 05-TheManOfLawsTale.txt",
|
37
|
+
" 7 -rw-r--r-- 1 jpace jpace 71054 2010-12-04 15:24 06-TheWifeOfBathsTale.txt",
|
38
|
+
" 8 -rw-r--r-- 1 jpace jpace 22754 2010-12-04 15:24 07-TheFriarsTale.txt",
|
39
|
+
" 17 -rw-r--r-- 1 jpace jpace 14979 2010-12-04 15:24 16-ThePrioresssTale.txt",
|
40
|
+
" 18 -rw-r--r-- 1 jpace jpace 14834 2010-12-04 15:24 17-ChaucersTaleOfSirThopas.txt",
|
41
|
+
" 19 -rw-r--r-- 1 jpace jpace 43249 2010-12-04 15:24 18-ChaucersTaleOfMeliboeus.txt",
|
42
|
+
" 20 -rw-r--r-- 1 jpace jpace 49747 2010-12-04 15:24 19-TheMonksTale.txt",
|
43
|
+
" 21 -rw-r--r-- 1 jpace jpace 45326 2010-12-04 15:24 20-TheNunsPriestsTale.txt",
|
44
|
+
" 26 -rw-r--r-- 1 jpace jpace 3650 2010-12-04 15:24 25-PrecesDeChauceres.txt",
|
45
|
+
]
|
46
|
+
run_app_test expected, [ '--invert-match', '--and=6', '\b5\d{4}\b', 'TheS.*Tale' ], fname
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# -*- ruby -*-
|
3
|
+
|
4
|
+
require 'glark/app/tc'
|
5
|
+
|
6
|
+
module Glark
|
7
|
+
class InclusiveOrTestCase < AppTestCase
|
8
|
+
def test_simple
|
9
|
+
fname = '/proj/org/incava/glark/test/resources/textfile.txt'
|
10
|
+
expected = [
|
11
|
+
" 3 -rw-r--r-- 1 jpace jpace 45450 2010-12-04 15:24 02-[30m[42mTheMillersTale[0m.txt",
|
12
|
+
" 6 -rw-r--r-- 1 jpace jpace [30m[43m63290[0m 2010-12-04 15:24 05-[30m[42mTheManOfLawsTale[0m.txt",
|
13
|
+
" 10 -rw-r--r-- 1 jpace jpace [30m[43m64791[0m 2010-12-04 15:24 09-TheClerksTale.txt",
|
14
|
+
" 11 -rw-r--r-- 1 jpace jpace [30m[43m65852[0m 2010-12-04 15:24 10-[30m[42mTheMerchantsTale[0m.txt",
|
15
|
+
" 20 -rw-r--r-- 1 jpace jpace 49747 2010-12-04 15:24 19-[30m[42mTheMonksTale[0m.txt",
|
16
|
+
" 24 -rw-r--r-- 1 jpace jpace 21141 2010-12-04 15:24 23-[30m[42mTheManciplesTale[0m.txt",
|
17
|
+
]
|
18
|
+
run_app_test expected, [ '--or', '\b6\d{4}\b', 'TheM.*Tale' ], fname
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# -*- ruby -*-
|
3
|
+
|
4
|
+
require 'glark/app/tc'
|
5
|
+
|
6
|
+
module Glark
|
7
|
+
class LabelTestCase < AppTestCase
|
8
|
+
def test_one_file
|
9
|
+
fname = '/proj/org/incava/glark/test/resources/textfile.txt'
|
10
|
+
expected = [
|
11
|
+
"[1mTheFileName[0m",
|
12
|
+
" 14 -rw-r--r-- 1 jpace jpace 15615 2010-12-04 15:24 13-[30m[43mTheDoc[0mtorsTale.txt"
|
13
|
+
]
|
14
|
+
run_app_test expected, %w{ --label TheFileName TheDoc }, fname
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_two_files
|
18
|
+
fnames = [ '/proj/org/incava/glark/test/resources/textfile.txt', '/proj/org/incava/glark/test/resources/spaces.txt' ]
|
19
|
+
expected = [
|
20
|
+
"[1mTheFileName[0m",
|
21
|
+
" 14 -rw-r--r-- 1 jpace jpace 15615 2010-12-04 15:24 13-[30m[43mTheDoc[0mtorsTale.txt",
|
22
|
+
"[1mTheFileName[0m",
|
23
|
+
" 14 13 [30m[43mThe Doc[0mtors Tale.txt",
|
24
|
+
]
|
25
|
+
run_app_test expected, %w{ --label TheFileName The.*Doc }, *fnames
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# -*- ruby -*-
|
3
|
+
|
4
|
+
require 'glark/app/tc'
|
5
|
+
|
6
|
+
module Glark
|
7
|
+
class LineNumberColorTestCase < AppTestCase
|
8
|
+
def test_none
|
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-[30m[43mTheSompnoursTale[0m.txt",
|
12
|
+
" 12 -rw-r--r-- 1 jpace jpace 42282 2010-12-04 15:24 11-[30m[43mTheSquiresTale[0m.txt",
|
13
|
+
" 16 -rw-r--r-- 1 jpace jpace 25163 2010-12-04 15:24 15-[30m[43mTheShipmansTale[0m.txt",
|
14
|
+
" 22 -rw-r--r-- 1 jpace jpace 30734 2010-12-04 15:24 21-[30m[43mTheSecondNunsTale[0m.txt",
|
15
|
+
]
|
16
|
+
run_app_test expected, [ 'TheS.*Tale' ], fname
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_single
|
20
|
+
fname = '/proj/org/incava/glark/test/resources/textfile.txt'
|
21
|
+
expected = [
|
22
|
+
" [1m9[0m -rw-r--r-- 1 jpace jpace 35994 2010-12-04 15:24 08-[30m[43mTheSompnoursTale[0m.txt",
|
23
|
+
" [1m12[0m -rw-r--r-- 1 jpace jpace 42282 2010-12-04 15:24 11-[30m[43mTheSquiresTale[0m.txt",
|
24
|
+
" [1m16[0m -rw-r--r-- 1 jpace jpace 25163 2010-12-04 15:24 15-[30m[43mTheShipmansTale[0m.txt",
|
25
|
+
" [1m22[0m -rw-r--r-- 1 jpace jpace 30734 2010-12-04 15:24 21-[30m[43mTheSecondNunsTale[0m.txt",
|
26
|
+
]
|
27
|
+
run_app_test expected, [ '--line-number-color', 'bold', 'TheS.*Tale' ], fname
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_multi
|
31
|
+
fname = '/proj/org/incava/glark/test/resources/textfile.txt'
|
32
|
+
expected = [
|
33
|
+
# go Purdue!
|
34
|
+
" [1m[33m[40m9[0m -rw-r--r-- 1 jpace jpace 35994 2010-12-04 15:24 08-[30m[43mTheSompnoursTale[0m.txt",
|
35
|
+
" [1m[33m[40m12[0m -rw-r--r-- 1 jpace jpace 42282 2010-12-04 15:24 11-[30m[43mTheSquiresTale[0m.txt",
|
36
|
+
" [1m[33m[40m16[0m -rw-r--r-- 1 jpace jpace 25163 2010-12-04 15:24 15-[30m[43mTheShipmansTale[0m.txt",
|
37
|
+
" [1m[33m[40m22[0m -rw-r--r-- 1 jpace jpace 30734 2010-12-04 15:24 21-[30m[43mTheSecondNunsTale[0m.txt",
|
38
|
+
]
|
39
|
+
run_app_test expected, [ '--line-number-color', 'bold yellow on black', 'TheS.*Tale' ], fname
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# -*- ruby -*-
|
3
|
+
|
4
|
+
require 'glark/app/tc'
|
5
|
+
|
6
|
+
module Glark
|
7
|
+
class LineNumbersTestCase < AppTestCase
|
8
|
+
def test_glark
|
9
|
+
fname = '/proj/org/incava/glark/test/resources/textfile.txt'
|
10
|
+
expected = [
|
11
|
+
" -rw-r--r-- 1 jpace jpace 35994 2010-12-04 15:24 08-[30m[43mTheSompnoursTale[0m.txt",
|
12
|
+
" -rw-r--r-- 1 jpace jpace 42282 2010-12-04 15:24 11-[30m[43mTheSquiresTale[0m.txt",
|
13
|
+
" -rw-r--r-- 1 jpace jpace 25163 2010-12-04 15:24 15-[30m[43mTheShipmansTale[0m.txt",
|
14
|
+
" -rw-r--r-- 1 jpace jpace 30734 2010-12-04 15:24 21-[30m[43mTheSecondNunsTale[0m.txt",
|
15
|
+
]
|
16
|
+
run_app_test expected, [ '-N', 'TheS\w+Tale' ], fname
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_grep_without_numbers
|
20
|
+
fname = '/proj/org/incava/glark/test/resources/textfile.txt'
|
21
|
+
expected = [
|
22
|
+
" -rw-r--r-- 1 jpace jpace 35994 2010-12-04 15:24 08-TheSompnoursTale.txt",
|
23
|
+
" -rw-r--r-- 1 jpace jpace 42282 2010-12-04 15:24 11-TheSquiresTale.txt",
|
24
|
+
" -rw-r--r-- 1 jpace jpace 25163 2010-12-04 15:24 15-TheShipmansTale.txt",
|
25
|
+
" -rw-r--r-- 1 jpace jpace 30734 2010-12-04 15:24 21-TheSecondNunsTale.txt",
|
26
|
+
]
|
27
|
+
run_app_test expected, [ '-g', 'TheS\w+Tale' ], fname
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_grep_with_numbers
|
31
|
+
# grep defaults to no numbers
|
32
|
+
fname = '/proj/org/incava/glark/test/resources/textfile.txt'
|
33
|
+
expected = [
|
34
|
+
"9: -rw-r--r-- 1 jpace jpace 35994 2010-12-04 15:24 08-TheSompnoursTale.txt",
|
35
|
+
"12: -rw-r--r-- 1 jpace jpace 42282 2010-12-04 15:24 11-TheSquiresTale.txt",
|
36
|
+
"16: -rw-r--r-- 1 jpace jpace 25163 2010-12-04 15:24 15-TheShipmansTale.txt",
|
37
|
+
"22: -rw-r--r-- 1 jpace jpace 30734 2010-12-04 15:24 21-TheSecondNunsTale.txt",
|
38
|
+
]
|
39
|
+
run_app_test expected, [ '-g', '-n', 'TheS.*Tale' ], fname
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# -*- ruby -*-
|
3
|
+
|
4
|
+
require 'glark/app/tc'
|
5
|
+
|
6
|
+
module Glark
|
7
|
+
class MatchLimitTestCase < AppTestCase
|
8
|
+
def test_one_file_limit_one
|
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-[30m[43mTheSompnoursTale[0m.txt",
|
12
|
+
]
|
13
|
+
run_app_test expected, [ '-m', '1', 'TheS\w+Tale' ], fname
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_one_file_limit_two
|
17
|
+
fname = '/proj/org/incava/glark/test/resources/textfile.txt'
|
18
|
+
expected = [
|
19
|
+
" 9 -rw-r--r-- 1 jpace jpace 35994 2010-12-04 15:24 08-[30m[43mTheSompnoursTale[0m.txt",
|
20
|
+
" 12 -rw-r--r-- 1 jpace jpace 42282 2010-12-04 15:24 11-[30m[43mTheSquiresTale[0m.txt",
|
21
|
+
]
|
22
|
+
run_app_test expected, [ '-m', '2', 'TheS\w+Tale' ], fname
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_two_files_limit_one
|
26
|
+
fnames = [ '/proj/org/incava/glark/test/resources/textfile.txt', '/proj/org/incava/glark/test/resources/spaces.txt' ]
|
27
|
+
expected = [
|
28
|
+
"[1m/proj/org/incava/glark/test/resources/textfile.txt[0m",
|
29
|
+
" 9 -rw-r--r-- 1 jpace jpace 35994 2010-12-04 15:24 08-[30m[43mTheSompnoursTale[0m.txt",
|
30
|
+
"[1m/proj/org/incava/glark/test/resources/spaces.txt[0m",
|
31
|
+
" 9 08 [30m[43mThe Sompnours Tale[0m.txt",
|
32
|
+
]
|
33
|
+
run_app_test expected, [ '-m', '1', 'The.?S.*Tale' ], *fnames
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_two_files_limit_two
|
37
|
+
fnames = [ '/proj/org/incava/glark/test/resources/textfile.txt', '/proj/org/incava/glark/test/resources/spaces.txt' ]
|
38
|
+
expected = [
|
39
|
+
"[1m/proj/org/incava/glark/test/resources/textfile.txt[0m",
|
40
|
+
" 9 -rw-r--r-- 1 jpace jpace 35994 2010-12-04 15:24 08-[30m[43mTheSompnoursTale[0m.txt",
|
41
|
+
" 12 -rw-r--r-- 1 jpace jpace 42282 2010-12-04 15:24 11-[30m[43mTheSquiresTale[0m.txt",
|
42
|
+
"[1m/proj/org/incava/glark/test/resources/spaces.txt[0m",
|
43
|
+
" 9 08 [30m[43mThe Sompnours Tale[0m.txt",
|
44
|
+
" 12 11 [30m[43mThe Squires Tale[0m.txt",
|
45
|
+
]
|
46
|
+
run_app_test expected, [ '-m', '2', 'The.?S.*Tale' ], *fnames
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,722 @@
|
|
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
|
+
require 'glark/util/highlight'
|
9
|
+
|
10
|
+
module Glark
|
11
|
+
class OptionsTestCase < AppTestCase
|
12
|
+
@@hl = HlWrapper.new
|
13
|
+
|
14
|
+
def str_to_color_codes str
|
15
|
+
@@hl.make_color str
|
16
|
+
end
|
17
|
+
|
18
|
+
def assert_method_values opts, exp, args
|
19
|
+
return unless exp
|
20
|
+
exp.each do |name, expval|
|
21
|
+
if name.to_s == 'text_colors'
|
22
|
+
assert_color opts, name, expval, args
|
23
|
+
else
|
24
|
+
val = opts.method(name).call
|
25
|
+
assert_equal expval, val, "args: #{args}"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def assert_color opts, name, expval, args
|
31
|
+
val = opts.method(name).call
|
32
|
+
### puts "val: #{val}"
|
33
|
+
### puts "expval: #{expval}"
|
34
|
+
###$$$ assert_equal expval, val, "args: #{args}"
|
35
|
+
end
|
36
|
+
|
37
|
+
def assert_colors opts, exp, args
|
38
|
+
return unless exp
|
39
|
+
exp.each do |name, expval|
|
40
|
+
### puts "name: #{name}"
|
41
|
+
val = opts.method(name).call
|
42
|
+
### puts "val: #{val}"
|
43
|
+
### puts "expval: #{expval}"
|
44
|
+
###$$$ assert_equal expval, val, "args: #{args}"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def run_test args, expected = Hash.new, &blk
|
49
|
+
gopt = Glark::AppOptions.new
|
50
|
+
gopt.run args + Array.new
|
51
|
+
outputopts = gopt.output_options
|
52
|
+
|
53
|
+
assert_method_values gopt, expected[:app], args
|
54
|
+
assert_method_values gopt.match_spec, expected[:match], args
|
55
|
+
# assert_method_values gopt.colors, expected[:colors], args
|
56
|
+
assert_colors gopt.colors, expected[:colors], args
|
57
|
+
assert_method_values gopt.output_options, expected[:output], args
|
58
|
+
assert_method_values gopt.info_options, expected[:info], args
|
59
|
+
assert_method_values gopt.input_spec, expected[:input], args
|
60
|
+
|
61
|
+
blk.call(gopt) if blk
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_default_values
|
65
|
+
run_test(%w{ foo file1 file2 },
|
66
|
+
:match => { :expr => RegexpExpression.new(%r{foo}, 0) })
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_extract_match
|
70
|
+
run_test(%w{ --extract-matches foo file1 file2 },
|
71
|
+
:match => { :extract_matches => true })
|
72
|
+
end
|
73
|
+
|
74
|
+
def test_extract_match_incomplete
|
75
|
+
str = '--extract-matches'
|
76
|
+
(5 ... str.length - 1).each do |idx|
|
77
|
+
tag = str[0 .. idx]
|
78
|
+
run_test([ tag ] + %w{ foo file1 file2 },
|
79
|
+
:match => { :extract_matches => true })
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
def test_record_separator
|
84
|
+
%w{ -0 -00 -000 }.each do |arg|
|
85
|
+
$/ = "\n"
|
86
|
+
run_test([ arg ] + %w{ foo file1 file2 }) do |gopt|
|
87
|
+
assert_equal "\n\n", $/
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
def test_short_options
|
93
|
+
[
|
94
|
+
%w{ -rli },
|
95
|
+
%w{ -rl -i },
|
96
|
+
%w{ -r -li },
|
97
|
+
%w{ -r -l -i },
|
98
|
+
].each do |args|
|
99
|
+
run_test(args + %w{ foo },
|
100
|
+
:match => { :ignorecase => true, :expr => RegexpExpression.new(%r{foo}i, 0) },
|
101
|
+
:output => { :file_names_only => true },
|
102
|
+
:input => { :max_depth => nil }) do |opts|
|
103
|
+
dircrit = opts.input_spec.dir_criteria
|
104
|
+
assert_equal false, dircrit.skip_all
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
def test_context_default
|
110
|
+
%w{ -C --context }.each do |ctx|
|
111
|
+
args = [ ctx, 'foo' ]
|
112
|
+
run_test(args) do |opts|
|
113
|
+
assert_context 2, 2, opts
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
def assert_context expbefore, expafter, opts
|
119
|
+
context = opts.output_options.context
|
120
|
+
if expafter
|
121
|
+
assert_equal expafter, context.after
|
122
|
+
end
|
123
|
+
if expbefore
|
124
|
+
assert_equal expbefore, context.before
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
def test_context_specified
|
129
|
+
[ 3, 1, 666 ].each do |val|
|
130
|
+
vstr = val.to_s
|
131
|
+
[
|
132
|
+
[ '-C', vstr ],
|
133
|
+
[ '--context', vstr ],
|
134
|
+
[ '--context=' + vstr, ]
|
135
|
+
].each do |args|
|
136
|
+
run_test(args + %w{ foo }) do |opts|
|
137
|
+
assert_context val, val, opts
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
vals = (1 .. 10).to_a | (1 .. 16).collect { |x| 2 ** x }
|
143
|
+
vals.each do |val|
|
144
|
+
args = [ '-' + val.to_s, 'foo' ]
|
145
|
+
run_test(args) do |opts|
|
146
|
+
assert_context val, val, opts
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
def test_after_context
|
152
|
+
[ 3, 1, 666 ].each do |val|
|
153
|
+
vstr = val.to_s
|
154
|
+
[
|
155
|
+
[ '-A', vstr ],
|
156
|
+
[ '--after-context', vstr ],
|
157
|
+
[ '--after-context=' + vstr ]
|
158
|
+
].each do |args|
|
159
|
+
run_test(args + %w{ foo }) do |opts|
|
160
|
+
assert_context nil, val, opts
|
161
|
+
end
|
162
|
+
end
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
def test_before_context
|
167
|
+
[ 3, 1, 666 ].each do |val|
|
168
|
+
vstr = val.to_s
|
169
|
+
[
|
170
|
+
[ '-B', vstr ],
|
171
|
+
[ '--before-context', vstr ],
|
172
|
+
[ '--before-context=' + vstr ]
|
173
|
+
].each do |args|
|
174
|
+
run_test(args + %w{ foo }) do |opts|
|
175
|
+
assert_context val, nil, opts
|
176
|
+
end
|
177
|
+
end
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
def test_highlight
|
182
|
+
%w{ -u --highlight }.each do |hlopt|
|
183
|
+
run_test([ hlopt, 'foo' ],
|
184
|
+
:color => { :text_color_style => "multi" })
|
185
|
+
end
|
186
|
+
|
187
|
+
%w{ multi }.each do |val|
|
188
|
+
[
|
189
|
+
[ '--highlight=' + val ],
|
190
|
+
[ '--highlight', val ],
|
191
|
+
].each do |opt|
|
192
|
+
run_test(opt + [ 'foo' ],
|
193
|
+
:color => { :text_color_style => val })
|
194
|
+
end
|
195
|
+
end
|
196
|
+
|
197
|
+
singlecolor = str_to_color_codes(Text::Highlighter::DEFAULT_COLORS[0])
|
198
|
+
|
199
|
+
%w{ single }.each do |val|
|
200
|
+
[
|
201
|
+
[ '--highlight=' + val ],
|
202
|
+
[ '--highlight', val ],
|
203
|
+
].each do |opt|
|
204
|
+
run_test(opt + [ 'foo' ],
|
205
|
+
:match => { :text_colors => [ singlecolor ] },
|
206
|
+
:color => { :text_color_style => val })
|
207
|
+
end
|
208
|
+
end
|
209
|
+
|
210
|
+
%w{ none }.each do |val|
|
211
|
+
run_test([ '--highlight=' + val, 'foo' ],
|
212
|
+
:match => { :text_colors => [] },
|
213
|
+
:color => { :text_color_style => nil })
|
214
|
+
end
|
215
|
+
end
|
216
|
+
|
217
|
+
def test_no_highlight
|
218
|
+
%w{ -U --no-highlight }.each do |hlopt|
|
219
|
+
run_test([ hlopt, 'foo' ],
|
220
|
+
:match => { :text_colors => [] },
|
221
|
+
:color => { :text_color_style => nil })
|
222
|
+
end
|
223
|
+
end
|
224
|
+
|
225
|
+
def test_verbose
|
226
|
+
if origverb = Log.verbose
|
227
|
+
%w{ --verbose }.each do |vtag|
|
228
|
+
[ nil, 1, 2, 3, 4 ].each do |num|
|
229
|
+
vopt = vtag
|
230
|
+
if num
|
231
|
+
vopt += "=" + num.to_s
|
232
|
+
end
|
233
|
+
Log.verbose = nil
|
234
|
+
run_test([ vopt, 'foo' ]) do |opts|
|
235
|
+
assert_equal true, Log.verbose, "log verbosity"
|
236
|
+
end
|
237
|
+
end
|
238
|
+
end
|
239
|
+
|
240
|
+
Log.verbose = origverb
|
241
|
+
end
|
242
|
+
end
|
243
|
+
|
244
|
+
def test_invert_match
|
245
|
+
%w{ -v --invert-match }.each do |vopt|
|
246
|
+
run_test([ vopt, 'foo' ], :output => { :invert_match => true })
|
247
|
+
end
|
248
|
+
end
|
249
|
+
|
250
|
+
def test_ignore_case
|
251
|
+
%w{ -i --ignore-case }.each do |opt|
|
252
|
+
run_test([ opt, 'foo' ],
|
253
|
+
:match => {
|
254
|
+
:expr => RegexpExpression.new(%r{foo}i, 0),
|
255
|
+
:ignorecase => true
|
256
|
+
})
|
257
|
+
end
|
258
|
+
end
|
259
|
+
|
260
|
+
def test_filter
|
261
|
+
%w{ --filter }.each do |opt|
|
262
|
+
run_test([ opt, 'foo' ],
|
263
|
+
:output => { :filter => true })
|
264
|
+
end
|
265
|
+
end
|
266
|
+
|
267
|
+
def test_no_filter
|
268
|
+
%w{ --no-filter --nofilter }.each do |opt|
|
269
|
+
run_test([ opt, 'foo' ],
|
270
|
+
:output => { :filter => false })
|
271
|
+
end
|
272
|
+
end
|
273
|
+
|
274
|
+
def test_output_type
|
275
|
+
%w{ -g --grep }.each do |opt|
|
276
|
+
run_test([ opt, 'foo' ],
|
277
|
+
:match => { :text_colors => [] },
|
278
|
+
:output => { :show_line_numbers => false, :style => "grep" },
|
279
|
+
:colors => { :text_color_style => false }) do |opts|
|
280
|
+
assert_context 0, 0, opts
|
281
|
+
end
|
282
|
+
end
|
283
|
+
end
|
284
|
+
|
285
|
+
def test_line_number
|
286
|
+
%w{ -n --line-number }.each do |opt|
|
287
|
+
run_test([ opt, 'foo' ],
|
288
|
+
:output => { :show_line_numbers => true })
|
289
|
+
end
|
290
|
+
end
|
291
|
+
|
292
|
+
def test_no_line_number
|
293
|
+
%w{ -N --no-line-number }.each do |opt|
|
294
|
+
run_test([ opt, 'foo' ],
|
295
|
+
:output => { :show_line_numbers => false })
|
296
|
+
end
|
297
|
+
end
|
298
|
+
|
299
|
+
def test_no_line_number_no_file_name
|
300
|
+
[ %w{ -N -h }, '-hN', '-Nh' ].each do |opt|
|
301
|
+
run_test([ opt, 'foo' ].flatten,
|
302
|
+
:output => { :show_line_numbers => false, :show_file_names => false })
|
303
|
+
end
|
304
|
+
end
|
305
|
+
|
306
|
+
def test_explain
|
307
|
+
%w{ --explain }.each do |opt|
|
308
|
+
run_test([ opt, 'foo' ],
|
309
|
+
:info => { :explain => true })
|
310
|
+
end
|
311
|
+
end
|
312
|
+
|
313
|
+
def test_quiet
|
314
|
+
%w{ -q -s --quiet --messages }.each do |opt|
|
315
|
+
run_test([ opt, 'foo' ]) do |opts|
|
316
|
+
assert Log.quiet
|
317
|
+
end
|
318
|
+
end
|
319
|
+
end
|
320
|
+
|
321
|
+
def test_no_quiet
|
322
|
+
%w{ -Q -S --no-quiet --no-messages }.each do |opt|
|
323
|
+
run_test([ opt, 'foo' ]) do |opts|
|
324
|
+
assert !Log.quiet
|
325
|
+
end
|
326
|
+
end
|
327
|
+
end
|
328
|
+
|
329
|
+
def test_whole_words
|
330
|
+
%w{ -w --word }.each do |opt|
|
331
|
+
run_test([ opt, 'foo' ],
|
332
|
+
:match => {
|
333
|
+
:expr => RegexpExpression.new(%r{\bfoo\b}, 0),
|
334
|
+
:whole_words => true
|
335
|
+
})
|
336
|
+
end
|
337
|
+
end
|
338
|
+
|
339
|
+
def test_whole_lines
|
340
|
+
%w{ -x --line-regexp }.each do |opt|
|
341
|
+
run_test([ opt, 'foo' ],
|
342
|
+
:match => {
|
343
|
+
:expr => RegexpExpression.new(%r{^foo$}, 0),
|
344
|
+
:whole_lines => true
|
345
|
+
})
|
346
|
+
end
|
347
|
+
end
|
348
|
+
|
349
|
+
def test_files_with_matches
|
350
|
+
%w{ -l --files-with-matches }.each do |opt|
|
351
|
+
run_test([ opt, 'foo' ],
|
352
|
+
:output => { :invert_match => false, :file_names_only => true })
|
353
|
+
end
|
354
|
+
end
|
355
|
+
|
356
|
+
def test_files_without_matches
|
357
|
+
%w{ -L --files-without-match }.each do |opt|
|
358
|
+
run_test([ opt, 'foo' ],
|
359
|
+
:output => { :invert_match => true, :file_names_only => true })
|
360
|
+
end
|
361
|
+
end
|
362
|
+
|
363
|
+
def test_count
|
364
|
+
%w{ -c --count }.each do |opt|
|
365
|
+
run_test([ opt, 'foo' ],
|
366
|
+
:output => { :count => true })
|
367
|
+
end
|
368
|
+
end
|
369
|
+
|
370
|
+
def test_write_null
|
371
|
+
%w{ -Z --null }.each do |opt|
|
372
|
+
run_test([ opt, 'foo' ],
|
373
|
+
:output => { :write_null => true })
|
374
|
+
end
|
375
|
+
end
|
376
|
+
|
377
|
+
def test_exclude_matching
|
378
|
+
%w{ -M --exclude-matching }.each do |opt|
|
379
|
+
run_test([ opt, 'foo' ],
|
380
|
+
:input => { :exclude_matching => true })
|
381
|
+
end
|
382
|
+
end
|
383
|
+
|
384
|
+
def run_directory_test expmaxdepth, expskipall, args
|
385
|
+
run_test(args, :input => { :max_depth => expmaxdepth }) do |opts|
|
386
|
+
dircrit = opts.input_spec.dir_criteria
|
387
|
+
assert_equal expskipall, dircrit.skip_all
|
388
|
+
end
|
389
|
+
end
|
390
|
+
|
391
|
+
def run_directory_d_test expmaxdepth, expskipall, arg
|
392
|
+
run_directory_test expmaxdepth, expskipall, [ '-d', arg, 'foo' ]
|
393
|
+
end
|
394
|
+
|
395
|
+
def test_directory_d_list
|
396
|
+
run_directory_d_test 0, false, 'list'
|
397
|
+
end
|
398
|
+
|
399
|
+
def test_directory_d_find
|
400
|
+
run_directory_d_test nil, false, 'find'
|
401
|
+
end
|
402
|
+
|
403
|
+
def test_directory_d_recurse
|
404
|
+
run_directory_d_test nil, false, 'recurse'
|
405
|
+
end
|
406
|
+
|
407
|
+
def test_directory_d_skip
|
408
|
+
run_directory_d_test nil, true, 'skip'
|
409
|
+
end
|
410
|
+
|
411
|
+
def test_recurse
|
412
|
+
%w{ -r --recurse }.each do |opt|
|
413
|
+
run_directory_test nil, false, [ opt, 'foo' ]
|
414
|
+
end
|
415
|
+
end
|
416
|
+
|
417
|
+
def test_extract_matches
|
418
|
+
%w{ -y --extract-matches }.each do |opt|
|
419
|
+
run_test([ opt, 'foo' ],
|
420
|
+
:match => { :extract_matches => true })
|
421
|
+
end
|
422
|
+
end
|
423
|
+
|
424
|
+
def test_no_split_as_path
|
425
|
+
%w{ --no-split-as-path }.each do |opt|
|
426
|
+
run_test([ opt, 'foo' ],
|
427
|
+
:input => { :split_as_path => false })
|
428
|
+
end
|
429
|
+
end
|
430
|
+
|
431
|
+
def test_split_as_path
|
432
|
+
%w{ --split-as-path }.each do |opt|
|
433
|
+
run_test([ opt, 'foo' ],
|
434
|
+
:input => { :split_as_path => true })
|
435
|
+
end
|
436
|
+
end
|
437
|
+
|
438
|
+
def run_directories_test expmaxdepth, expskipall, arg
|
439
|
+
[
|
440
|
+
[ '--directories=' + arg ],
|
441
|
+
[ '--directories', arg ]
|
442
|
+
].each do |args|
|
443
|
+
run_directory_test expmaxdepth, expskipall, args + %w{ foo }
|
444
|
+
end
|
445
|
+
end
|
446
|
+
|
447
|
+
def test_directory_list
|
448
|
+
run_directories_test 0, false, 'list'
|
449
|
+
end
|
450
|
+
|
451
|
+
def test_directory_find
|
452
|
+
run_directories_test nil, false, 'find'
|
453
|
+
end
|
454
|
+
|
455
|
+
def test_directory_recurse
|
456
|
+
run_directories_test nil, false, 'recurse'
|
457
|
+
end
|
458
|
+
|
459
|
+
def test_directory_skip
|
460
|
+
run_directories_test nil, true, 'skip'
|
461
|
+
end
|
462
|
+
|
463
|
+
def test_no_show_file_names
|
464
|
+
%w{ -h --no-filename }.each do |opt|
|
465
|
+
run_test([ opt, 'foo' ],
|
466
|
+
:output => { :show_file_names => false })
|
467
|
+
end
|
468
|
+
end
|
469
|
+
|
470
|
+
def test_show_file_names
|
471
|
+
%w{ -H --with-filename }.each do |opt|
|
472
|
+
run_test([ opt, 'foo' ],
|
473
|
+
:output => { :show_file_names => true })
|
474
|
+
end
|
475
|
+
end
|
476
|
+
|
477
|
+
def test_label
|
478
|
+
%w{ testing 123 any*char\/acters }.each do |label|
|
479
|
+
[
|
480
|
+
[ '--label=' + label ],
|
481
|
+
[ '--label', label ]
|
482
|
+
].each do |opt|
|
483
|
+
run_test(opt + %w{ foo },
|
484
|
+
:output => { :label => label })
|
485
|
+
end
|
486
|
+
end
|
487
|
+
end
|
488
|
+
|
489
|
+
def test_match_limit
|
490
|
+
%w{ 1 2 4 20 50 100 2000 30000 }.each do |num|
|
491
|
+
[
|
492
|
+
[ '-m', num ],
|
493
|
+
[ '--match-limit', num ],
|
494
|
+
[ '--match-limit=' + num ],
|
495
|
+
].each do |args|
|
496
|
+
run_test(args + %w{ foo },
|
497
|
+
:output => { :match_limit => num.to_i })
|
498
|
+
end
|
499
|
+
end
|
500
|
+
end
|
501
|
+
|
502
|
+
def test_with_basename
|
503
|
+
%w{ abc123 \w+\S* }.each do |pat|
|
504
|
+
%w{ --with-basename --basename --with-name --name --match-name }.each do |tag|
|
505
|
+
[
|
506
|
+
[ tag, pat ],
|
507
|
+
[ tag + '=' + pat ]
|
508
|
+
].each do |args|
|
509
|
+
run_test(args + %w{ foo }) do |opts|
|
510
|
+
assert_file_filter_pattern_eq pat, opts, :name, :positive, BaseNameFilter
|
511
|
+
end
|
512
|
+
end
|
513
|
+
end
|
514
|
+
end
|
515
|
+
end
|
516
|
+
|
517
|
+
def test_without_basename
|
518
|
+
%w{ abc123 \w+\S* }.each do |pat|
|
519
|
+
%w{ --without-basename --without-name --not-name }.each do |tag|
|
520
|
+
[
|
521
|
+
[ tag, pat ],
|
522
|
+
[ tag + '=' + pat ]
|
523
|
+
].each do |args|
|
524
|
+
run_test(args + %w{ foo }) do |opts|
|
525
|
+
assert_file_filter_pattern_eq pat, opts, :name, :negative, BaseNameFilter
|
526
|
+
end
|
527
|
+
end
|
528
|
+
end
|
529
|
+
end
|
530
|
+
end
|
531
|
+
|
532
|
+
def test_match_path
|
533
|
+
%w{ abc123 \w+\S* }.each do |pat|
|
534
|
+
%w{ --with-fullname --fullname --with-path --path --match-path }.each do |tag|
|
535
|
+
[
|
536
|
+
[ tag, pat ],
|
537
|
+
[ tag + '=' + pat ]
|
538
|
+
].each do |args|
|
539
|
+
run_test(args + %w{ foo }) do |opts|
|
540
|
+
assert_file_filter_pattern_eq pat, opts, :path, :positive, FullNameFilter
|
541
|
+
end
|
542
|
+
end
|
543
|
+
end
|
544
|
+
end
|
545
|
+
end
|
546
|
+
|
547
|
+
def test_nomatch_path
|
548
|
+
%w{ abc123 \w+\S* }.each do |pat|
|
549
|
+
%w{ --without-fullname --without-path --not-path }.each do |tag|
|
550
|
+
[
|
551
|
+
[ tag, pat ],
|
552
|
+
[ tag + '=' + pat ]
|
553
|
+
].each do |args|
|
554
|
+
run_test(args + %w{ foo }) do |opts|
|
555
|
+
assert_file_filter_pattern_eq pat, opts, :path, :negative, FullNameFilter
|
556
|
+
end
|
557
|
+
end
|
558
|
+
end
|
559
|
+
end
|
560
|
+
end
|
561
|
+
|
562
|
+
def run_range_test expfrom, expto, args
|
563
|
+
run_test(args + %w{ foo },
|
564
|
+
:input => { :range => Glark::Range.new(expfrom, expto) })
|
565
|
+
end
|
566
|
+
|
567
|
+
def test_range_start
|
568
|
+
%w{ 5 5% 10 90% }.each do |rg|
|
569
|
+
[
|
570
|
+
[ '--after=' + rg ],
|
571
|
+
[ '--after', rg ]
|
572
|
+
].each do |opt|
|
573
|
+
run_range_test rg, nil, opt
|
574
|
+
end
|
575
|
+
end
|
576
|
+
end
|
577
|
+
|
578
|
+
def test_range_end
|
579
|
+
%w{ 5 5% 10 90% }.each do |rg|
|
580
|
+
[
|
581
|
+
[ '--before=' + rg ],
|
582
|
+
[ '--before', rg ],
|
583
|
+
].each do |opt|
|
584
|
+
run_range_test nil, rg, opt
|
585
|
+
end
|
586
|
+
end
|
587
|
+
end
|
588
|
+
|
589
|
+
def test_range_both
|
590
|
+
[
|
591
|
+
%w{ 5 10 },
|
592
|
+
%w{ 7 10% },
|
593
|
+
%w{ 90% 95% },
|
594
|
+
%w{ 18 81 }
|
595
|
+
].each do |from, to|
|
596
|
+
[
|
597
|
+
[ '--range=' + from + ',' + to ],
|
598
|
+
[ '--range', from + ',' + to ],
|
599
|
+
].each do |opt|
|
600
|
+
run_range_test from, to, opt
|
601
|
+
end
|
602
|
+
end
|
603
|
+
end
|
604
|
+
|
605
|
+
def test_binary_files
|
606
|
+
%w{ binary without-match text }.each do |val|
|
607
|
+
[
|
608
|
+
[ '--binary-files="' + val + '"' ],
|
609
|
+
[ '--binary-files=' + val ],
|
610
|
+
[ '--binary-files', val ],
|
611
|
+
].each do |opt|
|
612
|
+
run_test(opt + %w{ foo },
|
613
|
+
:input => { :binary_files => val })
|
614
|
+
end
|
615
|
+
end
|
616
|
+
end
|
617
|
+
|
618
|
+
def test_size_limit
|
619
|
+
[ 0, 1, 10, 10000, 100000 ].each do |val|
|
620
|
+
[
|
621
|
+
[ '--size-limit=' + val.to_s ],
|
622
|
+
[ '--size-limit', val.to_s ],
|
623
|
+
].each do |opt|
|
624
|
+
run_test(opt + %w{ foo }) do |opts|
|
625
|
+
assert_file_filter_eq val, opts, :size, :negative, SizeLimitFilter, :max_size
|
626
|
+
end
|
627
|
+
end
|
628
|
+
end
|
629
|
+
end
|
630
|
+
|
631
|
+
def test_text_highlight
|
632
|
+
[ 'red', 'blue', 'cyan', 'bold blue', 'blue bold' ].each do |color|
|
633
|
+
[
|
634
|
+
[ '--text-color="' + color + '"' ],
|
635
|
+
[ '--text-color=' + color ],
|
636
|
+
].each do |opt|
|
637
|
+
run_test(opt + [ 'foo' ],
|
638
|
+
:match => { :text_colors => [ str_to_color_codes(color) ] })
|
639
|
+
end
|
640
|
+
end
|
641
|
+
end
|
642
|
+
|
643
|
+
def test_file_color
|
644
|
+
[ 'red', 'blue', 'cyan', 'bold blue', 'blue bold' ].each do |color|
|
645
|
+
[
|
646
|
+
[ '--file-color', color ],
|
647
|
+
[ '--file-color="' + color + '"' ],
|
648
|
+
[ '--file-color=' + color ],
|
649
|
+
].each do |opt|
|
650
|
+
run_test(opt + [ 'foo' ],
|
651
|
+
:colors => { :file_name_color => str_to_color_codes(color) })
|
652
|
+
end
|
653
|
+
end
|
654
|
+
end
|
655
|
+
|
656
|
+
def test_file_expression
|
657
|
+
res = %w{ foo bar baz \w\s+\d\S\W }
|
658
|
+
|
659
|
+
t = Tempfile.new "tc_options"
|
660
|
+
res.each do |re|
|
661
|
+
t.puts re
|
662
|
+
end
|
663
|
+
t.close
|
664
|
+
|
665
|
+
pt = Pathname.new t.path
|
666
|
+
|
667
|
+
orexpr = nil
|
668
|
+
res.each do |re|
|
669
|
+
refo = RegexpExpression.new Regexp.new(re), 0
|
670
|
+
if orexpr
|
671
|
+
orexpr.ops << refo
|
672
|
+
else
|
673
|
+
orexpr = InclusiveOrExpression.new refo
|
674
|
+
end
|
675
|
+
end
|
676
|
+
|
677
|
+
begin
|
678
|
+
[
|
679
|
+
[ '-f', t.path ],
|
680
|
+
[ '--file="' + t.path + '"' ],
|
681
|
+
[ '--file=' + t.path ],
|
682
|
+
[ '--file', t.path ],
|
683
|
+
].each do |opt|
|
684
|
+
run_test(opt, :match => { :expr => orexpr })
|
685
|
+
end
|
686
|
+
ensure
|
687
|
+
if pt.exist?
|
688
|
+
pt.delete
|
689
|
+
end
|
690
|
+
end
|
691
|
+
end
|
692
|
+
|
693
|
+
def test_or_expression
|
694
|
+
pats = %w{ foo bar }
|
695
|
+
|
696
|
+
re0, re1 = pats.collect { |pat| RegexpExpression.new(Regexp.new(pat), 0) }
|
697
|
+
|
698
|
+
orexpr = InclusiveOrExpression.new re0, re1
|
699
|
+
|
700
|
+
[
|
701
|
+
[ '-o', *pats ],
|
702
|
+
].each do |opt|
|
703
|
+
run_test(opt, :match => { :expr => orexpr })
|
704
|
+
end
|
705
|
+
end
|
706
|
+
|
707
|
+
def test_and_expression
|
708
|
+
pats = %w{ foo bar }
|
709
|
+
|
710
|
+
re0, re1 = pats.collect { |pat| RegexpExpression.new(Regexp.new(pat), 0) }
|
711
|
+
|
712
|
+
exp = AndExpression.new 0, re0, re1
|
713
|
+
|
714
|
+
[
|
715
|
+
[ '-a', 0, *pats ],
|
716
|
+
].each do |opt|
|
717
|
+
run_test(opt, :match => { :expr => exp })
|
718
|
+
end
|
719
|
+
end
|
720
|
+
end
|
721
|
+
end
|
722
|
+
|