Commit 76caa7a0 authored by Felix Freiberger's avatar Felix Freiberger

Integrated pseuco-tests project.

parent afdbe96b
Pipeline #6161 failed with stages
in 1 minute
stages:
- deps
- build
- test
npm-install:
stage: deps
image: node:latest
script:
- npm ci
- npm install grunt-cli
artifacts:
expire_in: 1 hour
paths:
- node_modules/
grunt-build:
stage: build
image: node:latest
dependencies:
- npm-install
script:
- node_modules/.bin/grunt build
artifacts:
expire_in: 2 weeks
paths:
- lib/
grunt-test:
stage: test
image: node:latest
dependencies:
- npm-install
- grunt-build
variables:
GIT_SUBMODULE_STRATEGY: normal
script:
- node_modules/.bin/grunt test
[submodule "pseuco-tests"]
path = pseuco-tests
url = ../../pseuco/pseuco-tests
......@@ -34,6 +34,14 @@ module.exports = function(grunt) {
create: ['lib']
}
}
},
mochaTest: {
test: {
options: {
reporter: 'spec'
},
src: ['test.js']
}
}
});
......@@ -43,6 +51,7 @@ module.exports = function(grunt) {
grunt.loadNpmTasks('grunt-contrib-coffee');
grunt.loadNpmTasks('grunt-contrib-rename');
grunt.loadNpmTasks('grunt-mkdir');
grunt.loadNpmTasks('grunt-mocha-test');
grunt.registerTask('build', [
'coffee',
......@@ -50,5 +59,6 @@ module.exports = function(grunt) {
'rename',
'clean'
]);
grunt.registerTask('default', ['build']);
grunt.registerTask('test', ['mochaTest']);
grunt.registerTask('default', ['build', 'test']);
};
\ No newline at end of file
This diff is collapsed.
Subproject commit f5b38fb8c9bc4fd2d2def614e0462597b08a034c
/* global require, describe, it, console */
const fs = require('fs');
const _ = require('lodash');
require('should');
require('source-map-support').install();
const PseuCo = require('@pseuco/lang');
const PseuCoParser = PseuCo.parser;
const CCSCompiler = require('./lib/CCSCompiler');
const expectUniquePrintLn = function (ccs, expected) {
const failWithMessage = (state, message) => {
throw new Error(`Failure in state ${state.toString()}: ${message}`);
}
let checkJobs = [];
let checked = [];
checkJobs.push({
state: ccs,
stateString: ccs.toString(),
expected
});
const previousStateStringMap = new Map();
while (checkJobs.length) {
let job = checkJobs.shift();
let { state : currentState, stateString: currentStateString, expected : currentExpected } = job;
// search if job is already completed
const preCheckedJob = _.find(checked, ({ stateString : checkedStateString }) => checkedStateString === currentStateString);
if (preCheckedJob) {
// validate check
if (!_.isEqual(preCheckedJob.expected, currentExpected)) failWithMessage(currentState, `There were inconsistent checks, so at least one of them must be false.`);
// validate cycle-freeness
let s = previousStateStringMap.get(currentStateString);
while (s) {
if (s === preCheckedJob.stateString) failWithMessage(`I found a cycle.`);
s = previousStateStringMap.get(s);
}
continue; // already checked, next
}
const possibleSteps = currentState.getPossibleSteps(true);
if (possibleSteps.length == 0 && currentExpected.length) failWithMessage(currentMarking, `Expected a println but found a terminal state (${currentStateString}).`);
const printlnPattern = /^println!\((.+)\)$/;
_.forEach(possibleSteps, (step) => {
let nextExpected = currentExpected;
const successorState = step.perform();
const stepLabel = step.toString(false);
const printMatch = printlnPattern.exec(stepLabel);
if (printMatch) {
if (currentExpected.length == 0) failWithMessage(currentMarking, `unexpected println (from state: ${currentStateString})`);
const printedValue = printMatch[1];
printedValue.should.equal(JSON.stringify(_.head(currentExpected)));
nextExpected = _.tail(currentExpected);
}
checkJobs.push({
state: successorState,
stateString: successorState.toString(),
expected: nextExpected
});
checked.push(job);
});
}
};
describe("passed shared pseuco-tests", function () {
"use strict";
var files = fs.readdirSync('./pseuco-tests/tests', { withFileTypes: true });
_.each(files, (file) => {
if (file.isFile() && /\.json$/.test(file.name)) {
const baseName = /^(.*)\.json$/.exec(file.name)[1];
const testData = JSON.parse(fs.readFileSync(`./pseuco-tests/tests/${file.name}`, 'utf8'));
const pseucoProgram = fs.readFileSync(`./pseuco-tests/tests/${baseName}.pseuco`, 'utf8');
it(`${testData.description} (${baseName})`, function () {
this.timeout(30000);
const tree = PseuCoParser.parse(pseucoProgram);
const env = new CCSCompiler.ProgramController(tree);
tree.getType(env); // type-check
const compiler = new CCSCompiler.Compiler(tree, env);
const ccs = compiler.compileProgram();
_.each(testData.correctnessProperties, (property) => {
if (property.type !== 'deterministicOutput') throw new Error("unknown correctness property");
expectUniquePrintLn(ccs, property.output);
});
});
}
});
});
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment