Skip to content

Commit 6a3a5e5

Browse files
committed
add Travis CI
1 parent cd7ae3b commit 6a3a5e5

File tree

15 files changed

+583
-241
lines changed

15 files changed

+583
-241
lines changed

.luacheckrc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
-- vim: ft=lua
2+
3+
include_files = {"src", "spec/*.lua", "scripts/*.lua", "*.rockspec", "*.luacheckrc"}
4+
std = "max"
5+
stds.busted_patch = {
6+
read_globals = { "randomize" }
7+
}
8+
9+
files["spec/*.lua"].std = "+busted+busted_patch"
10+
ignore = {"432"}

.travis.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
language: c
2+
3+
sudo: required
4+
5+
branches:
6+
only:
7+
- travis_ci
8+
- master
9+
10+
env:
11+
global:
12+
- LUAROCKS=3.0.4
13+
matrix:
14+
- LUA=lua5.1
15+
- LUA=lua5.2
16+
- LUA=lua5.3
17+
18+
before_install:
19+
- source .travis/setenv_lua.sh
20+
21+
script:
22+
make test

.travis/platform.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
if [ -z "${PLATFORM:-}" ]; then
2+
PLATFORM=$TRAVIS_OS_NAME;
3+
fi
4+
5+
if [ "$PLATFORM" == "osx" ]; then
6+
PLATFORM="macosx";
7+
fi
8+
9+
if [ -z "$PLATFORM" ]; then
10+
if [ "$(uname)" == "Linux" ]; then
11+
PLATFORM="linux";
12+
else
13+
PLATFORM="macosx";
14+
fi;
15+
fi

.travis/setenv_lua.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export PATH=${PATH}:$HOME/.lua:$HOME/.local/bin:${TRAVIS_BUILD_DIR}/install/luarocks/bin
2+
bash .travis/setup_lua.sh
3+
eval $($HOME/.lua/luarocks path)

.travis/setup_lua.sh

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
#! /bin/bash
2+
3+
# A script for setting up environment for travis-ci testing.
4+
# Sets up Lua and Luarocks.
5+
# LUA must be "lua5.1", "lua5.2" or "luajit".
6+
# luajit2.0 - master v2.0
7+
# luajit2.1 - master v2.1
8+
9+
set -eufo pipefail
10+
11+
LUAJIT_VERSION="2.0.5"
12+
LUAJIT_BASE="LuaJIT-$LUAJIT_VERSION"
13+
14+
source .travis/platform.sh
15+
16+
LUA_HOME_DIR=$TRAVIS_BUILD_DIR/install/lua
17+
18+
LR_HOME_DIR=$TRAVIS_BUILD_DIR/install/luarocks
19+
20+
mkdir $HOME/.lua
21+
22+
LUAJIT="no"
23+
24+
if [ "$PLATFORM" == "macosx" ]; then
25+
if [ "$LUA" == "luajit" ]; then
26+
LUAJIT="yes";
27+
fi
28+
if [ "$LUA" == "luajit2.0" ]; then
29+
LUAJIT="yes";
30+
fi
31+
if [ "$LUA" == "luajit2.1" ]; then
32+
LUAJIT="yes";
33+
fi;
34+
elif [ "$(expr substr $LUA 1 6)" == "luajit" ]; then
35+
LUAJIT="yes";
36+
fi
37+
38+
mkdir -p "$LUA_HOME_DIR"
39+
40+
if [ "$LUAJIT" == "yes" ]; then
41+
42+
if [ "$LUA" == "luajit" ]; then
43+
curl --location https://github.com/LuaJIT/LuaJIT/archive/v$LUAJIT_VERSION.tar.gz | tar xz;
44+
else
45+
git clone https://github.com/LuaJIT/LuaJIT.git $LUAJIT_BASE;
46+
fi
47+
48+
cd $LUAJIT_BASE
49+
50+
if [ "$LUA" == "luajit2.1" ]; then
51+
git checkout v2.1;
52+
# force the INSTALL_TNAME to be luajit
53+
perl -i -pe 's/INSTALL_TNAME=.+/INSTALL_TNAME= luajit/' Makefile
54+
fi
55+
56+
make && make install PREFIX="$LUA_HOME_DIR"
57+
58+
ln -s $LUA_HOME_DIR/bin/luajit $HOME/.lua/luajit
59+
ln -s $LUA_HOME_DIR/bin/luajit $HOME/.lua/lua;
60+
61+
else
62+
63+
if [ "$LUA" == "lua5.1" ]; then
64+
curl http://www.lua.org/ftp/lua-5.1.5.tar.gz | tar xz
65+
cd lua-5.1.5;
66+
elif [ "$LUA" == "lua5.2" ]; then
67+
curl http://www.lua.org/ftp/lua-5.2.4.tar.gz | tar xz
68+
cd lua-5.2.4;
69+
elif [ "$LUA" == "lua5.3" ]; then
70+
curl http://www.lua.org/ftp/lua-5.3.2.tar.gz | tar xz
71+
cd lua-5.3.2;
72+
fi
73+
74+
# Build Lua without backwards compatibility for testing
75+
perl -i -pe 's/-DLUA_COMPAT_(ALL|5_2)/-DLUA_COMPAT_5_2 -DLUA_COMPAT_5_1 -DLUA_COMPAT_ALL/' src/Makefile
76+
make $PLATFORM
77+
make INSTALL_TOP="$LUA_HOME_DIR" install;
78+
79+
ln -s $LUA_HOME_DIR/bin/lua $HOME/.lua/lua
80+
ln -s $LUA_HOME_DIR/bin/luac $HOME/.lua/luac;
81+
82+
fi
83+
84+
cd $TRAVIS_BUILD_DIR
85+
86+
lua -v
87+
88+
LUAROCKS_BASE=luarocks-$LUAROCKS
89+
90+
curl --location http://luarocks.org/releases/$LUAROCKS_BASE.tar.gz | tar xz
91+
92+
cd $LUAROCKS_BASE
93+
94+
if [ "$LUA" == "luajit" ]; then
95+
./configure --lua-suffix=jit --with-lua-include="$LUA_HOME_DIR/include/luajit-2.0" --prefix="$LR_HOME_DIR";
96+
elif [ "$LUA" == "luajit2.0" ]; then
97+
./configure --lua-suffix=jit --with-lua-include="$LUA_HOME_DIR/include/luajit-2.0" --prefix="$LR_HOME_DIR";
98+
elif [ "$LUA" == "luajit2.1" ]; then
99+
./configure --lua-suffix=jit --with-lua-include="$LUA_HOME_DIR/include/luajit-2.1" --prefix="$LR_HOME_DIR";
100+
else
101+
./configure --with-lua="$LUA_HOME_DIR" --prefix="$LR_HOME_DIR"
102+
fi
103+
104+
make build && make install
105+
106+
ln -s $LR_HOME_DIR/bin/luarocks $HOME/.lua/luarocks
107+
108+
cd $TRAVIS_BUILD_DIR
109+
110+
luarocks --version
111+
112+
rm -rf $LUAROCKS_BASE
113+
114+
if [ "$LUAJIT" == "yes" ]; then
115+
rm -rf $LUAJIT_BASE;
116+
elif [ "$LUA" == "lua5.1" ]; then
117+
rm -rf lua-5.1.5;
118+
elif [ "$LUA" == "lua5.2" ]; then
119+
rm -rf lua-5.2.4;
120+
elif [ "$LUA" == "lua5.3" ]; then
121+
rm -rf lua-5.3.2;
122+
fi

Makefile

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
SRC_DIR = src
2+
TEST_DIR = spec
3+
4+
BUSTED = busted
5+
LUAROCKS = luarocks
6+
LUACHECK = luacheck
7+
8+
LUACHECKRC = luacheckrc
9+
10+
DEPENDENCIES = $(BUSTED) $(LUACHECK)
11+
12+
.PHONY: luacheck test dependencies each_version each_dependencies
13+
14+
all: test
15+
16+
dependencies:
17+
#) -- $@ --
18+
$(foreach package, $(DEPENDENCIES), \
19+
$(LUAROCKS) install --local $(package);)
20+
21+
luacheck: $(SRC_DIR) dependencies
22+
#) -- $@ --
23+
$(foreach file, $(wildcard $</*), $(LUACHECK) $(file);)
24+
$(foreach file, $(wildcard $(TEST_DIR)/*), $(LUACHECK) $(file);)
25+
26+
test: luacheck
27+
#) -- $@ --
28+
$(BUSTED) --verbose --keep-going $(TEST_DIR)/*
29+

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
eff.lua
22
===
33

4+
[![Build Status](https://api.travis-ci.org/Nymphium/eff.lua.svg?branch=master)](https://travis-ci.org/Nymphium/eff.lua)
5+
46
ONE-SHOT Algebraic Effects for Lua!
57

68
# installation
Lines changed: 50 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,12 @@
11
-- https://github.com/ocamllabs/ocaml-effects-tutorial/blob/master/sources/solved/async_await.ml
22

3-
local eff = require('eff')
3+
local eff = require('src/eff')
44
local Eff, perform, handler = eff.Eff, eff.perform, eff.handler
5-
local inspect = require('inspect')
6-
7-
local imut
8-
do
9-
table.move = table.move
10-
or function(src, from, to, on, dst)
11-
for i = from, to do
12-
dst[i + on - 1] = src[i]
13-
end
14-
15-
return dst
16-
end
17-
18-
local cp = function(t)
19-
return table.move(t, 1, #t, 1, {})
20-
end
21-
22-
local cons = function(e, t)
23-
local ret = cp(t)
24-
table.insert(ret, e)
25-
return ret
26-
end
27-
28-
local rev = function(t)
29-
local ret = {}
30-
31-
for i = #t, 1, -1 do
32-
table.insert(ret, t[i])
33-
end
34-
35-
return ret
36-
end
37-
38-
imut = {
39-
cp = cp,
40-
cons = cons,
41-
rev = rev
42-
}
43-
end
445

45-
local ref
46-
do
47-
local newref = function()
48-
return setmetatable({
49-
content = nil,
50-
get = function(self)
51-
return self.content
52-
end
53-
}, {
54-
__call = function(self, v)
55-
self.content = v
56-
return self
57-
end,
58-
__bnot = function(self)
59-
return self.content
60-
end})
61-
end
62-
63-
ref = function(v) return newref()(v) end
64-
end
6+
local imut = require('spec/utils/imut')
7+
local ref = require('spec/utils/ref')
8+
local randoms = require('spec/utils/SEED')
9+
randoms.init()
6510

6611
local Waiting = function(conts)
6712
return { conts, cls = "waiting" }
@@ -142,27 +87,53 @@ local run = function(main)
14287
return fork(ref(Waiting{}), main)
14388
end
14489

145-
local main = function()
146-
local task = function(name)
147-
return function()
148-
print(("Starting %s"):format(name))
149-
local v = math.random(100)
150-
print(("Yielding %s"):format(name))
151-
yield()
152-
print(("Ending %s with %d"):format(name, v))
153-
return v
90+
insulate("async await test", function()
91+
randomize(false)
92+
93+
spy.on(_G, "print")
94+
95+
local main = function()
96+
local task = function(name)
97+
return function()
98+
print(("Starting %s"):format(name))
99+
local v = math.random(100)
100+
print(("Yielding %s"):format(name))
101+
yield()
102+
print(("Ending %s with %d"):format(name, v))
103+
return v
104+
end
154105
end
155-
end
156106

157-
local pa = async(task "a")
158-
local pb = async(task "b")
159-
local pc = async(function()
160-
return await(pa) + await(pb)
161-
end)
107+
local pa = async(task "a")
162108

163-
print(("sum is %d"):format(await(pc)))
164-
assert(await(pa) + await(pb) == await(pc))
165-
end
109+
local pb = async(task "b")
110+
local pc = async(function()
111+
return await(pa) + await(pb)
112+
end)
166113

167-
run(main)
114+
print(("sum is %d"):format(await(pc)))
115+
assert(await(pa) + await(pb) == await(pc))
116+
end
117+
118+
describe("run", function()
119+
run(main)
120+
121+
it("check first resuming a", function()
122+
assert.spy(print).was_called_with("Starting a")
123+
assert.spy(print).was_called_with("Yielding a")
124+
end)
125+
126+
it("check first resuming b", function()
127+
assert.spy(print).was_called_with("Starting b")
128+
assert.spy(print).was_called_with("Yielding b")
129+
end)
130+
131+
it("check task return value", function()
132+
assert.spy(print).was_called_with(("Ending %s with %d"):format("a", randoms[1]))
133+
assert.spy(print).was_called_with(("Ending %s with %d"):format("b", randoms[2]))
134+
assert.spy(print).was_called_with(("sum is %d"):format(randoms[1] + randoms[2]))
135+
assert.spy(print).was_called(7)
136+
end)
137+
end)
138+
end)
168139

test/fringe.lua renamed to spec/fringe.lua

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
-- https://github.com/ocamllabs/ocaml-effects-tutorial/blob/master/sources/solved/fringe.ml
22

3-
local eff = require('eff')
3+
local eff = require('src/eff')
44
local Eff, perform, handler = eff.Eff, eff.perform, eff.handler
55

66
local Yield = Eff("Yield")
@@ -62,14 +62,18 @@ local same_fringe = function(t1, t2)
6262
return loop()
6363
end
6464

65-
local t1 = Node(Leaf(1), Node(Leaf(2), Leaf(3)))
66-
local t2 = Node(Node(Leaf(1), Leaf(2)), Leaf((3)))
67-
local t3 = Node(Node(Leaf(3), Leaf(1)), Leaf((1)))
68-
local t7 = Node(Leaf(1), Node(Leaf(2), Leaf(3)))
65+
describe("fringe test", function()
66+
it("run", function()
67+
local t1 = Node(Leaf(1), Node(Leaf(2), Leaf(3)))
68+
local t2 = Node(Node(Leaf(1), Leaf(2)), Leaf((3)))
69+
local t3 = Node(Node(Leaf(3), Leaf(1)), Leaf((1)))
70+
local t7 = Node(Leaf(1), Node(Leaf(2), Leaf(3)))
6971

70-
assert(same_fringe(t1, t2))
71-
assert(same_fringe(t2, t1))
72-
assert(not same_fringe(t1, t3))
73-
assert(same_fringe(t1, t7))
74-
assert(same_fringe(t2, t7))
72+
assert.True(same_fringe(t1, t2))
73+
assert.True(same_fringe(t2, t1))
74+
assert.True(not same_fringe(t1, t3))
75+
assert.True(same_fringe(t1, t7))
76+
assert.True(same_fringe(t2, t7))
77+
end)
78+
end)
7579

0 commit comments

Comments
 (0)