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

Tests for errors on game events #244

Merged
merged 4 commits into from
Jun 15, 2024
Merged
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
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "wollok-ts",
"version": "4.1.2",
"wollokVersion": "3.2.3",
"wollokVersion": ":master",
"description": "TypeScript based Wollok language implementation",
"repository": "https://github.com/uqbar-project/wollok-ts",
"license": "MIT",
Expand Down Expand Up @@ -29,7 +29,8 @@
"test:printer": "mocha --parallel -r ts-node/register/transpile-only test/printer.test.ts",
"test:parser": "mocha --parallel -r ts-node/register/transpile-only test/parser.test.ts",
"lint:fix": "eslint . --fix",
"prepublishOnly": "npm run build && npm test",
"validate:wollokVersion": "ts-node scripts/validateWollokVersion.ts",
"prepublishOnly": "validate:wollokVersion && npm run build && npm test",
"postpublish": "git tag v$npm_package_version && git push --tags",
"prepack": "npm run build"
},
Expand Down
7 changes: 7 additions & 0 deletions scripts/validateWollokVersion.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { exit } from 'process'
import { wollokVersion } from '../package.json'

if (wollokVersion.includes(':')) {
console.error('ERROR: wollokVersion in package.json must be a fixed version')
exit(-1)
}
4 changes: 0 additions & 4 deletions src/wre/game.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,6 @@ const game: Natives = {
visual.set('showAttributes', yield* this.reify(false))
},

*errorReporter(self: RuntimeObject, visual: RuntimeObject): Execution<void> {
self.set('errorReporter', visual)
},

},

Sound: {
Expand Down
50 changes: 24 additions & 26 deletions test/game.test.ts
Original file line number Diff line number Diff line change
@@ -1,59 +1,57 @@
import { should } from 'chai'
import { resolve } from 'path'
import { buildEnvironment } from './assertions'
import natives from '../src/wre/wre.natives'
import { Environment, GAME_MODULE, PROGRAM_FILE_EXTENSION } from '../src'
import { Environment, Execution, get, Natives, PROGRAM_FILE_EXTENSION, RuntimeObject } from '../src'
import { interpret, Interpreter } from '../src/interpreter/interpreter'
import natives from '../src/wre/wre.natives'
import { buildEnvironment } from './assertions'

should()

// TODO: Move the wollok code to language -> We need to run programs!

describe('Wollok Game', () => {

describe('actions', () => {

let environment: Environment
let interpreter: Interpreter
const logs: string[] = []

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

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

beforeEach(() => {
interpreter = interpret(environment, natives)
})

it('addVisual', () => {
interpreter.run('actions.addVisual')
const visuals = interpreter.object(GAME_MODULE).get('visuals')!.innerValue!
visuals.should.have.length(1)
})

it('removeVisual', () => {
interpreter.run('actions.removeVisual')
const visuals = interpreter.object(GAME_MODULE).get('visuals')!.innerValue!
visuals.should.have.length(0)
})

it('say', () => {
it('say set message and time to visual', () => {
interpreter.run('actions.say')
interpreter.object('actions.visual').get('message')!.innerValue!.should.equal('Hi!')
interpreter.object('actions.visual').get('messageTime')!.innerValue!.should.equal(2000)
})

it('clear', () => {
interpreter.run('actions.clear')
const visuals = interpreter.object(GAME_MODULE)!.get('visuals')!.innerValue!
visuals.should.have.length(0)
it('on DomainError, visual source says the message', () => {
interpreter.run('actions.domainError')
interpreter.object('actions.visual').get('message')!.innerValue!.should.equal('DOMAIN_ERROR')
interpreter.object('actions.visual').get('messageTime')!.innerValue!.should.equal(2000)
})

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

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

it('with file name game (devil test)', () => {
Expand Down
Loading