diff --git a/assertions/directoryExist.ts b/assertions/directoryExist.ts new file mode 100644 index 00000000..8ef7c335 --- /dev/null +++ b/assertions/directoryExist.ts @@ -0,0 +1,10 @@ +import { RunResult } from "../engine/run_result"; +import * as fs from "fs"; + +export class DirectoryExist { + public static run(directory: string): void { + if(!fs.existsSync(directory)) { + throw new Error("directory " + directory + " does not exist"); + } + } +} \ No newline at end of file diff --git a/assertions/index.ts b/assertions/index.ts index 402eed45..6946937c 100644 --- a/assertions/index.ts +++ b/assertions/index.ts @@ -3,9 +3,10 @@ import { Step } from "../engine/step"; import { Command } from "../engine/command"; import { NoErrorCode } from "./noErrorCode"; import { NoException } from "./noException"; +import { DirectoryExist } from "./directoryExist"; -export class Assertions{ +export class Assertions { public noErrorCode(result: RunResult): Assertions { NoErrorCode.run(result); @@ -16,4 +17,9 @@ export class Assertions{ NoException.run(result); return this; } + + public directoryExits(directory: string): Assertions { + DirectoryExist.run(directory); + return this; + } } \ No newline at end of file diff --git a/assertions/noErrorCode.ts b/assertions/noErrorCode.ts index c87183ce..95e8ef1e 100644 --- a/assertions/noErrorCode.ts +++ b/assertions/noErrorCode.ts @@ -1,8 +1,8 @@ import { RunResult } from "../engine/run_result"; -export class NoErrorCode{ +export class NoErrorCode { public static run(result: RunResult): void { - if(result.returnCode != 0){ + if(result.returnCode != 0) { throw new Error("returnCode is not 0"); } } diff --git a/assertions/noException.ts b/assertions/noException.ts index 17cdc193..f2ae777b 100644 --- a/assertions/noException.ts +++ b/assertions/noException.ts @@ -2,7 +2,7 @@ import { RunResult } from "../engine/run_result"; export class NoException { public static run(result: RunResult): void { - if(result.exceptions.length > 0){ + if(result.exceptions.length > 0) { throw new Error("Unexpected exception."); } }