Skip to content

Commit a5cd696

Browse files
authored
Merge pull request #244 from uqbar-project/wgame-tests-for-errors
Tests for errors on game events
2 parents 22dd519 + b2058ce commit a5cd696

File tree

5 files changed

+36
-34
lines changed

5 files changed

+36
-34
lines changed

package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "wollok-ts",
33
"version": "4.1.2",
4-
"wollokVersion": "3.2.3",
4+
"wollokVersion": ":master",
55
"description": "TypeScript based Wollok language implementation",
66
"repository": "https://github.com/uqbar-project/wollok-ts",
77
"license": "MIT",
@@ -29,7 +29,8 @@
2929
"test:printer": "mocha --parallel -r ts-node/register/transpile-only test/printer.test.ts",
3030
"test:parser": "mocha --parallel -r ts-node/register/transpile-only test/parser.test.ts",
3131
"lint:fix": "eslint . --fix",
32-
"prepublishOnly": "npm run build && npm test",
32+
"validate:wollokVersion": "ts-node scripts/validateWollokVersion.ts",
33+
"prepublishOnly": "validate:wollokVersion && npm run build && npm test",
3334
"postpublish": "git tag v$npm_package_version && git push --tags",
3435
"prepack": "npm run build"
3536
},

scripts/validateWollokVersion.ts

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { exit } from 'process'
2+
import { wollokVersion } from '../package.json'
3+
4+
if (wollokVersion.includes(':')) {
5+
console.error('ERROR: wollokVersion in package.json must be a fixed version')
6+
exit(-1)
7+
}

src/wre/game.ts

-4
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,6 @@ const game: Natives = {
108108
visual.set('showAttributes', yield* this.reify(false))
109109
},
110110

111-
*errorReporter(self: RuntimeObject, visual: RuntimeObject): Execution<void> {
112-
self.set('errorReporter', visual)
113-
},
114-
115111
},
116112

117113
Sound: {

test/game.test.ts

+24-26
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,57 @@
11
import { should } from 'chai'
22
import { resolve } from 'path'
3-
import { buildEnvironment } from './assertions'
4-
import natives from '../src/wre/wre.natives'
5-
import { Environment, GAME_MODULE, PROGRAM_FILE_EXTENSION } from '../src'
3+
import { Environment, Execution, get, Natives, PROGRAM_FILE_EXTENSION, RuntimeObject } from '../src'
64
import { interpret, Interpreter } from '../src/interpreter/interpreter'
5+
import natives from '../src/wre/wre.natives'
6+
import { buildEnvironment } from './assertions'
77

88
should()
99

10-
// TODO: Move the wollok code to language -> We need to run programs!
11-
1210
describe('Wollok Game', () => {
1311

1412
describe('actions', () => {
1513

1614
let environment: Environment
1715
let interpreter: Interpreter
16+
const logs: string[] = []
1817

18+
const mockNativeFunction = function* (_self: RuntimeObject, obj: RuntimeObject): Execution<void> {
19+
logs.push(obj.innerString!)
20+
}
1921

2022
before(async () => {
2123
environment = await buildEnvironment(`**/*.${PROGRAM_FILE_EXTENSION}`, resolve('language', 'test', 'game'))
24+
const wConsole = get<Natives>(natives, 'wollok.lib.console')!
25+
wConsole.println = mockNativeFunction
2226
})
2327

2428
beforeEach(() => {
2529
interpreter = interpret(environment, natives)
2630
})
2731

28-
it('addVisual', () => {
29-
interpreter.run('actions.addVisual')
30-
const visuals = interpreter.object(GAME_MODULE).get('visuals')!.innerValue!
31-
visuals.should.have.length(1)
32-
})
33-
34-
it('removeVisual', () => {
35-
interpreter.run('actions.removeVisual')
36-
const visuals = interpreter.object(GAME_MODULE).get('visuals')!.innerValue!
37-
visuals.should.have.length(0)
38-
})
39-
40-
it('say', () => {
32+
it('say set message and time to visual', () => {
4133
interpreter.run('actions.say')
4234
interpreter.object('actions.visual').get('message')!.innerValue!.should.equal('Hi!')
4335
interpreter.object('actions.visual').get('messageTime')!.innerValue!.should.equal(2000)
4436
})
4537

46-
it('clear', () => {
47-
interpreter.run('actions.clear')
48-
const visuals = interpreter.object(GAME_MODULE)!.get('visuals')!.innerValue!
49-
visuals.should.have.length(0)
38+
it('on DomainError, visual source says the message', () => {
39+
interpreter.run('actions.domainError')
40+
interpreter.object('actions.visual').get('message')!.innerValue!.should.equal('DOMAIN_ERROR')
41+
interpreter.object('actions.visual').get('messageTime')!.innerValue!.should.equal(2000)
42+
})
5043

44+
it('on DomainError with error reporter, it says the message', () => {
45+
interpreter.run('actions.domainErrorWithReporter')
46+
interpreter.object('actions.reporter').get('message')!.innerValue!.should.equal('DOMAIN_ERROR')
47+
interpreter.object('actions.reporter').get('messageTime')!.innerValue!.should.equal(2000)
5148
})
5249

53-
it('flush event', () => {
54-
const game = interpreter.object(GAME_MODULE)!
55-
const time = interpreter.reify(1)
56-
interpreter.send('flushEvents', game, time)
50+
it('on Error, console should print stack trace', () => {
51+
interpreter.run('actions.genericError')
52+
logs.should.be.deep.eq([
53+
'wollok.lang.Exception: ERROR',
54+
'\tat actions.genericError [actions.wpgm:33]'])
5755
})
5856

5957
it('with file name game (devil test)', () => {

0 commit comments

Comments
 (0)