From 52414b881946dbe0db3e132f145ba7e5dd03babe Mon Sep 17 00:00:00 2001 From: palumbon Date: Thu, 23 May 2024 05:53:25 +0200 Subject: [PATCH 1/4] Remove tests moved to sanity --- package-lock.json | 4 ++-- test/game.test.ts | 16 +--------------- 2 files changed, 3 insertions(+), 17 deletions(-) diff --git a/package-lock.json b/package-lock.json index d9137cfd..ea01b793 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "wollok-ts", - "version": "4.1.1", + "version": "4.1.2", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "wollok-ts", - "version": "4.1.1", + "version": "4.1.2", "license": "MIT", "dependencies": { "@types/parsimmon": "^1.10.8", diff --git a/test/game.test.ts b/test/game.test.ts index 214a4aeb..84bedbe7 100644 --- a/test/game.test.ts +++ b/test/game.test.ts @@ -7,8 +7,6 @@ import { interpret, Interpreter } from '../src/interpreter/interpreter' should() -// TODO: Move the wollok code to language -> We need to run programs! - describe('Wollok Game', () => { describe('actions', () => { @@ -25,19 +23,7 @@ describe('Wollok Game', () => { 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) From db8d9af07337726f551ea76dc57c52b5e951497f Mon Sep 17 00:00:00 2001 From: palumbon Date: Thu, 23 May 2024 05:53:40 +0200 Subject: [PATCH 2/4] Adding tests for errors on events --- test/game.test.ts | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/test/game.test.ts b/test/game.test.ts index 84bedbe7..f69332f9 100644 --- a/test/game.test.ts +++ b/test/game.test.ts @@ -1,9 +1,9 @@ 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() @@ -13,10 +13,16 @@ describe('Wollok Game', () => { let environment: Environment let interpreter: Interpreter + const logs: string[] = [] + const mockNativeFunction = function* (_self: RuntimeObject, obj: RuntimeObject): Execution { + logs.push(obj.innerString!) + } before(async () => { environment = await buildEnvironment(`**/*.${PROGRAM_FILE_EXTENSION}`, resolve('language', 'test', 'game')) + const wConsole = get(natives, 'wollok.lib.console')! + wConsole.println = mockNativeFunction }) beforeEach(() => { @@ -29,17 +35,17 @@ describe('Wollok Game', () => { 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 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('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:21]']) }) it('with file name game (devil test)', () => { From 54e8af2ec14229d679d0ef13d15d2d2b3bd8978d Mon Sep 17 00:00:00 2001 From: palumbon Date: Thu, 23 May 2024 06:22:51 +0200 Subject: [PATCH 3/4] Test error reporter + move property to lang --- src/wre/game.ts | 4 ---- test/game.test.ts | 10 ++++++++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/wre/game.ts b/src/wre/game.ts index 2d19e97d..55e28218 100644 --- a/src/wre/game.ts +++ b/src/wre/game.ts @@ -108,10 +108,6 @@ const game: Natives = { visual.set('showAttributes', yield* this.reify(false)) }, - *errorReporter(self: RuntimeObject, visual: RuntimeObject): Execution { - self.set('errorReporter', visual) - }, - }, Sound: { diff --git a/test/game.test.ts b/test/game.test.ts index f69332f9..d9f21c57 100644 --- a/test/game.test.ts +++ b/test/game.test.ts @@ -35,17 +35,23 @@ describe('Wollok Game', () => { interpreter.object('actions.visual').get('messageTime')!.innerValue!.should.equal(2000) }) - it('on DomainError, visual says the message', () => { + 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('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:21]']) + '\tat actions.genericError [actions.wpgm:33]']) }) it('with file name game (devil test)', () => { From b2058ceb9354543e8578d30e553c091d12a392bf Mon Sep 17 00:00:00 2001 From: palumbon Date: Sat, 15 Jun 2024 22:30:24 +0200 Subject: [PATCH 4/4] =?UTF-8?q?Point=20wollokVersion=20to=20master=20branc?= =?UTF-8?q?h=20=F0=9F=98=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 5 +++-- scripts/validateWollokVersion.ts | 7 +++++++ 2 files changed, 10 insertions(+), 2 deletions(-) create mode 100644 scripts/validateWollokVersion.ts diff --git a/package.json b/package.json index 3709eebf..2e7fd3bb 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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" }, diff --git a/scripts/validateWollokVersion.ts b/scripts/validateWollokVersion.ts new file mode 100644 index 00000000..d2579746 --- /dev/null +++ b/scripts/validateWollokVersion.ts @@ -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) +} \ No newline at end of file