Skip to content

Commit

Permalink
TESTS: Cleaned up filepath handling in quick-test.r, re-instated run-…
Browse files Browse the repository at this point in the history
…test.r & updated quick-test docs
  • Loading branch information
PeterWAWood committed Feb 29, 2012
1 parent 86e048f commit 5c61a62
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 39 deletions.
79 changes: 55 additions & 24 deletions docs/red-system-quick-test.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Red/System Quick Test - A testing framework

Author: Peter W A Wood
Date: 5/07/2011
Version 0.5.0
Date: 29/02/2012
Version 0.8.0
Home: <a href="http://www.red-lang.org">red-lang.org</a>

===Introduction
Expand All @@ -12,7 +12,7 @@ As a result, quick-test is very fussy about where files are and it is not partic

There are actually two aspects to Quick-Test. The first is quick-test.reds, a handful of Red/System functions which can be included in a Red/System program to write unit tests. This can easily be used on its own to test Red/System code and is not at all fussy about where files reside.

A temporary addition has been made to this part of Quick-Test. It is quick-test.red which is currently written in REBOL and used for unit testing the bootstrapping Red compiler. It will be replaced by a Red version once the compiler is re-written in Red.
A temporary addition has been made to this part of Quick-Test. It is quick-unit-test.r which is written in REBOL and used for unit testing the bootstrapping Red compiler.

The second aspect is that Quick-Test is a full-test suite for Red/System itself and includes the files used to test Red/System.

Expand All @@ -28,29 +28,30 @@ Quick-Test consists of the following:

quick-test.r - a REBOL script that supports testing compiler and executable output.
quick-test.reds - a set of Red/System functions that supports writing tests in Red/System.
quick-test.red - a set of REBOL functions that supports writing tests in REBOL.
quick-unit-test.r - a set of REBOL functions that supports writing tests in REBOL.

(The above are stored in the red-system/tests/quick-test/ directory.)
(The above are stored in the Red/quick-test/ directory.)

run-all.r - a script which runs the complete set of Red/System tests.
run-all.r - a script(s) which runs a set of Red/System tests.
- run-all.r in Red/red-system/tests/ runs the Red/System test suite
- run-all.r in Red/red/tests/ will run the Red test suite*
- run-all.r in Red/ will run all the tests*
run-test.r - a script which will run an individual test.
- stored in Red/quick-test/

(Both the above are stored in the red-system/tests/ directory.)

run-all.r - a script that runs the complete set of Red tests.

(Stored in the red/tests/ directory.)
* to be written

===Directory Structure
Quick-Test uses the following directory structure:

Red/
quick-test/ ;; quick-test components
red/
run-all.r ;; runs all Red tests
source/
compiler/ ;; red compiler unit tests
runtime/ ;; runtime tests
tests/
run-all.r ;; runs all Red tests
source/
compiler/ ;; red compiler unit tests
runtime/ ;; runtime tests
red-system/
tests/ ;; the main test directory
run-all.r ;; runs all Red/System tests
Expand All @@ -65,24 +66,37 @@ Quick-Test uses the following directory structure:
;; listed in .gitignore

===Running Tests
The tests are designed to be run from a REBOL console session. This must be a REBOL/View console session under Windows.
The tests are designed to be run from the command line or a REBOL console session. This must be a REBOL/View console session under Windows.

To run all Red tests:
The following examples assume that they have been run from the Red dir

To run all Red tests from the console:

rebol -s red/tests/run-all.r

To run all Red tests from the REBOL console:

do %red/tests/run-all.r

To run all Red/System tests:
To run all Red/System tests from the console:
rebol -s red-system/tests/run-all.r

To run all Red/System tests from the REBOL console:
do %red-system/tests/run-all.r

To run an individual test file (must be run from the red-system/tests/ directory):
do/args %run-test.r "%<file>"
To run an individual test file from the console:
rebol -s quick-test/run-test.r "<file>"

where <file> is the path to the file to be tested (from the red-system/tests/ directory).
To run an individual test file from the REBOL console:
do/args %quick-test/run-test.r "<file>"

e.g.
The command to run the logic-test.reds test file which is in the units directory:
do/args %run-test.r "%source/units/logic-test.reds"
where <file> is the path to the file to be tested .

e.g. The command to run the logic-test.reds test file which is in the units directory:
do/args %quick-test/run-test.r "red-system/tests/source/units/logic-test.reds"

(Note: %run-test.r can run both .r and .reds tests).
(Note: When using run-test.r from within a REBOL console session, the file paths to both run-test.r and the test file msut be relative to the directory from which the REBOL session was launched (system/options/path).

===Writing Tests
In terms of writing tests, Quick-Test is quite minimal by design. It provides only a simple assert function and a minimal set of test organisation functions.
Expand Down Expand Up @@ -198,6 +212,18 @@ The start of an individual test. The number of tests in a run and file are count

An assertion. True = pass. False = fail. The number of assertions, passes and failures are counted and reported for each run and file.

--assertf~= <value> <value> <tolerance>
<value> : a float! value
<tolerance> : a float! value

An assertion that two floating point numbers are approximately equal. The tolerance provided is used both as an absolute and relative tolerance. The calculation of the tolerance is a quite simplistic but has proved sufficient for its purpose.

--assertf32~= <value> <value> <tolerance>
<value> : a float32! value
<tolerance> : a float32! value

AssetF~= for float32! values.

===end-group===

Marks the end of a group of tests.
Expand Down Expand Up @@ -310,6 +336,11 @@ An assertion. True = pass. False = fail. The number of assertions, passes and fa

Checks if the compiler has produced the expected message.

--assert-printed? <phrase>
<phrase> : expected runtime output - string!

Checks if the runtime output included the expected phrase.

--clean

Cleans up the temporary files created by --compile-this and --compile-and-run-this. Can be safely used, but is not necessary, after --compile, --compile-and-run and --run.
Expand Down
29 changes: 14 additions & 15 deletions quick-test/quick-test.r
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ REBOL [
Title: "Simple testing framework for Red/System programs"
Author: "Peter W A Wood"
File: %quick-test.r
Version: 0.7.1
Version: 0.8.0
Rights: "Copyright (C) 2011 Peter W A Wood. All rights reserved."
License: "BSD-3 - https://github.com/dockimbel/Red/blob/master/BSD-3-License.txt"
]
Expand All @@ -27,22 +27,22 @@ qt: make object! [
base-dir: system/script/path
base-dir: copy/part base-dir find base-dir "quick-test"
;; set the red/system compiler directory
comp-dir: join base-dir "red-system/"
comp-dir: base-dir/red-system
;; set the red/system runnable dir
runnable-dir: join comp-dir "tests/runnable/"
runnable-dir: comp-dir/tests/runnable
;; set the builds dir
builds-dir: join comp-dir "builds/"
builds-dir: comp-dir/builds
;; set the default base dir for tests
tests-dir: join comp-dir "tests/"
tests-dir: comp-dir/tests

;; set the version number
version: system/script/header/version

;; set temporary files names
;; use Red/red-system/runnable for temp files
comp-echo: join runnable-dir %comp-echo.txt
comp-r: join runnable-dir %comp.r
test-src-file: join %runnable/ "qt-test-comp.reds"
comp-echo: runnable-dir/comp-echo.txt
comp-r: runnable-dir/comp.r
test-src-file: runnable-dir/qt-test-comp.reds

;; set log file
log-file: join system/script/path "quick-test.log"
Expand Down Expand Up @@ -150,7 +150,8 @@ qt: make object! [
echo (comp-echo)
do/args %rsc.r "***src***"
]
replace comp "***src***" join tests-dir src
if #"/" <> first src [src: tests-dir/:src] ;; relative path supplied
replace comp "***src***" src
write comp-r comp

;; compose command line and call it
Expand All @@ -165,8 +166,8 @@ qt: make object! [
if exists? comp-r [delete comp-r]

;; move the executable from /builds to /tests/runnable
built: join builds-dir [exe]
runner: join runnable-dir [exe]
built: builds-dir/:exe
runner: runnable-dir/:exe

if exists? built [
write/binary runner read/binary built
Expand Down Expand Up @@ -212,7 +213,6 @@ qt: make object! [
compile-from-string: func [src][
;-- add a default header if not provided
if none = find src "Red/System" [insert src "Red/System []^/"]

write test-src-file src
compile test-src-file ;; returns path to executable or none
]
Expand Down Expand Up @@ -242,7 +242,7 @@ qt: make object! [
/local
exec [string!] ;; command to be executed
][
exec: to-local-file join runnable-dir [prog]
exec: to-local-file runnable-dir/:prog
;;exec: join "" compose/deep [(exec either args [join " " parms] [""])]
clear output
call/output/wait exec output
Expand Down Expand Up @@ -279,9 +279,8 @@ qt: make object! [
filename ;; filename of script
script ;; %runnable/filename
][
src: replace/all src "%" ""
if not filename: copy find/last/tail src "/" [filename: copy src]
script: join runnable-dir [filename]
script: runnable-dir/:filename
write to file! script read join tests-dir [src]
do script
]
Expand Down
45 changes: 45 additions & 0 deletions quick-test/run-test.r
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
REBOL [
Title: "Builds and Runs a single Red/System Tests"
File: %run-test.r
Author: "Peter W A Wood"
Version: 0.7.0
License: "BSD-3 - https://github.com/dockimbel/Red/blob/master/BSD-3-License.txt"
]


;; include quick-test.r
do %quick-test.r

;; set the base dir for the test source
qt/tests-dir: system/options/path

print rejoin ["Quick-Test v" system/script/header/version]
print rejoin ["Running under REBOL " system/version]

;; get the name of the test file
src: system/script/args

either any [
(not find src ".r") and (not find src ".reds")
not src: to-file src
][
print "No valid test file supplied"
][
print ["run-test src " src]
either find src ".reds" [
;; compile & run reds pgm
either exe: qt/compile src [
qt/run exe
print qt/output
][
print "Compile Error!!!"
print qt/comp-output
]
][
;; copy and run rebol script
qt/run-script src
]
]

prin ""

0 comments on commit 5c61a62

Please sign in to comment.