Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update for Lasso 9.3 #6

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,18 @@ Installation
### Pre-compiled Libraries

1. Click the "Downloads" menu option at the top of this page.
2. Choose the proper download for your platform
3. Decompress the files and move lspec to `$LASSO9_HOME/bin/` and lspec.so or lspec.dylib into `$LASSO9_HOME/LassoLibraries/`
2. Choose the proper download for your platform.
3. Decompress the files and move lspec to `$LASSO9_HOME/bin/` and lspec.so or lspec.dylib into `$LASSO9_HOME/LassoLibraries/`.

### Compile From Source

$> cd where/you/want/the/source/installed/
$> git clone https://bitbucket.org/bfad/lspec.git
$> git clone https://github.com/bfad/lspec.git
$> cd lspec
$> make
$> make install

_Note: If you're compiling on Mac OS X, you'll need the 10.5 SDK installed. You can follow the instructions [here](http://hints.macworld.com/article.php?story=20110318050811544) to restore the 10.5 SDK to Xcode 4._
_Note: If you're compiling on Mac OS X, you'll need the 10.5 SDK installed to build a library for all supported versions. You can follow [these instructions](https://github.com/devernay/xcodelegacy) to restore the 10.5 SDK to Xcode 4 and later._

### Set Your Path

Expand All @@ -50,16 +50,16 @@ First, create a file named zoo.spec.inc and write a test describing functionalit
local(menagerie) = zoo
local(num_animals_start) = #menagerie->numberOfAnimals
local(num_animals_end)

#menagerie->addAnimal(animal('Rhino'))
#num_animals_end = #menagerie->numberOfAnimals

expect(#menagerie->hasA('Rhino'))
expect(#num_animals_end == 1 + #num_animals_start)
}
}
}

Then run the test and watch it fail.

$> lspec zoo.spec.inc
Expand All @@ -68,7 +68,7 @@ Then run the test and watch it fail.
Failures:

1) Zoo addAnimal inserts an animal into the zoo and increases numberOfAnimals by 1
Failure/Error: Unexpcted Error!
Failure/Error: Unexpected Error!
Error Code: -9948
Error Msg: Definition Not Found: zoo()
# 3:9 /Path/To/zoo.spec.inc
Expand All @@ -77,7 +77,7 @@ Then run the test and watch it fail.
1 test, 1 failure

Now add the following code to the beginning of zoo.spec.inc. (Usually you would keep the tests in separate files and have them first include the code you are testing.)

define zoo => type {
data private animals = array

Expand Down Expand Up @@ -129,4 +129,4 @@ Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
limitations under the License.
28 changes: 17 additions & 11 deletions command/lspec
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
#!/usr/bin/lasso9
#!/usr/bin/env lasso9

define usage(exit_status::integer=-1) => {
local(cmd) = $argv->get(1)->lastComponent
stdoutnl("\
usage: " + #cmd + " [options] [file or director paths]
usage: " + #cmd + " [options] [file or directory paths]

The " + #cmd + " command executes the Lasso code in the specified file or
all Lasso files in the specified directory. If no file or directory path is
all Lasso files in the specified directory. If no file or directory path is
specified, then it tries a relative directory named \"spec\".

When a directory is specified (or when using the default \"spec\" directory),
the command executes all files ending in \".spec.inc\" in that directory. Then
the command executes all files ending in \".spec.inc\" in that directory. Then
it proceeds to do the same thing in any nested directories. (To specify what
extensions are considered Lasso files, see the \"-exts\" option.)

Options
-------
-documentation
Output just the group and test descriptions
Output just the group and test descriptions.

-exts CSV_EXT_LIST
Allows for specifying a comma-separated list of file extensions to be
Expand All @@ -28,7 +28,7 @@ Options
Don't use terminal colors for the output.

-h
Displays this help and exits"
Displays this help and exits."
)
sys_exit(#exit_status)
}
Expand All @@ -45,7 +45,13 @@ define lspec_runDir(d::dir, ext::staticarray=(:'inc')) => {
}

define lspec_runFile(f::file) => {
sourcefile(#f, -autoCollect=false)->invoke
protect => {
handle_failure => {
error_code != error_code_aborted ?
stdoutnl('\nError Code: ' + error_code + '\nError Msg: ' + error_msg + '\nError Stack:\n\n' + error_stack + '\n')
}
sourcefile(#f, -autoCollect=false)->invoke
}
}

// Defaults
Expand All @@ -71,7 +77,7 @@ while(#opts->size > 0) => {
? usage

#exts = #opts->get(2)->split(',')->asStaticArray
// Since we're deaing with the next item, delete one now (we delete the other later)
// Since we're dealing with the next item, delete one now (we delete the other later)
#opts->remove(1,1)

case
Expand All @@ -87,15 +93,15 @@ lspec->formatResults(#mode)

#use_color? lspec->useColor

with path in #paths
with path in #paths
let f = file(#path)
do {
if(not #f->exists) => {
file_stderr->writeString(error_code_resNotFound + ':' + error_msg_resNotFound + ' - ' + #path)
file_stderr->writeString(error_code_resNotFound + ':' + error_msg_resNotFound + ' - ' + #path + sys_eol)
sys_exit(1)
}
#f->isDir? lspec_runDir(dir(#path), #exts)
| lspec_runFile(#f)
}

lspec->stop
lspec->stop
74 changes: 36 additions & 38 deletions lspec.inc
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ define error_code_lspecTestGroupInTest => 102
define error_msg_lspecTestGroupInTest => "The test group is in a test block"

define error_code_lspecStopInTestGroup => 103
define error_msg_lspecStopInTestGroup => "Can not stop while in a test group"
define error_msg_lspecStopInTestGroup => "Cannot stop while in a test group"

define error_code_lspecInvalidResultFormat => 104
define error_msg_lspecInvalidResultFormat => "You have specified an invalid result format"
Expand All @@ -48,7 +48,7 @@ define error_code_lspecTestGroupHasBeforeAll => 107
define error_msg_lspecTestGroupHasBeforeAll => "You have already specified a [beforeAll] block"

define error_code_lspecTestGroupHasAfterAll => 108
define error_msg_lspecTestGroupHasAfterAll => "You have already specified a [afterAll] block"
define error_msg_lspecTestGroupHasAfterAll => "You have already specified an [afterAll] block"


define lspec_testSuite => type {
Expand Down Expand Up @@ -110,12 +110,12 @@ define lspec_testSuite => type {
'resultsFormat' = "p",
'indentor' = " ",
'suppressOutput' = false,
'colorOutput' = false,
'colorOutput' = false,
)
// Configuration Options Setters & Getters
public options => .'options'
public setOptions(new::map) => {
with key in .'options'->keys
with key in .'options'->keys
do {
#new->contains(#key)? .'options'->find(#key) = #new->find(#key)
}
Expand All @@ -126,34 +126,33 @@ define lspec_testSuite => type {
public isOutputSuppressed => .options->find('suppressOutput'),
suppressOutput => { .options->find('suppressOutput') = true },
showOutput => { .options->find('suppressOutput') = false }
public isOutputInColor => .options->find(`colorOutput`),
noColor => { .options->find(`colorOutput`) = false },
useColor => { .options->find(`colorOutput`) = true }

public isOutputInColor => .options->find(`colorOutput`),
noColor => { .options->find(`colorOutput`) = false },
useColor => { .options->find(`colorOutput`) = true }

public resultsFormat => .options->find('resultsFormat')
public formatResults(new::string) => {
fail_if(not .validFormats->contains(#new),
fail_if(not .validFormats->contains(#new),
error_code_lspecInvalidResultFormat, error_msg_lspecInvalidResultFormat)
.options->find('resultsFormat') = #new
}

// Color Stuff
data terminalColors = map(
`normal` = decode_base64('Gw==') + '[0m',
`boldRed` = decode_base64('Gw==') + '[1;31;49m',
`boldGreen` = decode_base64('Gw==') + '[1;32;49m',
`boldYellow` = decode_base64('Gw==') + '[1;33;49m',
`boldCyan` = decode_base64('Gw==') + '[1;36;49m',
)
public outputColor(color::string) => {
not .isOutputInColor
? return ''

return string(.'terminalColors'->get(#color))
}


// Color Stuff
data terminalColors = map(
`normal` = decode_base64('Gw==') + '[0m',
`boldRed` = decode_base64('Gw==') + '[1;31;49m',
`boldGreen` = decode_base64('Gw==') + '[1;32;49m',
`boldYellow` = decode_base64('Gw==') + '[1;33;49m',
`boldCyan` = decode_base64('Gw==') + '[1;36;49m',
)
public outputColor(color::string) => {
not .isOutputInColor? return ''

return string(.'terminalColors'->get(#color))
}


// Code to add test stuff to lspec test suite
public addTestGroup(tg::lspec_testGroup) => {
fail_if(.inTest, error_code_lspecTestGroupInTest, error_msg_lspecTestGroupInTest)
Expand All @@ -180,7 +179,6 @@ define lspec_testSuite => type {
}
public addBeforeEach(block::capture) => {
fail_if(not .inTestGroup, error_code_lspecNotInTestGroup, error_msg_lspecNotInTestGroup)

.getCurrentTestGroup->beforeEach(#block)
}
public addAfterAll(block::capture) => {
Expand All @@ -189,7 +187,6 @@ define lspec_testSuite => type {
}
public addAfterEach(block::capture) => {
fail_if(not .inTestGroup, error_code_lspecNotInTestGroup, error_msg_lspecNotInTestGroup)

.getCurrentTestGroup->afterEach(#block)
}

Expand Down Expand Up @@ -243,13 +240,13 @@ define lspec_testSuite => type {
.numFailures++

local(spacer) = ' ' * (.numFailures->asString->size + 2)
local(location) = (not #error ? #test->failedTestCase->location | #test->location)
local(location) = (not #error? #test->failedTestCase->location | #test->location)
local(line_num) = integer(#location->first->split(':')->first)
local(col_num) = integer(#location->first->split(':')->second)
local(code)

if(#error) => {
#code = 'Unexpcted Error!'
#code = 'Unexpected Error!'
else
local(f) = file(#location->second, file_openRead, file_modeLine)
#f->doWithClose => {
Expand Down Expand Up @@ -282,7 +279,8 @@ define lspec_testSuite => type {
'p' == .resultsFormat? return

local(out) = (.indentor * .currentDepth) + #tg->label
.result != '' ? #out = '\n' + #out
.result != ''
? #out = '\n' + #out
.output(#out)
}
public output(test::lspec_test) => {
Expand Down Expand Up @@ -321,7 +319,7 @@ define lspec_testSuite => type {
/*
* Wrapper for the test suite.
* This allows us to create one universal test suite object per thread. All
* subsequent methods use this object, and so should users when necessary
* subsequent methods use this object, and so should users when necessary.
*/
define lspec => var(_lspec) || $_lspec := lspec_testSuite

Expand Down Expand Up @@ -417,7 +415,6 @@ define lspec_testGroup => type {
.currentTest = 0
.tests->forEach => {
.currentTest++

.parentSuite->runCurrentBeforeEach
#1->run
.runAfterEaches
Expand All @@ -427,7 +424,7 @@ define lspec_testGroup => type {
.currentGroup++
.parentSuite->incGroupDepth
#1->parentGroup = self
#1->run
#1->run
.parentSuite->decGroupDepth
}
}
Expand All @@ -450,7 +447,7 @@ define lspec_test => type {
location => .'location',
failedTestCase => .'failedTestCase'
// Setters
public failed(test_case::expect) => {
public failed(test_case::expect) => {
.status = 'fail'
.failedTestCase = #test_case
}
Expand Down Expand Up @@ -590,7 +587,7 @@ define expect => type {
}

/*
* This expect statement expects a null value to be passed into it
* This expect statement expects a null value to be passed into it.
*/
define expect->null(value) => {
not #value->isA(::null)?
Expand Down Expand Up @@ -681,7 +678,7 @@ define expect->errorMsg(msg::string) => {
*/
define expect->error => {
fail_if(not givenBlock,
error_code_missingGivenBlock, error_msg_missingGivenBlock)
error_code_missingGivenBlock, error_msg_missingGivenBlock)

local(my_error) = pair(error_code_noerror=error_msg_noerror)
protect => {
Expand Down Expand Up @@ -720,5 +717,6 @@ define expect->stdout(expected::string) => {

local(did_read) = #read_test->readString

#did_read != #expected? .fail(#expected, #did_read)
}
#did_read != #expected
? .fail(#expected, #did_read)
}
4 changes: 2 additions & 2 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ CC = gcc
KERNEL_NAME = $(shell uname -s)

OSX_DEPLOY_VERS = 10.5
SDK = /Developer/SDKs/MacOSX$(OSX_DEPLOY_VERS).sdk
SDK = $(shell xcodebuild -version -sdk macosx Path)

ifeq ($(DEBUG),1)

Expand Down Expand Up @@ -32,7 +32,7 @@ Linux_DLL_EXT = .so

DLL_EXT = $($(KERNEL_NAME)_DLL_EXT)

LASSO9_MODULE_CMD = /usr/bin/lassoc
LASSO9_MODULE_CMD = $(shell which lassoc)

C_FLAGS = $(DEBUG_FLAGS) -fPIC
LN_FLAGS = $(DEBUG_FLAGS) $($(KERNEL_NAME)_LN_FLAGS)
Expand Down
Loading