countloc 0.3.1 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README +16 -1
- data/bin/countloc +123 -0
- data/lib/countloc.rb +135 -69
- data/setup.rb +31 -0
- data/test/tc_cpp.rb +1 -1
- data/test/tc_vb.rb +67 -0
- data/test/ts_countloc.rb +1 -0
- metadata +10 -6
data/README
CHANGED
@@ -17,6 +17,8 @@ Python, C, C++, C#, Java, Perl, etc. ...
|
|
17
17
|
== Download
|
18
18
|
The latest release can be downloaded from: http://rubyforge.org/projects/countloc/
|
19
19
|
|
20
|
+
The latest release can also be installed from the Gem Cutter repository at: http://gemcutter.org/gems/countloc
|
21
|
+
|
20
22
|
== Installation
|
21
23
|
CountLOC is packaged as a Ruby gem and as a .zip file.
|
22
24
|
|
@@ -62,10 +64,23 @@ To get LOC metrics for a C file:
|
|
62
64
|
% countloc.rb hello.c
|
63
65
|
|
64
66
|
To get LOC metrics for all C files in a directory tree:
|
65
|
-
% countloc.rb -r
|
67
|
+
% countloc.rb -r -m c .
|
66
68
|
|
67
69
|
|
68
70
|
== Release Notes
|
71
|
+
=== Release 0.4.0:
|
72
|
+
Features
|
73
|
+
* Added VB support via patch posted on Rubyforge
|
74
|
+
* Added mode option to simplify the selection of source code language.
|
75
|
+
* By default all known file types will be processed with language selected based on file type.
|
76
|
+
* Installers now install an executable - countloc
|
77
|
+
|
78
|
+
Bugfixes:
|
79
|
+
* [27526] Added workaround for Ruby 1.9.1 bug which caused a stack trace to be dumped during exception processing when a bad filename or directory name was encountered.
|
80
|
+
* [27527] Improved help text.
|
81
|
+
* [27528] Improved handling of non-ruby source files.
|
82
|
+
* [27565] Fixed error where files are duplicated when a directory is specified as an argument.
|
83
|
+
|
69
84
|
=== Release 0.3.1:
|
70
85
|
Features
|
71
86
|
* No new features - bugfix release only.
|
data/bin/countloc
ADDED
@@ -0,0 +1,123 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
#
|
3
|
+
# = countloc - Ruby line counter.
|
4
|
+
#
|
5
|
+
# Copyright (C) 2009 Stephen Doyle
|
6
|
+
#
|
7
|
+
# == Features
|
8
|
+
# countloc currently supports generating LOC metrics for source
|
9
|
+
# code of various languages.
|
10
|
+
#
|
11
|
+
# == Download
|
12
|
+
# The latest countloc release can be downloaded from RubyForge:
|
13
|
+
# http://rubyforge.org/frs/?group_id=7555&release_id=29931
|
14
|
+
#
|
15
|
+
# == Example
|
16
|
+
# * countloc --help
|
17
|
+
# * countloc some_file.rb
|
18
|
+
# * countloc -r .
|
19
|
+
#
|
20
|
+
|
21
|
+
require 'countloc'
|
22
|
+
|
23
|
+
class CmdLineOptParser
|
24
|
+
|
25
|
+
def self.usage
|
26
|
+
"Usage: #{File.basename($0)} [-h|--help] [options] <file> ... <file>"
|
27
|
+
end
|
28
|
+
|
29
|
+
#
|
30
|
+
# Return a structure describing the options
|
31
|
+
#
|
32
|
+
def self.parse(args)
|
33
|
+
# The options set on the command line will be collected in "options"
|
34
|
+
# Setup the defaults here
|
35
|
+
options = {}
|
36
|
+
options[:recurse] = false
|
37
|
+
options[:quiet] = false
|
38
|
+
options[:mode] = :ruby
|
39
|
+
options[:defaultMode] = true
|
40
|
+
options[:csv] = false
|
41
|
+
options[:csvFilename] = 'countloc.csv'
|
42
|
+
options[:html] = false
|
43
|
+
options[:htmlFilename] = 'countloc.html'
|
44
|
+
options[:useUserFileTypes] = false
|
45
|
+
|
46
|
+
begin
|
47
|
+
OptionParser.new do |opts|
|
48
|
+
opts.banner = usage
|
49
|
+
|
50
|
+
opts.on('-r', '--recurse', 'Recurse into subdirectories') do
|
51
|
+
options[:recurse] = true
|
52
|
+
end
|
53
|
+
|
54
|
+
opts.on('-v', '--version', 'Display version number') do
|
55
|
+
puts "#{File.basename($0)}, version: #{CountLOC::VERSION}"
|
56
|
+
exit
|
57
|
+
end
|
58
|
+
|
59
|
+
opts.on('-q', '--quiet', "Don't write results to stdout") do
|
60
|
+
options[:quiet] = true
|
61
|
+
end
|
62
|
+
|
63
|
+
opts.on('-m', '--mode mode',
|
64
|
+
[:ruby, :python, :c, :cpp, :csharp, :java, :vb],
|
65
|
+
"Set the language mode.",
|
66
|
+
"All languages are used by default",
|
67
|
+
"if the mode option is omitted.",
|
68
|
+
"Supported modes: ",
|
69
|
+
" ruby, python,",
|
70
|
+
" c, cpp, csharp,",
|
71
|
+
" java, vb") do |mode|
|
72
|
+
options[:mode] = mode
|
73
|
+
options[:defaultMode] = false
|
74
|
+
end
|
75
|
+
|
76
|
+
opts.on('--csv csvFilename', 'Generate csv file') do |csvFilename|
|
77
|
+
options[:csvFilename] = csvFilename
|
78
|
+
options[:csv] = true
|
79
|
+
end
|
80
|
+
|
81
|
+
opts.on('--html htmlFilename', 'Generate html file') do |htmlFilename|
|
82
|
+
options[:htmlFilename] = htmlFilename
|
83
|
+
options[:html] = true
|
84
|
+
end
|
85
|
+
|
86
|
+
opts.on('--file-types fileTypes',
|
87
|
+
"File types to be included.",
|
88
|
+
"Default is dependant upon language mode:",
|
89
|
+
" ruby: *.rb",
|
90
|
+
" python: *.py",
|
91
|
+
" c: *.h, *.c",
|
92
|
+
" cpp: *.h, *.hpp, *.cpp, *.c, *.inl",
|
93
|
+
" csharp: *.cs",
|
94
|
+
" java: *.java",
|
95
|
+
" vb: *.vb",
|
96
|
+
"Defaults are overridden using this option.") do |fileTypes|
|
97
|
+
options[:fileTypes] = fileTypes.split()
|
98
|
+
options[:useUserFileTypes] = true
|
99
|
+
end
|
100
|
+
|
101
|
+
opts.on_tail('-h', '--help', 'Display this help and exit') do
|
102
|
+
puts opts
|
103
|
+
exit
|
104
|
+
end
|
105
|
+
|
106
|
+
end.parse!(args)
|
107
|
+
|
108
|
+
rescue
|
109
|
+
puts "Error: " + $!.to_s
|
110
|
+
exit
|
111
|
+
end
|
112
|
+
|
113
|
+
options
|
114
|
+
end # parse()
|
115
|
+
end # class CmdLineOptParser
|
116
|
+
|
117
|
+
options = CmdLineOptParser.parse(ARGV)
|
118
|
+
if ARGV.length < 1
|
119
|
+
puts CmdLineOptParser.usage
|
120
|
+
exit
|
121
|
+
end
|
122
|
+
|
123
|
+
CountLOC.countloc(ARGV, options)
|
data/lib/countloc.rb
CHANGED
@@ -5,23 +5,18 @@
|
|
5
5
|
# Copyright (C) 2008 Stephen Doyle
|
6
6
|
#
|
7
7
|
# == Features
|
8
|
-
# countloc.rb
|
9
|
-
#
|
10
|
-
# The following commenting styles are supported:
|
11
|
-
# * Single line comments - starting from a # until the end of the line.
|
12
|
-
# * Multi-line comments - between "=begin" and "=end" tags.
|
8
|
+
# countloc.rb generates LOC metrics for a variety of programming languages.
|
13
9
|
#
|
14
10
|
# == Download
|
15
11
|
# The latest countloc release can be downloaded from RubyForge:
|
16
12
|
# http://rubyforge.org/frs/?group_id=7555&release_id=29931
|
17
13
|
#
|
18
14
|
# == Example
|
19
|
-
# * countloc
|
20
|
-
# * countloc
|
21
|
-
# * countloc
|
15
|
+
# * countloc --help
|
16
|
+
# * countloc some_file.rb
|
17
|
+
# * countloc -r .
|
22
18
|
#
|
23
19
|
|
24
|
-
|
25
20
|
require 'optparse'
|
26
21
|
require 'time'
|
27
22
|
|
@@ -31,7 +26,36 @@ require 'time'
|
|
31
26
|
#
|
32
27
|
module CountLOC
|
33
28
|
|
34
|
-
VERSION = '0.
|
29
|
+
VERSION = '0.4.0'
|
30
|
+
|
31
|
+
DEFAULT_FILE_TYPES = {
|
32
|
+
:ruby => [".rb"],
|
33
|
+
:python => [".py"],
|
34
|
+
:c => [".h", ".c"],
|
35
|
+
:cpp => [".h", ".hpp", ".cpp", ".c", ".cc", ".inl"],
|
36
|
+
:csharp => [".cs"],
|
37
|
+
:java => [".java"],
|
38
|
+
:vb => [".vb"]
|
39
|
+
}
|
40
|
+
|
41
|
+
DEFAULT_STYLE = {
|
42
|
+
".rb" => :ruby,
|
43
|
+
".py" => :python,
|
44
|
+
".h" => :cpp,
|
45
|
+
".c" => :cpp,
|
46
|
+
".hpp" => :cpp,
|
47
|
+
".cpp" => :cpp,
|
48
|
+
".cc" => :cpp,
|
49
|
+
".inl" => :cpp,
|
50
|
+
".cs" => :csharp,
|
51
|
+
".java" => :java,
|
52
|
+
".vb" => :vb
|
53
|
+
}
|
54
|
+
|
55
|
+
# Get the supported style for a given filename
|
56
|
+
def getStyle(filename)
|
57
|
+
DEFAULT_FILE_TYPES.invert[File.extname(filename)]
|
58
|
+
end
|
35
59
|
|
36
60
|
# Class that gathers the metrics.
|
37
61
|
#
|
@@ -42,33 +66,48 @@ module CountLOC
|
|
42
66
|
attr_reader :name
|
43
67
|
attr_accessor :code, :comments, :blank, :lines
|
44
68
|
|
45
|
-
|
46
|
-
|
47
|
-
:
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
69
|
+
def comment_patterns(style)
|
70
|
+
patterns = {
|
71
|
+
:ruby => {
|
72
|
+
:single_line_full => /^\s*#/,
|
73
|
+
:single_line_mixed => /#/,
|
74
|
+
:multiline_begin => /=begin(\s|$)/,
|
75
|
+
:multiline_end => /=end(\s|$)/,
|
76
|
+
:blank_line => /^\s*$/
|
77
|
+
},
|
53
78
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
79
|
+
:vb => {
|
80
|
+
:single_line_full => /^\s*\'/,
|
81
|
+
:single_line_mixed => /\'/,
|
82
|
+
:multiline_begin => /=begin(\s|$)/, # No VB multi-line comment
|
83
|
+
:multiline_end => /=end(\s|$)/, # No VB multi-line comment
|
84
|
+
:blank_line => /^\s*$/
|
85
|
+
},
|
86
|
+
|
87
|
+
:python => {
|
88
|
+
:single_line_full => /^\s*#/,
|
89
|
+
:single_line_mixed => /#/,
|
90
|
+
:multiline_begin => /^\s*"""/,
|
91
|
+
:multiline_end => /"""/,
|
92
|
+
:blank_line => /^\s*$/
|
93
|
+
},
|
94
|
+
|
95
|
+
:cpp => { # C++
|
96
|
+
:single_line_full => /^\s*\/\//,
|
97
|
+
:single_line_mixed => /\/\//,
|
98
|
+
:multiline_begin => /\/\*/,
|
99
|
+
:multiline_end => /\*\/\s*$/,
|
100
|
+
:multiline_begin_mixed => /^[^\s]+.*\/\*/,
|
101
|
+
:multiline_end_mixed => /\*\/\s*[^\s]+$/,
|
102
|
+
:blank_line => /^\s*$/
|
103
|
+
}
|
70
104
|
}
|
71
|
-
|
105
|
+
patterns[:c] = patterns[:cpp]
|
106
|
+
patterns[:csharp] = patterns[:cpp]
|
107
|
+
patterns[:java] = patterns[:cpp]
|
108
|
+
|
109
|
+
patterns[style]
|
110
|
+
end
|
72
111
|
|
73
112
|
LINE_FORMAT = '%8s %8s %8s %8s %12s %s'
|
74
113
|
|
@@ -87,23 +126,6 @@ module CountLOC
|
|
87
126
|
self.headline.split(' ', 6)
|
88
127
|
end
|
89
128
|
|
90
|
-
#
|
91
|
-
# Retrieve the commenting style that should be used for the given
|
92
|
-
# file type.
|
93
|
-
#
|
94
|
-
def self.commentStyle(ext)
|
95
|
-
{ ".rb" => :ruby,
|
96
|
-
".py" => :python,
|
97
|
-
".c" => :cplusplus,
|
98
|
-
".cpp" => :cplusplus,
|
99
|
-
".cc" => :cplusplus,
|
100
|
-
".cs" => :cplusplus,
|
101
|
-
".h" => :cplusplus,
|
102
|
-
".hpp" => :cplusplus,
|
103
|
-
".java" => :cplusplus
|
104
|
-
}[ext]
|
105
|
-
end
|
106
|
-
|
107
129
|
def initialize(name)
|
108
130
|
@name = name
|
109
131
|
@code = 0
|
@@ -129,7 +151,7 @@ module CountLOC
|
|
129
151
|
line.gsub!(/\/.*?\//, "X") # Regular expression
|
130
152
|
end
|
131
153
|
|
132
|
-
patterns =
|
154
|
+
patterns = comment_patterns(style)
|
133
155
|
|
134
156
|
# In the event where the multiline_end pattern is the same as the
|
135
157
|
# multiline_begin pattern, it is necessary to check for the ending
|
@@ -280,7 +302,7 @@ module CountLOC
|
|
280
302
|
begin
|
281
303
|
File.open(@filename, "wb") { |file| file.puts data.to_csv }
|
282
304
|
rescue
|
283
|
-
puts "Error: " +
|
305
|
+
puts "Error: " + $!.to_s
|
284
306
|
end
|
285
307
|
end
|
286
308
|
|
@@ -301,7 +323,7 @@ module CountLOC
|
|
301
323
|
begin
|
302
324
|
File.open(@filename, "w") { |file| file.puts data.to_html }
|
303
325
|
rescue
|
304
|
-
puts "Error: " +
|
326
|
+
puts "Error: " + $!.to_s
|
305
327
|
end
|
306
328
|
end
|
307
329
|
|
@@ -316,15 +338,23 @@ module CountLOC
|
|
316
338
|
# * :html - write the results to a html file. Default = false.
|
317
339
|
# * :htmlFilename - name of html file to generate. Used with :html option. Default = countloc.html
|
318
340
|
# * :quiet - do not output results to stdout
|
319
|
-
# * :
|
320
|
-
#
|
341
|
+
# * :mode - language mode. Determines parsing rules and default file types.
|
342
|
+
# Supported modes: ruby, python, c, cpp, csharp, java, vb.
|
343
|
+
# If no mode is selected, the default mode is to select the parsing rules based on
|
344
|
+
# file extension. A default set of file extensions covering all supported languages
|
345
|
+
# will be used.
|
346
|
+
# * :fileTypes - Types of file to include in the LOC analysis. By default the file types
|
347
|
+
# used are based on the language mode selected. This option can be used to override
|
348
|
+
# the default file types.
|
321
349
|
def countloc(files, options = {})
|
322
|
-
|
350
|
+
|
323
351
|
# Setup defaults for filenames
|
324
|
-
options[:
|
325
|
-
|
326
|
-
|
327
|
-
|
352
|
+
if options[:defaultMode]
|
353
|
+
options[:fileTypes] = DEFAULT_FILE_TYPES.values.flatten if not options[:useUserFileTypes]
|
354
|
+
else
|
355
|
+
options[:fileTypes] = DEFAULT_FILE_TYPES[options[:mode]] if not options[:useUserFileTypes]
|
356
|
+
end
|
357
|
+
|
328
358
|
# Setup the output writers based on the options
|
329
359
|
writers = []
|
330
360
|
writers << ConsoleWriter.new if not options[:quiet]
|
@@ -337,8 +367,9 @@ module CountLOC
|
|
337
367
|
recursePattern = ("**" if options[:recurse]) || ""
|
338
368
|
files -= dirs
|
339
369
|
options[:fileTypes].each do |fileType|
|
340
|
-
files += dirs.collect { |dirname| Dir.glob(File.join(dirname, recursePattern, fileType))}.flatten
|
370
|
+
files += dirs.collect { |dirname| Dir.glob(File.join(dirname, recursePattern, '*'+fileType))}.flatten
|
341
371
|
end
|
372
|
+
files.uniq!
|
342
373
|
end
|
343
374
|
|
344
375
|
# Sum will keep the running total
|
@@ -350,14 +381,18 @@ module CountLOC
|
|
350
381
|
# Generate metrics for each file
|
351
382
|
files.each do |filename|
|
352
383
|
begin
|
353
|
-
|
384
|
+
File.open(filename) do |file|
|
354
385
|
counter = LineCounter.new(filename)
|
355
|
-
|
386
|
+
mode = options[:mode]
|
387
|
+
if options[:defaultMode]
|
388
|
+
mode = DEFAULT_STYLE[File.extname(filename)] || options[:mode]
|
389
|
+
end
|
390
|
+
counter.read(file, mode)
|
356
391
|
sum += counter
|
357
392
|
results << counter
|
358
393
|
end
|
359
394
|
rescue
|
360
|
-
puts "Error: " +
|
395
|
+
puts "Error: " + $!.to_s
|
361
396
|
end
|
362
397
|
end
|
363
398
|
|
@@ -392,6 +427,15 @@ if $0 == __FILE__
|
|
392
427
|
# The options set on the command line will be collected in "options"
|
393
428
|
# Setup the defaults here
|
394
429
|
options = {}
|
430
|
+
options[:recurse] = false
|
431
|
+
options[:quiet] = false
|
432
|
+
options[:mode] = :ruby
|
433
|
+
options[:defaultMode] = true
|
434
|
+
options[:csv] = false
|
435
|
+
options[:csvFilename] = 'countloc.csv'
|
436
|
+
options[:html] = false
|
437
|
+
options[:htmlFilename] = 'countloc.html'
|
438
|
+
options[:useUserFileTypes] = false
|
395
439
|
|
396
440
|
begin
|
397
441
|
OptionParser.new do |opts|
|
@@ -402,7 +446,7 @@ if $0 == __FILE__
|
|
402
446
|
end
|
403
447
|
|
404
448
|
opts.on('-v', '--version', 'Display version number') do
|
405
|
-
puts "#{File.basename($0)}, version: #{VERSION}"
|
449
|
+
puts "#{File.basename($0)}, version: #{CountLOC::VERSION}"
|
406
450
|
exit
|
407
451
|
end
|
408
452
|
|
@@ -410,6 +454,19 @@ if $0 == __FILE__
|
|
410
454
|
options[:quiet] = true
|
411
455
|
end
|
412
456
|
|
457
|
+
opts.on('-m', '--mode mode',
|
458
|
+
[:ruby, :python, :c, :cpp, :csharp, :java, :vb],
|
459
|
+
"Set the language mode.",
|
460
|
+
"All languages are used by default",
|
461
|
+
"if the mode option is omitted.",
|
462
|
+
"Supported modes: ",
|
463
|
+
" ruby, python,",
|
464
|
+
" c, cpp, csharp,",
|
465
|
+
" java, vb") do |mode|
|
466
|
+
options[:mode] = mode
|
467
|
+
options[:defaultMode] = false
|
468
|
+
end
|
469
|
+
|
413
470
|
opts.on('--csv csvFilename', 'Generate csv file') do |csvFilename|
|
414
471
|
options[:csvFilename] = csvFilename
|
415
472
|
options[:csv] = true
|
@@ -422,8 +479,17 @@ if $0 == __FILE__
|
|
422
479
|
|
423
480
|
opts.on('--file-types fileTypes',
|
424
481
|
"File types to be included.",
|
425
|
-
"Default
|
482
|
+
"Default is dependant upon language mode:",
|
483
|
+
" ruby: *.rb",
|
484
|
+
" python: *.py",
|
485
|
+
" c: *.h, *.c",
|
486
|
+
" cpp: *.h, *.hpp, *.cpp, *.c, *.inl",
|
487
|
+
" csharp: *.cs",
|
488
|
+
" java: *.java",
|
489
|
+
" vb: *.vb",
|
490
|
+
"Defaults are overridden using this option.") do |fileTypes|
|
426
491
|
options[:fileTypes] = fileTypes.split()
|
492
|
+
options[:useUserFileTypes] = true
|
427
493
|
end
|
428
494
|
|
429
495
|
opts.on_tail('-h', '--help', 'Display this help and exit') do
|
@@ -434,7 +500,7 @@ if $0 == __FILE__
|
|
434
500
|
end.parse!(args)
|
435
501
|
|
436
502
|
rescue
|
437
|
-
puts "Error: " +
|
503
|
+
puts "Error: " + $!.to_s
|
438
504
|
exit
|
439
505
|
end
|
440
506
|
|
data/setup.rb
CHANGED
@@ -8,6 +8,10 @@
|
|
8
8
|
# the GNU LGPL, Lesser General Public License version 2.1.
|
9
9
|
#
|
10
10
|
|
11
|
+
require 'rubygems'
|
12
|
+
require 'fileutils'
|
13
|
+
require 'tmpdir'
|
14
|
+
|
11
15
|
unless Enumerable.method_defined?(:map) # Ruby 1.4.6
|
12
16
|
module Enumerable
|
13
17
|
alias map collect
|
@@ -1344,6 +1348,9 @@ class Installer
|
|
1344
1348
|
|
1345
1349
|
def install_dir_bin(rel)
|
1346
1350
|
install_files targetfiles(), "#{config('bindir')}/#{rel}", 0755
|
1351
|
+
|
1352
|
+
return unless Gem.win_platform?
|
1353
|
+
install_bat_files targetfiles(), "#{config('bindir')}/#{rel}", 0755
|
1347
1354
|
end
|
1348
1355
|
|
1349
1356
|
def install_dir_lib(rel)
|
@@ -1378,6 +1385,30 @@ class Installer
|
|
1378
1385
|
end
|
1379
1386
|
end
|
1380
1387
|
|
1388
|
+
def install_bat_files(list, dest, mode)
|
1389
|
+
mkdir_p dest, @config.install_prefix
|
1390
|
+
list.each do |bin_file|
|
1391
|
+
begin
|
1392
|
+
bin_cmd_file = File.join Dir.tmpdir, "#{bin_file}.bat"
|
1393
|
+
|
1394
|
+
File.open bin_cmd_file, 'w' do |file|
|
1395
|
+
file.puts <<-TEXT
|
1396
|
+
@ECHO OFF
|
1397
|
+
IF NOT "%~f0" == "~f0" GOTO :WinNT
|
1398
|
+
@"#{Gem.ruby}" "#{bin_file}" %1 %2 %3 %4 %5 %6 %7 %8 %9
|
1399
|
+
GOTO :EOF
|
1400
|
+
:WinNT
|
1401
|
+
"%~d0%~p0ruby.exe" "%~d0%~p0%~n0" %*
|
1402
|
+
TEXT
|
1403
|
+
end
|
1404
|
+
|
1405
|
+
install bin_cmd_file, dest, mode, @config.install_prefix
|
1406
|
+
ensure
|
1407
|
+
FileUtils.rm bin_cmd_file
|
1408
|
+
end
|
1409
|
+
end
|
1410
|
+
end
|
1411
|
+
|
1381
1412
|
def libfiles
|
1382
1413
|
glob_reject(%w(*.y *.output), targetfiles())
|
1383
1414
|
end
|
data/test/tc_cpp.rb
CHANGED
data/test/tc_vb.rb
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
$:.unshift File.join(File.dirname(__FILE__), "..", "lib")
|
2
|
+
|
3
|
+
# Copyright (C) 2008 Stephen Doyle
|
4
|
+
|
5
|
+
require 'test/unit'
|
6
|
+
require 'countloc'
|
7
|
+
|
8
|
+
class VBTest < Test::Unit::TestCase
|
9
|
+
|
10
|
+
include CountLOC
|
11
|
+
|
12
|
+
def setup
|
13
|
+
@counter = LineCounter.new('Test')
|
14
|
+
@style = :vb
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_single_line_comment
|
18
|
+
@counter.read("' This is a comment", @style)
|
19
|
+
assert_equal(0, @counter.code)
|
20
|
+
assert_equal(1, @counter.comments)
|
21
|
+
assert_equal(0, @counter.blank)
|
22
|
+
assert_equal(1, @counter.lines)
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_single_line_comment_with_whitespace
|
26
|
+
@counter.read(" ' This is a comment", @style)
|
27
|
+
assert_equal(0, @counter.code)
|
28
|
+
assert_equal(1, @counter.comments)
|
29
|
+
assert_equal(0, @counter.blank)
|
30
|
+
assert_equal(1, @counter.lines)
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_mixed
|
34
|
+
@counter.read("Label1.Visible = false ' This is a mixed comment", @style)
|
35
|
+
assert_equal(1, @counter.code)
|
36
|
+
assert_equal(1, @counter.comments)
|
37
|
+
assert_equal(0, @counter.blank)
|
38
|
+
assert_equal(1, @counter.lines)
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_comment_char_in_double_quote_string
|
42
|
+
@counter.read("x = \"hello '\"", @style)
|
43
|
+
assert_equal(1, @counter.code)
|
44
|
+
assert_equal(0, @counter.comments)
|
45
|
+
assert_equal(0, @counter.blank)
|
46
|
+
assert_equal(1, @counter.lines)
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_blank_lines_with_newline
|
50
|
+
@counter.read("\n", @style)
|
51
|
+
assert_equal(0, @counter.code)
|
52
|
+
assert_equal(0, @counter.comments)
|
53
|
+
assert_equal(1, @counter.blank)
|
54
|
+
assert_equal(1, @counter.lines)
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_blank_lines_with_whitespace
|
58
|
+
@counter.read(" \t", @style)
|
59
|
+
assert_equal(0, @counter.code)
|
60
|
+
assert_equal(0, @counter.comments)
|
61
|
+
assert_equal(1, @counter.blank)
|
62
|
+
assert_equal(1, @counter.lines)
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
|
67
|
+
|
data/test/ts_countloc.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: countloc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stephen Doyle
|
@@ -9,14 +9,14 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-12-
|
12
|
+
date: 2009-12-17 21:43:16.254209 +00:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
16
16
|
description: LOC metrics generation script implementation in Ruby.
|
17
17
|
email: support@stephendoyle.net
|
18
|
-
executables:
|
19
|
-
|
18
|
+
executables:
|
19
|
+
- countloc
|
20
20
|
extensions: []
|
21
21
|
|
22
22
|
extra_rdoc_files: []
|
@@ -26,12 +26,16 @@ files:
|
|
26
26
|
- LICENSE
|
27
27
|
- setup.rb
|
28
28
|
- lib/countloc.rb
|
29
|
+
- bin/countloc
|
29
30
|
- test/tc_cpp.rb
|
30
31
|
- test/tc_python.rb
|
31
32
|
- test/tc_ruby.rb
|
33
|
+
- test/tc_vb.rb
|
32
34
|
- test/ts_countloc.rb
|
33
35
|
has_rdoc: true
|
34
36
|
homepage: http://countloc.rubyforge.org/
|
37
|
+
licenses: []
|
38
|
+
|
35
39
|
post_install_message:
|
36
40
|
rdoc_options:
|
37
41
|
- --title
|
@@ -54,9 +58,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
54
58
|
requirements: []
|
55
59
|
|
56
60
|
rubyforge_project: countloc
|
57
|
-
rubygems_version: 1.
|
61
|
+
rubygems_version: 1.3.5
|
58
62
|
signing_key:
|
59
|
-
specification_version:
|
63
|
+
specification_version: 3
|
60
64
|
summary: Ruby line counter - countLOC
|
61
65
|
test_files:
|
62
66
|
- test/ts_countloc.rb
|