Skip to content

Commit

Permalink
Merge pull request #4 from mockagne/bugfix/3-Lua_5.3_compatibiliy_wit…
Browse files Browse the repository at this point in the history
…h_unpack

#3: Lua 5.3 fix for unpack()
  • Loading branch information
vertti committed Sep 3, 2020
2 parents 116a84d + 98fdaa5 commit 7240622
Show file tree
Hide file tree
Showing 15 changed files with 496 additions and 366 deletions.
6 changes: 6 additions & 0 deletions .buildpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<buildpath>
<buildpathentry kind="src" path="test"/>
<buildpathentry kind="src" path="src"/>
<buildpathentry kind="con" path="org.eclipse.ldt.ExecutionEnvironmentContainer/lua/5.1"/>
</buildpath>
17 changes: 17 additions & 0 deletions .project
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>mockagne</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.dltk.core.scriptbuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.ldt.nature</nature>
</natures>
</projectDescription>
2 changes: 2 additions & 0 deletions .settings/org.eclipse.ldt.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Grammar__default_id=lua-5.1
eclipse.preferences.version=1
22 changes: 22 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
dist: focal

language: c

sudo: required

os: linux

env:
- LUA_VERSION=5.1
- LUA_VERSION=5.2
- LUA_VERSION=5.3

before_script:
- sudo apt-get -y install lua$LUA_VERSION
- sudo apt-get -y install liblua$LUA_VERSION-dev
- sudo apt-get -y install luarocks
- sudo luarocks install busted

script:
- sudo luarocks make
- busted test
1 change: 1 addition & 0 deletions LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ MIT License Terms
=================

Copyright (c) 2013 Punch Wolf Game Studios.
Copyright (c) 2019 Exasol.

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
Expand Down
77 changes: 23 additions & 54 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,70 +1,39 @@
mockagne
========
# mockagne - Mocking Framework for Lua

Fully dynamic mocking for Lua. Create mock objects with ease, teach them to return values and verify their invocations.
`mockagne` is a fully dynamic mocking framework that is designed to be a Lua variant of the famous Java framework [mockito](https://site.mockito.org/).

## Usage
### Creating and using mocks
Start by requiring mockagne and creating some local function references for better readability:
## In a Nutshell

```lua
local mockagne = require "mockagne"

local when = mockagne.when
local any = mockagne.any
local verify = mockagne.verify
```

Then just create a mock instance for you:

```lua
t = mockagne.getMock()
local mockagne = require("mockagne")
local mock = mockagne.getMock()
mockagne.when(mock.say(mockagne.any())).thenAnswer("Hello world")
-- ...
mock.ask("You name?")
mockagne.verify(mock.ask("You name?"))
```

Then you can invoke anything on the mock instance. Like:
## Information for Users

```lua
t.foo()
```

### Verifying calls to mocks
After your test has executed, you might be interested if a specific function on a mock was called. For example, to check if function `foo()` was call, you would simply say:

```lua
verify(t.foo())
```

Same works with parameters:

```lua
t.foo("bar")
verify(t.foo("bar"))
```

### Returning values from mocks
If you want a call to `t.foo()` to return a value, you can teach the mock with:

```lua
when(t.foo("bar")).thenAnswer("baz")
print(t.foo("bar")) -- this will print "baz"
```
* [User Guide](doc/user_guide/user_guide.md)

Otherwise calls to mock methods will return `nil`.
## Dependencies

### More examples
For more examples, refer to [`mockagne_spec.lua`](spec/mockagne_spec.lua) that comes with. It contains all unit tests used to exercise mockagnes all features.
### Runtime Dependencies

## Installation
`mockagne` is a single-file pure-Lua module with no other runtime dependencies than Lua 5.1 or later.

Easiest way to install `mockagne` is through `luarocks`. Just run
### Test Dependencies

luarocks install mockagne
| Dependency | Purpose | License |
|------------------------------------------|--------------------------------------------------------|-------------------------------|
| [busted][busted] | Unit testing framework | MIT License |

For manual installation, just add `mockagne.lua` to your `package.path`.
[busted]: https://github.com/Olivine-Labs/busted

## More information
### License

_Mockagne_ was originally written by Janne Sinivirta and Marko Pukari. It was created to help with testing of our mobile games written in Lua. It is now maintained by
Sebastian Bär.
Lua is Open Source, distributed under the terms of the [MIT license](License).

_Mockagne_ name is a cross between _mock_ and _champagne_, like it's Java big brother _mockito_. We are great fans of _mockito_ and mockagne is heavily based on _mockito_'s DSL.
Copyright (c) 2013 Punch Wolf Game Studios.
Copyright (c) 2020 [Exasol](https://www.exasol.com).
5 changes: 5 additions & 0 deletions doc/changes/changelog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Changes

* [1.0.2](changes_1.0.2)
* [1.0.1](changes_1.0.1)
* [1.0.0](changes_1.0.0)
11 changes: 11 additions & 0 deletions doc/changes/changes_1.0.0.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# mockange 1.0.0, released 2013-07-13

Code name: First Release

## Features

* Added basic mocking

## Documentation

* Added basic user guide
11 changes: 11 additions & 0 deletions doc/changes/changes_1.0.1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# mockagne 1.0.1, released 2013-07-13

Code name: Support for `nil` primitive fields

## Features

* Added support

## Documentation

* Improved user guide
16 changes: 16 additions & 0 deletions doc/changes/changes_1.0.2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# mockagne 1.0.2, released 2020-09-03

Code name: Resurrection

## Summary

After an extended break starting 2013, with this release `mockagne` is now maintained again.
We added compatibility for Lua 5.3, improved the project structure and added CI builds.

## Bug Fixes

* #3: Fixed Lua 5.3 incompatibility caused by global `unpack()`

## Documentation

* #3: Added change log, restructured documentation.
67 changes: 67 additions & 0 deletions doc/user_guide/user_guide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# User Guid &mdash; `mockagne`

## Introduction

_Mockagne_ was originally written by Janne Sinivirta and Marko Pukari. It was created to help with testing of our mobile games written in Lua. It is now maintained by Sebastian Bär.

_Mockagne_ name is a cross between _mock_ and _champagne_, like it's Java big brother _mockito_. We are great fans of _mockito_ and mockagne is heavily based on _mockito_'s DSL.

## Using `mockagne`

### Creating and using mocks
Start by requiring mockagne and creating some local function references for better readability:

```lua
local mockagne = require "mockagne"

local when = mockagne.when
local any = mockagne.any
local verify = mockagne.verify
```

Then just create a mock instance for you:

```lua
t = mockagne.getMock()
```

Then you can invoke anything on the mock instance. Like:

```lua
t.foo()
```

### Verifying calls to mocks
After your test has executed, you might be interested if a specific function on a mock was called. For example, to check if function `foo()` was call, you would simply say:

```lua
verify(t.foo())
```

Same works with parameters:

```lua
t.foo("bar")
verify(t.foo("bar"))
```

### Returning values from mocks
If you want a call to `t.foo()` to return a value, you can teach the mock with:

```lua
when(t.foo("bar")).thenAnswer("baz")
print(t.foo("bar")) -- this will print "baz"
```

Otherwise calls to mock methods will return `nil`.

### More examples
For more examples, refer to [`mockagne_spec.lua`](spec/mockagne_spec.lua) that comes with. It contains all unit tests used to exercise mockagnes all features.

## Installation

Easiest way to install `mockagne` is through `luarocks`. Just run

luarocks install mockagne

For manual installation, just add `mockagne.lua` to your `package.path`.
18 changes: 9 additions & 9 deletions mockagne-1.0-2.rockspec
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
package = "Mockagne"
version = "1.0-2"

source = {
url = "https://github.com/PunchWolf/mockagne/releases/download/v.1.0.2/mockagne-1.0.tar.gz",
dir = "mockagne-1.0"
url = "https://github.com/PunchWolf/mockagne",
tag = "1.0.2"
}

description = {
summary = "Fully dynamic mocking for Lua.",
detailed = [[
Fully dynamic mocking for Lua. Create mock objects with ease,
teach them to return values and verify their invocations.
]],
homepage = "https://github.com/PunchWolf/mockagne",
homepage = "https://github.com/mockagne/mockagne",
license = "MIT"
}
dependencies = {
"lua >= 5.1"
}

dependencies = { "lua >= 5.1, <= 5.4" }
build = {
type = "builtin",
modules = {
mockagne = "mockagne.lua"
}
modules = {mockagne = "src/mockagne.lua"},
copy_directories = { "doc", "test" }
}

0 comments on commit 7240622

Please sign in to comment.