From d3453837675b95bbd5867e32fc64377228f461aa Mon Sep 17 00:00:00 2001 From: Amos Wenger Date: Wed, 8 Jul 2015 11:47:46 +0200 Subject: [PATCH] Bump to 0.12.0: sam assert lib (very basic) Use 'describe' to describe a particular suite, use 'expect' to compare strings or ints, will print an error message and exit(1) if it fails, do nothing otherwise. Prints 'Pass' after each describe block works successfully. Could be a lot more sophisticated, but better keep it simple, since it's used to test rock itself :) --- sam-assert.use | 4 ++++ sam.use | 2 +- source/sam.ooc | 2 +- source/sam/TestSuite.ooc | 13 +++++++++++-- source/sam/assert.ooc | 20 ++++++++++++++++++++ 5 files changed, 37 insertions(+), 4 deletions(-) create mode 100644 sam-assert.use create mode 100644 source/sam/assert.ooc diff --git a/sam-assert.use b/sam-assert.use new file mode 100644 index 0000000..e513599 --- /dev/null +++ b/sam-assert.use @@ -0,0 +1,4 @@ +Name: sam-assert +Description: Sam's simple assert library makes some tests shorter +SourcePath: source +Imports: sam/assert diff --git a/sam.use b/sam.use index 7adb2ee..c2698ba 100644 --- a/sam.use +++ b/sam.use @@ -1,4 +1,4 @@ Name: sam -Description: Sam keeps your ooc repos up to date +Description: Sam keeps your ooc repos up to date and runs your tests SourcePath: source Main: sam.ooc diff --git a/source/sam.ooc b/source/sam.ooc index 814e18d..c273b43 100644 --- a/source/sam.ooc +++ b/source/sam.ooc @@ -24,7 +24,7 @@ Sam: class { args: Arguments home ::= args home - VERSION := "0.11.0" + VERSION := "0.12.0" init: func diff --git a/source/sam/TestSuite.ooc b/source/sam/TestSuite.ooc index 50b5809..96c33ca 100644 --- a/source/sam/TestSuite.ooc +++ b/source/sam/TestSuite.ooc @@ -250,11 +250,20 @@ TestCase: class { } compile: func { + // Write the test file to disk with sam builtins in front + testOoc := File new(suite cacheDir, oocFile name) + testOoc write( +"// added by sam +use sam-assert + +#{oocFile read()}" + ) + // Write out an ad-hoc .use file testUse := File new(suite cacheDir, "test.use") testUse write( - "SourcePath: %s\n" format(oocFile parent path) + - "Main: %s\n" format(oocFile name) + + "SourcePath: %s\n" format(suite cacheDir path) + + "Main: %s\n" format(testOoc name) + "BinaryPath: test\n" ) diff --git a/source/sam/assert.ooc b/source/sam/assert.ooc new file mode 100644 index 0000000..21c7615 --- /dev/null +++ b/source/sam/assert.ooc @@ -0,0 +1,20 @@ + +expect: func ~str (given: String, expected: String) { + if (given != expected) { + "Fail! given #{given}, expected #{expected}" + exit(1) + } +} + +expect: func ~int (given: Int, expected: Int) { + if (given != expected) { + "Fail! given #{given}, expected #{expected}" + exit(1) + } +} + +describe: func (name: String, body: Func) { + body() + "Pass: #{name}" println() +} +