The online community for software testing & quality assurance professionals
   
Active Topics Today's Topics
Sponsors:
Lost Password?

Home
BetaSoft
Jobs
Training
News
Links
Downloads

News Group:
software.testing


Testing
Automation
Performance
Engineering
Miscellaneous
Statistics
Poll
  QA Forums
  WinRunner
  LOC(Lines Of Code ) of WinRunner Scripts

Post New Topic  Post A Reply
profile | register | preferences | faq | search

UBBFriend: Email This Page to Someone! next newest topic | next oldest topic
Author Topic:   LOC(Lines Of Code ) of WinRunner Scripts
WinRunner
Moderator

Posts: 9845
Registered: Mar 2001

posted 10-20-2002 09:21 PM     Click Here to See the Profile for WinRunner   Edit/Delete Message Copy This Message   Reply w/Quote Search for more posts by WinRunner Visit WinRunner's Homepage!
User bindu bk (bindu_bk@rediffmail.com.nospam) posted:

hi,

could any one tell me whether there is any tool/Function to count

IP Logged

rajbalachandran
Member

Posts: 60
Registered: Jun 2001

posted 10-20-2002 10:40 PM     Click Here to See the Profile for rajbalachandran   Edit/Delete Message Copy This Message   Reply w/Quote Search for more posts by rajbalachandran
User Rajesh Balachandran (rajesh.balachandran@india.birlasoft.com.nospam) posted:

if u want to see the line u can set the line numbers in the gutter...use the
editor properties

IP Logged

cranem451
Guru

Posts: 395
Registered: Mar 2002

posted 10-21-2002 12:18 AM     Click Here to See the Profile for cranem451   Edit/Delete Message Copy This Message   Reply w/Quote Search for more posts by cranem451
Here is an example function to count:
Number of code lines (real code)
Number of Blank or Comment lines
Total Number of lines in script file

Link to Example code: http://www.addendum.com/winrunner/29286372.zip

------------------
cranem451 - cranem@addendum.com

IP Logged

Charles Reace
Advanced Guru

Posts: 1299
Registered: May 2001

posted 10-21-2002 12:35 PM     Click Here to See the Profile for Charles Reace   Edit/Delete Message Copy This Message   Reply w/Quote Search for more posts by Charles Reace Visit Charles Reace's Homepage!
User Charles Reace (cwreace@yahoo.com.nospam) posted:


The following Perl script should do the job (you'll need to install ActivePerl - http://www.activeperl.com - on your PC if you haven't already):

#!/auto/local/bin/perl -w
######################################################################
#
# numlines - counts number of code lines (non-comment, non-whitespace)
#
# CREATED: 2002/06/21 by creace
#
# USAGE: numlines filename
#
# NOTES: Assumes comment lines start with '#'
#
######################################################################
use strict;

### FUNCTIONS ###

sub usage {
print("USAGE: numlines file_pathname\n");
die "$_[0]\n";
}

### MAIN PROGRAM ###

my @lines;
my @codeLines;
my $ix;

if(! $ARGV[0])
{
usage("No filename supplied");
}

open(FILE,"$ARGV[0]") or usage("Could not open file '$ARGV[0]'");
while(<FILE> )
{
push @lines, "$_";
}
@codeLines = grep !/^\s*#/ && /[^\s]/, @lines;
printf("\nLines of code in $ARGV[0]: %d\n", $#codeLines + 1);

[This message has been edited by Charles Reace (edited 10-21-2002).]

IP Logged

kgoto
Member

Posts: 7
Registered: Oct 2002

posted 10-23-2002 02:20 PM     Click Here to See the Profile for kgoto   Edit/Delete Message Copy This Message   Reply w/Quote Search for more posts by kgoto
You can use this Perl script if you want to count lines for all of your WinRunner scripts living in a project directory. It should find any file named "script" living within 2 levels deep of the path you specify.

-keigo

#!perl -w
#
# Counts the number of lines specified in a directory of scripts
# (Does not count comments or blank lines)
# You can use this on a directory that is one level higher so that
# you can count the lines of an entire group of scripts.
#
# Created: 2002/10/23 by Keigo Goto
# Usage: perl WRLineCounter.pl <directory path>
#
#

use strict;

if (! $ARGV[0]) {
print("USAGE: perl WRLineCounter.pl <directory of scripts>");
exit(0);
}

my $counter = 0;
my $directory = $ARGV[0];

## add a slash if needed
my $lastChar = substr($directory, (length $directory) -1, 1);
if ($lastChar ne "/" | | $lastChar ne "\\") {
$directory = $directory."\\";
}

my @files;
### Gather the files we will parse and count lines.
opendir DIR, "$directory" or die "Error: Please specify a directory to check.";
while ($_ = readdir(DIR)) {
next if $_ eq "." or $_ eq "..";
if (-d $directory.$_) {
my $scriptFile = $directory.$_."\\script";
if (-f $scriptFile) {
push(@files, $scriptFile);
}
}
# also run for a single directory
elsif (-f $_ and $_=~/script/) {
push(@files, $_);
}
}

my $directory_str_length = length $directory;
### parse each file and increment counter for each good line.
foreach my $scriptFile (@files) {
open SCRIPT, "< $scriptFile" or die "Couldn't open the file $scriptFile";
## subCounter holds number of lines for each file.
my $subCounter = 0;
while (<SCRIPT> ) {
next if (($_ =~ /^[\s]*[#]/) or ($_ =~ /^\s*\n/));
$counter++;
$subCounter++;
}
my $displayScriptName = substr($scriptFile, $directory_str_length);
print $displayScriptName.": $subCounter lines\n";
}

### Print out the results
my $numOfFiles = scalar @files;
print "Number of files to parse: $numOfFiles\n";
print "Total Number of Lines of Code: $counter \n";

IP Logged

All times are PT (US)

next newest topic | next oldest topic

Administrative Options: Close Topic | Archive/Move | Delete Topic | Top
Post New Topic  Post A Reply
Hop to:

Contact Us | BetaSoft Inc. | Privacy Statement

Copyright 1997-2003 BetaSoft Inc.


Ultimate Bulletin Board 5.45c