9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
From: Fco.J.Ballesteros <nemo@plan9.escet.urjc.es>
To: 9fans@cse.psu.edu
Subject: [9fans] silly script to perform regression testing
Date: Sat, 18 Oct 2003 02:09:10 +0200	[thread overview]
Message-ID: <f142f9e2d97ba4b1b2126860ceef3d26@plan9.escet.urjc.es> (raw)

[-- 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.

                 reply	other threads:[~2003-10-18  0:09 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=f142f9e2d97ba4b1b2126860ceef3d26@plan9.escet.urjc.es \
    --to=nemo@plan9.escet.urjc.es \
    --cc=9fans@cse.psu.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).