Skip to content

Commit

Permalink
Bump to 0.12.0: sam assert lib (very basic)
Browse files Browse the repository at this point in the history
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 :)
  • Loading branch information
fasterthanlime committed Jul 8, 2015
1 parent d88735e commit d345383
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 4 deletions.
4 changes: 4 additions & 0 deletions sam-assert.use
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Name: sam-assert
Description: Sam's simple assert library makes some tests shorter
SourcePath: source
Imports: sam/assert
2 changes: 1 addition & 1 deletion sam.use
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion source/sam.ooc
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Sam: class {

args: Arguments
home ::= args home
VERSION := "0.11.0"
VERSION := "0.12.0"

init: func

Expand Down
13 changes: 11 additions & 2 deletions source/sam/TestSuite.ooc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down
20 changes: 20 additions & 0 deletions source/sam/assert.ooc
Original file line number Diff line number Diff line change
@@ -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()
}

0 comments on commit d345383

Please sign in to comment.