Skip to content

Commit

Permalink
TESTS: added trivial float tests to print-test.r & added new assertio…
Browse files Browse the repository at this point in the history
…n - assert-printed? to quick-test.r
  • Loading branch information
PeterWAWood committed Feb 27, 2012
1 parent 7fed80e commit 4437311
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 12 deletions.
23 changes: 19 additions & 4 deletions quick-test/quick-test.r
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ qt: make object! [
comp-output: copy "" ;; output captured from compile
output: copy "" ;; output captured from pgm exec
exe: none ;; filepath to executable
reds-file?: true ;; true = running reds test file
;; false = runnning test script

summary-template: ".. - .................................... / "

Expand Down Expand Up @@ -187,6 +189,7 @@ qt: make object! [
]

compile-and-run: func [src] [
reds-file?: true
either exe: compile src [
run exe
][
Expand All @@ -196,9 +199,11 @@ qt: make object! [
]

compile-and-run-from-string: func [src] [
reds-file?: false
either exe: compile-from-string src [
run exe
][

compile-error "Supplied source"
output: "Compilation failed"
]
Expand All @@ -217,7 +222,7 @@ qt: make object! [
][
print join "" [src " - compiler error"]
print comp-output
clear output ;; clear the ouptut from prevous test
clear output ;; clear the ouptut from previous test
_signify-failure
]

Expand All @@ -241,8 +246,11 @@ qt: make object! [
;;exec: join "" compose/deep [(exec either args [join " " parms] [""])]
clear output
call/output/wait exec output
if none <> find output "Runtime Error" [
_signify-failure
if all [
reds-file?
none <> find output "Runtime Error"
][
_signify-failure
]
]

Expand All @@ -252,6 +260,7 @@ qt: make object! [
cmd ;; command to run
test-name
][
reds-file?: true
test-name: find/last/tail src "/"
test-name: copy/part test-name find test-name "."
print [ "running " test-name #"^(0D)"]
Expand All @@ -277,7 +286,7 @@ qt: make object! [
do script
]

;; This is for the temporary version of quick-test.red (in REBOL)
;; This is for quick-unit-test.r (in REBOL)
run-script-quiet: func [src [file!]][
prin [ "running " find/last/tail src "/" #"^(0D)"]
print: :_quiet-print
Expand Down Expand Up @@ -311,6 +320,7 @@ qt: make object! [
add-to-run-totals: func [
/local
tests

asserts
passes
failures
Expand Down Expand Up @@ -410,6 +420,10 @@ qt: make object! [
assert found? find qt/comp-output msg
]

assert-printed?: func [msg] [
assert found? find qt/output msg
]

clean-compile-from-string: does [
if exists? test-src-file [delete test-src-file]
if all [exe exists? exe][delete exe]
Expand Down Expand Up @@ -496,6 +510,7 @@ qt: make object! [
set '--run-test-file-quiet :run-test-file-quiet
set '--assert :assert
set '--assert-msg? :assert-msg?
set '--assert-printed? :assert-printed?
set '--clean :clean-compile-from-string
set '===end-group=== :end-group
set '~~~end-file~~~ :end-file
Expand Down
28 changes: 20 additions & 8 deletions red-system/tests/source/compiler/print-test.r
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,29 @@ REBOL [
License: "BSD-3 - https://github.com/dockimbel/Red/blob/master/BSD-3-License.txt"
]

change-dir %../ ;; revert to tests/ directory from runnable/
change-dir %../ ;; revert to tests/ directory from runnable/

~~~start-file~~~ "print"

--test-- "p1"
--compile-and-run-this {
a: as-byte 1
b: as-byte 2
print as byte-ptr! (as-integer b) << 16 or as-integer a
print lf
}
--assert found? find qt/output "20001"
--compile-and-run-this {
a: as-byte 1
b: as-byte 2
print as byte-ptr! (as-integer b) << 16 or as-integer a
print lf
}
--assert-printed? "20001"

--test-- "p2"
--compile-and-run-this {
print [1.0 lf]
}
--assert-printed? "1.0"

--test-- "p3"
--compile-and-run-this {
print [as-float32 1.0 lf]
}
--assert-printed? "1.0"

~~~end-file~~~

0 comments on commit 4437311

Please sign in to comment.