9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
* [9fans] silly script to perform regression testing
@ 2003-10-18  0:09 Fco.J.Ballesteros
  0 siblings, 0 replies; only message in thread
From: Fco.J.Ballesteros @ 2003-10-18  0:09 UTC (permalink / raw)
  To: 9fans

[-- Attachment #1: Type: text/plain, Size: 80 bytes --]

I thought this might be useful for others, although it's a bit naive.

hth


[-- Attachment #2: check --]
[-- Type: text/plain, Size: 1268 bytes --]

#!/bin/rc

prog=8.out
verb=no

if (~ $1 -v){
	verb=yes
	shift
}

switch($#*){
case 0
	tests=`{ls [0-9]* >[2]/dev/null | grep -v 'out' | grep -v new}
case 1
	prog=$1
	tests=`{ls [0-9]* >[2]/dev/null | grep -v 'out' | grep -v new}
case 2
	prog=$1
	shift
	if (test -d $1)
		tests=`{ls $1/[0-9]* >[2]/dev/null |
			grep -v 'out$' | grep -v 'new$'}
	if not
		tests=$1
case *
	echo usage: $0 '[-v] [prog [test|testdir]]' >[1=2]
	exit usage
}

if (! test -x $prog){
	echo $prog ': not executable' >[1=2]
	exit prog
}
pname=`{basename $prog}

fn fail (){
	echo $* >[1=2]
	exit failed
}

for ( f in $tests) {
	what=`{sed 1q $f | grep '^#'}
	if (! ~ $#what 0)
		echo test $f : $what
	if not
		echo test $f
	broke|rc
	kill $pname|rc
	rm -f $f.new
	grep '^#!' $f | sed 's/..//'  | rc
	grep -v '^#' $f  | $prog $params>$f.new >[2=1]
	if (test -e $f.out){
		diff <{grep -v '^#' $f.out} <{grep -v '^#' $f.new} ||
			{ echo ; echo mv $f.new $f.out
			  echo output was:
			  sed 's/^/	/' $f.new
			  fail test $f failed
			}
		if (~ $verb yes)
			sed 's/^/	/' $f.new
		rm -f $f.new
	}
	if not {
		echo first time for $f
		if (~ $verb yes)
			sed 's/^/	/' $f.new
		mv $f.new $f.out
	}
}
echo all tests passed
exit 0

[-- Attachment #3: check --]
[-- Type: text/plain, Size: 1616 bytes --]

.TH CHECK 1
.SH NAME
check \- check that regression tests pass
.SH SYNOPSIS
.B check
[
.B -v
]
[
.I prog
[
.I file
|
.I dir
]
]
.SH DESCRIPTION
.I Check
is an rc script that performs regression testing for a program. It sends
input files to the program
.I prog
(by default
.B 8.out )
and compares its output with that of previous runs. It is usual to have
one input file per program test. Input files must have
names that start with a digit and do not have
.B .out
or
.B .new
suffixes.
.PP
Check executes the program just for
.IR file ,
if given as an argument. It checks all input files in
.I dir
if given, and all input files in
the current directory otherwise.
.PP
The first time a test is run, it is considered to pass and its output is
kept in a file named like the input file but terminated in
.BR .out .
When a check fails the new output (which differs from the
.B .out
file) is kept in a file for inspection. This file has the same name of the input
file terminated in
.BR .new .
.PP
Input files may contain arbitrary text. Lines starting with
.B #
are ignored and lines starting with
.B #!
are executed before starting the check of the input file. This mechanism
can be used to prepare the environment for the check.
Option
.B -v
makes the program output more verbose.
.PP
If the first line of an input file is a comment, check considers that
it contains a one-line description of the test performed by the file. That
description is printed when the test is run.
.SH SOURCE
.B /rc/bin/check
.SH BUGS
Binary input files are not handled properly.

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2003-10-18  0:09 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-10-18  0:09 [9fans] silly script to perform regression testing Fco.J.Ballesteros

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).