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.
Files changed (128) hide show
  1. data/bin/glark +2 -2
  2. data/lib/glark.rb +1 -1
  3. data/lib/glark/app/app.rb +48 -0
  4. data/lib/glark/app/help.rb +103 -0
  5. data/lib/glark/app/info/options.rb +84 -0
  6. data/lib/glark/app/options.rb +201 -0
  7. data/lib/glark/app/rcfile.rb +49 -0
  8. data/lib/glark/app/runner.rb +140 -0
  9. data/lib/glark/app/spec.rb +19 -0
  10. data/lib/glark/input/filter/criteria_opts.rb +41 -0
  11. data/lib/glark/input/filter/dir_criteria_opts.rb +37 -0
  12. data/lib/glark/input/filter/file_criteria_opts.rb +33 -0
  13. data/lib/glark/input/filter/filter.rb +59 -0
  14. data/lib/glark/input/filter/options.rb +171 -0
  15. data/lib/glark/input/options.rb +120 -0
  16. data/lib/glark/input/range.rb +104 -0
  17. data/lib/glark/input/spec.rb +39 -0
  18. data/lib/glark/io/file/archive_file.rb +64 -0
  19. data/lib/glark/io/file/binary_file.rb +19 -0
  20. data/lib/glark/io/file/file.rb +57 -0
  21. data/lib/glark/io/file/gz_file.rb +21 -0
  22. data/lib/glark/io/file/tar_file.rb +35 -0
  23. data/lib/glark/io/file/tar_gz_file.rb +52 -0
  24. data/lib/glark/io/file/zip_file.rb +39 -0
  25. data/lib/glark/match/and.rb +83 -0
  26. data/lib/glark/match/and_distance.rb +58 -0
  27. data/lib/glark/match/compound.rb +34 -0
  28. data/lib/glark/match/expression.rb +63 -0
  29. data/lib/glark/match/factory.rb +173 -0
  30. data/lib/glark/match/ior.rb +20 -0
  31. data/lib/glark/match/options.rb +74 -0
  32. data/lib/glark/match/or.rb +41 -0
  33. data/lib/glark/match/re.rb +81 -0
  34. data/lib/glark/match/re_factory.rb +44 -0
  35. data/lib/glark/match/spec.rb +59 -0
  36. data/lib/glark/match/xor.rb +20 -0
  37. data/lib/glark/output/binary_file_summary.rb +17 -0
  38. data/lib/glark/output/common.rb +43 -0
  39. data/lib/glark/output/context.rb +57 -0
  40. data/lib/glark/output/count.rb +26 -0
  41. data/lib/glark/output/file_header.rb +20 -0
  42. data/lib/glark/output/file_name_only.rb +35 -0
  43. data/lib/glark/output/formatted.rb +22 -0
  44. data/lib/glark/output/glark_count.rb +23 -0
  45. data/lib/glark/output/glark_format.rb +62 -0
  46. data/lib/glark/output/glark_lines.rb +36 -0
  47. data/lib/glark/output/grep_count.rb +18 -0
  48. data/lib/glark/output/grep_lines.rb +42 -0
  49. data/lib/glark/output/line_status.rb +46 -0
  50. data/lib/glark/output/lines.rb +100 -0
  51. data/lib/glark/output/match_list.rb +15 -0
  52. data/lib/glark/output/options.rb +103 -0
  53. data/lib/glark/output/results.rb +23 -0
  54. data/lib/glark/output/spec.rb +105 -0
  55. data/lib/glark/output/unfiltered_lines.rb +28 -0
  56. data/lib/glark/util/colors/options.rb +143 -0
  57. data/lib/glark/util/colors/spec.rb +21 -0
  58. data/lib/glark/util/highlight.rb +108 -0
  59. data/lib/glark/util/io/depth.rb +29 -0
  60. data/lib/glark/util/io/fileset.rb +162 -0
  61. data/lib/glark/util/io/filter/criteria.rb +49 -0
  62. data/lib/glark/util/io/filter/filter.rb +10 -0
  63. data/lib/glark/util/io/lines.rb +117 -0
  64. data/lib/glark/util/option.rb +34 -0
  65. data/lib/glark/util/options.rb +12 -0
  66. data/lib/glark/util/optutil.rb +69 -0
  67. data/lib/glark/util/timestamper.rb +18 -0
  68. data/man/glark.1 +1134 -0
  69. data/test/glark/app/and_test.rb +82 -0
  70. data/test/glark/app/compound_test.rb +33 -0
  71. data/test/glark/app/context_test.rb +43 -0
  72. data/test/glark/app/count_test.rb +89 -0
  73. data/test/glark/app/dump_test.rb +16 -0
  74. data/test/glark/app/expression_file_test.rb +22 -0
  75. data/test/glark/app/extended_regexp_test.rb +17 -0
  76. data/test/glark/app/extract_matches_test.rb +27 -0
  77. data/test/glark/app/files_with_match_test.rb +32 -0
  78. data/test/glark/app/files_without_match_test.rb +26 -0
  79. data/test/glark/app/filter_test.rb +118 -0
  80. data/test/glark/app/highlight_test.rb +78 -0
  81. data/test/glark/app/ignore_case_test.rb +22 -0
  82. data/test/glark/app/invert_test.rb +49 -0
  83. data/test/glark/app/ior_test.rb +21 -0
  84. data/test/glark/app/label_test.rb +28 -0
  85. data/test/glark/app/line_number_color_test.rb +42 -0
  86. data/test/glark/app/line_numbers_test.rb +42 -0
  87. data/test/glark/app/match_limit_test.rb +49 -0
  88. data/test/glark/app/options_test.rb +722 -0
  89. data/test/glark/app/range_test.rb +101 -0
  90. data/test/glark/app/rcfile_test.rb +113 -0
  91. data/test/glark/app/record_separator_test.rb +32 -0
  92. data/test/glark/app/regexp_test.rb +48 -0
  93. data/test/glark/app/tc.rb +92 -0
  94. data/test/glark/app/text_color_test.rb +31 -0
  95. data/test/glark/app/whole_lines_test.rb +17 -0
  96. data/test/glark/app/whole_words_test.rb +42 -0
  97. data/test/glark/app/xor_test.rb +19 -0
  98. data/test/glark/input/binary_file_test.rb +0 -0
  99. data/test/glark/input/directory_test.rb +202 -0
  100. data/test/glark/input/dirname_test.rb +69 -0
  101. data/test/glark/input/exclude_matching_test.rb +20 -0
  102. data/test/glark/input/ext_test.rb +65 -0
  103. data/test/glark/input/filter/criteria_test.rb +91 -0
  104. data/test/glark/input/filter/filter_spec_test.rb +27 -0
  105. data/test/glark/input/filter/filter_test.rb +21 -0
  106. data/test/glark/input/name_test.rb +75 -0
  107. data/test/glark/input/path_test.rb +72 -0
  108. data/test/glark/input/range_test.rb +82 -0
  109. data/test/glark/input/size_limit_test.rb +51 -0
  110. data/test/glark/input/split_as_path_test.rb +28 -0
  111. data/test/glark/match_test.rb +192 -0
  112. data/test/glark/resources.rb +21 -0
  113. data/test/glark/tc.rb +37 -0
  114. data/test/resources/add.rb +10 -0
  115. data/test/resources/echo.rb +2 -0
  116. data/test/resources/greet.rb +13 -0
  117. metadata +198 -28
  118. data/README +0 -0
  119. data/bin/jlark +0 -63
  120. data/lib/glark/expression.rb +0 -440
  121. data/lib/glark/exprfactory.rb +0 -248
  122. data/lib/glark/glark.rb +0 -297
  123. data/lib/glark/help.rb +0 -85
  124. data/lib/glark/input.rb +0 -183
  125. data/lib/glark/options.rb +0 -757
  126. data/lib/glark/output.rb +0 -266
  127. data/test/lib/glark/glark_test.rb +0 -317
  128. 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-TheFriarsTale.txt",
12
+ " 9 -rw-r--r-- 1 jpace jpace 35994 2010-12-04 15:24 08-TheSompnoursTale.txt",
13
+ " 10 -rw-r--r-- 1 jpace jpace 64791 2010-12-04 15:24 09-TheClerksTale.txt",
14
+ " 11 -rw-r--r-- 1 jpace jpace 65852 2010-12-04 15:24 10-TheMerchantsTale.txt",
15
+ " 12 -rw-r--r-- 1 jpace jpace 42282 2010-12-04 15:24 11-TheSquiresTale.txt",
16
+ " 13 -rw-r--r-- 1 jpace jpace 51996 2010-12-04 15:24 12-TheFranklinsTale.txt",
17
+ " 14 -rw-r--r-- 1 jpace jpace 15615 2010-12-04 15:24 13-TheDoctorsTale.txt",
18
+ " 15 -rw-r--r-- 1 jpace jpace 39546 2010-12-04 15:24 14-ThePardonersTale.txt",
19
+ " 16 -rw-r--r-- 1 jpace jpace 25163 2010-12-04 15:24 15-TheShipmansTale.txt",
20
+ " 17 -rw-r--r-- 1 jpace jpace 14979 2010-12-04 15:24 16-ThePrioresssTale.txt",
21
+ " 20 -rw-r--r-- 1 jpace jpace 49747 2010-12-04 15:24 19-TheMonksTale.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-TheFriarsTale.txt",
33
+ " 9 : -rw-r--r-- 1 jpace jpace 35994 2010-12-04 15:24 08-TheSompnoursTale.txt",
34
+ " 10 : -rw-r--r-- 1 jpace jpace 64791 2010-12-04 15:24 09-TheClerksTale.txt",
35
+ " 11 : -rw-r--r-- 1 jpace jpace 65852 2010-12-04 15:24 10-TheMerchantsTale.txt",
36
+ " 12 : -rw-r--r-- 1 jpace jpace 42282 2010-12-04 15:24 11-TheSquiresTale.txt",
37
+ " 13 : -rw-r--r-- 1 jpace jpace 51996 2010-12-04 15:24 12-TheFranklinsTale.txt",
38
+ " 14 : -rw-r--r-- 1 jpace jpace 15615 2010-12-04 15:24 13-TheDoctorsTale.txt",
39
+ " 15 : -rw-r--r-- 1 jpace jpace 39546 2010-12-04 15:24 14-ThePardonersTale.txt",
40
+ " 16 : -rw-r--r-- 1 jpace jpace 25163 2010-12-04 15:24 15-TheShipmansTale.txt",
41
+ " 17 : -rw-r--r-- 1 jpace jpace 14979 2010-12-04 15:24 16-ThePrioresssTale.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-TheMonksTale.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-TheFriarsTale.txt",
56
+ " 9 -rw-r--r-- 1 jpace jpace 35994 2010-12-04 15:24 08-TheSompnoursTale.txt",
57
+ " 10 -rw-r--r-- 1 jpace jpace 64791 2010-12-04 15:24 09-TheClerksTale.txt",
58
+ " 11 -rw-r--r-- 1 jpace jpace 65852 2010-12-04 15:24 10-TheMerchantsTale.txt",
59
+ " 12 -rw-r--r-- 1 jpace jpace 42282 2010-12-04 15:24 11-TheSquiresTale.txt",
60
+ " 13 -rw-r--r-- 1 jpace jpace 51996 2010-12-04 15:24 12-TheFranklinsTale.txt",
61
+ " 14 -rw-r--r-- 1 jpace jpace 15615 2010-12-04 15:24 13-TheDoctorsTale.txt",
62
+ " 15 -rw-r--r-- 1 jpace jpace 39546 2010-12-04 15:24 14-ThePardonersTale.txt",
63
+ " 16 -rw-r--r-- 1 jpace jpace 25163 2010-12-04 15:24 15-TheShipmansTale.txt",
64
+ " 17 -rw-r--r-- 1 jpace jpace 14979 2010-12-04 15:24 16-ThePrioresssTale.txt",
65
+ " 20 -rw-r--r-- 1 jpace jpace 49747 2010-12-04 15:24 19-TheMonksTale.txt",
66
+ " 21 -rw-r--r-- 1 jpace jpace 45326 2010-12-04 15:24 20-TheNunsPriestsTale.txt",
67
+ " 22 -rw-r--r-- 1 jpace jpace 30734 2010-12-04 15:24 21-TheSecondNunsTale.txt",
68
+ " 23 -rw-r--r-- 1 jpace jpace 52953 2010-12-04 15:24 22-TheCanonsYeomansTale.txt",
69
+ " 24 -rw-r--r-- 1 jpace jpace 21141 2010-12-04 15:24 23-TheManciplesTale.txt",
70
+ " 25 -rw-r--r-- 1 jpace jpace 58300 2010-12-04 15:24 24-TheParsonsTale.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-TheKnightsTale.txt",
79
+ " 3 -rw-r--r-- 1 jpace jpace 45450 2010-12-04 15:24 02-TheMillersTale.txt",
80
+ " 4 -rw-r--r-- 1 jpace jpace 29296 2010-12-04 15:24 03-TheReevesTale.txt",
81
+ " 5 -rw-r--r-- 1 jpace jpace 6525 2010-12-04 15:24 04-TheCooksTale.txt",
82
+ " 6 -rw-r--r-- 1 jpace jpace 63290 2010-12-04 15:24 05-TheManOfLawsTale.txt",
83
+ " 7 -rw-r--r-- 1 jpace jpace 71054 2010-12-04 15:24 06-TheWifeOfBathsTale.txt",
84
+ " 8 -rw-r--r-- 1 jpace jpace 22754 2010-12-04 15:24 07-TheFriarsTale.txt",
85
+ " 9 -rw-r--r-- 1 jpace jpace 35994 2010-12-04 15:24 08-TheSompnoursTale.txt",
86
+ " 10 -rw-r--r-- 1 jpace jpace 64791 2010-12-04 15:24 09-TheClerksTale.txt",
87
+ " 11 -rw-r--r-- 1 jpace jpace 65852 2010-12-04 15:24 10-TheMerchantsTale.txt",
88
+ " 12 -rw-r--r-- 1 jpace jpace 42282 2010-12-04 15:24 11-TheSquiresTale.txt",
89
+ " 13 -rw-r--r-- 1 jpace jpace 51996 2010-12-04 15:24 12-TheFranklinsTale.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 thy parsley yet fare they the 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 thy parsley yet fare they the worse.",
21
+ " 3 ",
22
+ " 4 That they have eaten in thy stubble goose:",
23
+ " 5 For in thy shop doth many a fly go loose.",
24
+ " 6 ",
25
+ " 7 Now tell on, gentle Roger, by thy name,",
26
+ " 8 But yet I pray thee 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-TheKnightsTale.txt",
12
+ " 3 -rw-r--r-- 1 jpace jpace 45450 2010-12-04 15:24 02-TheMillersTale.txt",
13
+ " 4 -rw-r--r-- 1 jpace jpace 29296 2010-12-04 15:24 03-TheReevesTale.txt",
14
+ " 5 -rw-r--r-- 1 jpace jpace 6525 2010-12-04 15:24 04-TheCooksTale.txt",
15
+ " 6 -rw-r--r-- 1 jpace jpace 63290 2010-12-04 15:24 05-TheManOfLawsTale.txt",
16
+ " 7 -rw-r--r-- 1 jpace jpace 71054 2010-12-04 15:24 06-TheWifeOfBathsTale.txt",
17
+ " 8 -rw-r--r-- 1 jpace jpace 22754 2010-12-04 15:24 07-TheFriarsTale.txt",
18
+ " 9 -rw-r--r-- 1 jpace jpace 35994 2010-12-04 15:24 08-TheSompnoursTale.txt",
19
+ " 10 -rw-r--r-- 1 jpace jpace 64791 2010-12-04 15:24 09-TheClerksTale.txt",
20
+ " 11 -rw-r--r-- 1 jpace jpace 65852 2010-12-04 15:24 10-TheMerchantsTale.txt",
21
+ " 12 -rw-r--r-- 1 jpace jpace 42282 2010-12-04 15:24 11-TheSquiresTale.txt",
22
+ " 13 -rw-r--r-- 1 jpace jpace 51996 2010-12-04 15:24 12-TheFranklinsTale.txt",
23
+ " 14 -rw-r--r-- 1 jpace jpace 15615 2010-12-04 15:24 13-TheDoctorsTale.txt",
24
+ " 15 -rw-r--r-- 1 jpace jpace 39546 2010-12-04 15:24 14-ThePardonersTale.txt",
25
+ " 16 -rw-r--r-- 1 jpace jpace 25163 2010-12-04 15:24 15-TheShipmansTale.txt",
26
+ " 17 -rw-r--r-- 1 jpace jpace 14979 2010-12-04 15:24 16-ThePrioresssTale.txt",
27
+ " 20 -rw-r--r-- 1 jpace jpace 49747 2010-12-04 15:24 19-TheMonksTale.txt",
28
+ " 21 -rw-r--r-- 1 jpace jpace 45326 2010-12-04 15:24 20-TheNunsPriestsTale.txt",
29
+ " 22 -rw-r--r-- 1 jpace jpace 30734 2010-12-04 15:24 21-TheSecondNunsTale.txt",
30
+ " 23 -rw-r--r-- 1 jpace jpace 52953 2010-12-04 15:24 22-TheCanonsYeomansTale.txt",
31
+ " 24 -rw-r--r-- 1 jpace jpace 21141 2010-12-04 15:24 23-TheManciplesTale.txt",
32
+ " 25 -rw-r--r-- 1 jpace jpace 58300 2010-12-04 15:24 24-TheParsonsTale.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-TheSompnoursTale.txt",
12
+ " 12 -rw-r--r-- 1 jpace jpace 42282 2010-12-04 15:24 11-TheSquiresTale.txt",
13
+ " 16 -rw-r--r-- 1 jpace jpace 25163 2010-12-04 15:24 15-TheShipmansTale.txt",
14
+ " 22 -rw-r--r-- 1 jpace jpace 30734 2010-12-04 15:24 21-TheSecondNunsTale.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-TheSompnoursTale.txt",
24
+ " 12 -rw-r--r-- 1 jpace jpace 42282 2010-12-04 15:24 11-TheSquiresTale.txt",
25
+ " 16 -rw-r--r-- 1 jpace jpace 25163 2010-12-04 15:24 15-TheShipmansTale.txt",
26
+ " 22 -rw-r--r-- 1 jpace jpace 30734 2010-12-04 15:24 21-TheSecondNunsTale.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 11-The_Squires_Tale.txt",
12
+ " 16 15-The_Shipmans_Tale.txt",
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 Laws Tale.txt",
12
+ " 7 06 The Wife Of Baths Tale.txt",
13
+ " 8 07 The Friars Tale.txt",
14
+ " 11 10 The Merchants Tale.txt",
15
+ " 13 12 The Franklins Tale.txt",
16
+ " 15 14 The Pardoners Tale.txt",
17
+ " 16 15 The Shipmans Tale.txt",
18
+ " 18 17 Chaucers Tale Of Sir Thopas.txt",
19
+ " 19 18 Chaucers Tale Of Meliboeus.txt",
20
+ " 23 22 The Canons Yeomans Tale.txt",
21
+ " 24 23 The Manciples Tale.txt",
22
+ " 25 24 The Parsons Tale.txt",
23
+ " 26 25 Preces De Chauceres.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 Laws Tale.txt",
32
+ " 7 06 The Wife Of Baths Tale.txt",
33
+ " 15 14 The Pardoners Tale.txt",
34
+ " 23 22 The Canons Yeomans Tale.txt",
35
+ " 24 23 The Manciples Tale.txt",
36
+ " 25 24 The Parsons Tale.txt",
37
+ ]
38
+ run_app_test expected, [ '-w', '\wa\w+s' ], fname
39
+ end
40
+ end
41
+ end
42
+