Skip to content
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
30 changes: 24 additions & 6 deletions engine/engine.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Environment } from "./environment";
import { Playbook } from "./playbook";
import { Runner } from "./runner";
import { RunCommand } from "./run_command";
import { RunResult } from "./run_result";


Expand All @@ -24,25 +25,26 @@ export class Engine {
(await this.getRunner(this.environment.runners[runnerIndex])).init(this.playbook);
}

mainloop: for (let stepIndex in this.playbook.steps) {
for (let lineIndex in this.playbook.steps[stepIndex].lines) {
mainloop: for (let stepIndex = 0; stepIndex < this.playbook.steps.length; stepIndex++) {
for (let lineIndex = 0; lineIndex < this.playbook.steps[stepIndex].lines.length; lineIndex++) {
let runCommand = this.initRunCommand(stepIndex, lineIndex);
let foundRunnerToExecuteCommand = false;
for (let runnerIndex in this.environment.runners) {
let runner = await this.getRunner(this.environment.runners[runnerIndex]);
if (runner.supports(this.playbook.steps[stepIndex].lines[lineIndex].name)) {
var result = new RunResult();
if(runner.commandIsSkippable(this.playbook.steps[stepIndex].lines[lineIndex].name)) {
console.log("Command " + this.playbook.steps[stepIndex].lines[lineIndex].name + " will be skipped.");
if(runner.commandIsSkippable(runCommand.command.name)) {
console.log("Command " + runCommand.command.name + " will be skipped.");
continue;
}
try {
result = runner.run(this.playbook.steps[stepIndex], this.playbook.steps[stepIndex].lines[lineIndex]);
result = runner.run(runCommand);
}
catch (e) {
result.exceptions.push(e);
}

await runner.assert(this.playbook.steps[stepIndex], this.playbook.steps[stepIndex].lines[lineIndex], result);
await runner.assert(runCommand, result);

foundRunnerToExecuteCommand = true;
break;
Expand Down Expand Up @@ -105,4 +107,20 @@ export class Engine {
runner.playbookTitle = this.playbook.title;
this.runners.set(name, runner);
}

private initRunCommand(stepIndex: number, lineIndex: number): RunCommand {
let runCommand = new RunCommand();
if(lineIndex == 0) {
runCommand.text = this.playbook.steps[stepIndex].text;
}
if(lineIndex == (this.playbook.steps[stepIndex].lines.length - 1)){
runCommand.textAfter = this.playbook.steps[stepIndex].textAfter;
}
runCommand.command = this.playbook.steps[stepIndex].lines[lineIndex];
runCommand.stepIndex = stepIndex;
runCommand.lineIndex = lineIndex;
runCommand.stepTitle = this.playbook.steps[stepIndex].title;

return runCommand;
}
}
20 changes: 12 additions & 8 deletions engine/parser.def
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,14 @@ step

stepinner
= steptextlines?
"[step]" ___
"--" ___
steplines
"--" __
"[step]" ___
stepstitle?
"--" ___
steplines
"--" __

stepstitle
= "==" _ string __

steptextlines
= steptextline* { return { "steptextlines": text()}; }
Expand All @@ -46,11 +50,11 @@ steptextafterline
= !"====" string __

steplines
= stepline+

stepline
= !"--" string __ { return { "stepline": text()}; }
= stepline+ { return { "steplines": text()}; }

stepline
= !"--" string __

string "string"
= [^\r\n]+ { return text(); }

Expand Down
18 changes: 13 additions & 5 deletions engine/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ export class Parser {
constructor() {
let def = fs.readFileSync(__dirname + "/parser.def", 'utf8');
this.parser = pegjs.generate(def);

}

parse(inputFile: string): Playbook {
Expand All @@ -23,9 +22,10 @@ export class Parser {
result.description = parseResult[1][2].descriptionlines;
for(let index in parseResult[2]){
let step = new Step();
step.text = this.getText(parseResult,index);;
step.lines = this.getLines(parseResult,index);
step.text = this.getText(parseResult, index);
step.lines = this.getLines(parseResult, index);
step.textAfter = this.getTextAfter(parseResult, index);
step.title = this.getTitle(parseResult, index);

result.steps.push(step);
}
Expand All @@ -43,9 +43,17 @@ export class Parser {

getLines(parseResult, index):Command[]{
try {
return (parseResult[2][index][5][0].stepline || parseResult[2][index][2][5][0].stepline).split("\r\n").filter(e => e != '').map(e => this.createCommand(e));
return (parseResult[2][index][6].steplines || parseResult[2][index][2][6].steplines).split("\r\n").filter(e => e != '').map(e => this.createCommand(e));
} catch (error) {
return parseResult[2][index][2][5][0].stepline.split("\r\n").filter(e => e != '').map(e => this.createCommand(e));
return parseResult[2][index][2][6].steplines.split("\r\n").filter(e => e != '').map(e => this.createCommand(e));
}
}

getTitle(parseResult, index) {
try {
return (parseResult[2][index][3][2]|| parseResult[2][index][2][3][2]);
} catch(error) {
return null;
}
}

Expand Down
10 changes: 10 additions & 0 deletions engine/run_command.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Command } from "./command";

export class RunCommand {
public text: string;
public command: Command;
public lineIndex: number;
public stepIndex: number;
public textAfter: string;
public stepTitle: string;
}
13 changes: 7 additions & 6 deletions engine/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Playbook } from "./playbook";
import { Step } from "./step";
import * as fs from 'fs';
import * as rimraf from 'rimraf';
import { RunCommand } from "./run_command";

export abstract class Runner {
public path: string;
Expand Down Expand Up @@ -86,14 +87,14 @@ export abstract class Runner {
this.setVariable(this.useDevonCommand, false);
}

run(step: Step, command: Command): RunResult {
console.log("Run " + command.name, command.parameters);
return this[this.getMethodName("run", command.name)](step, command);
run(runCommand: RunCommand): RunResult {
console.log("Run " + runCommand.command.name, runCommand.command.parameters);
return this[this.getMethodName("run", runCommand.command.name)](runCommand);
}

async assert(step: Step, command: Command, runResult: RunResult): Promise<void> {
if (this[this.getMethodName("assert", command.name)]) {
await this[this.getMethodName("assert", command.name)](step, command, runResult);
async assert(runCommand: RunCommand, runResult: RunResult): Promise<void> {
if (this[this.getMethodName("assert", runCommand.command.name)]) {
await this[this.getMethodName("assert", runCommand.command.name)](runCommand, runResult);
}
}

Expand Down
1 change: 1 addition & 0 deletions engine/step.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ import { Command } from "./command";
export class Step {
public text: string;
public lines: Command[] = [];
public title: string;
public textAfter: string;
}
Loading