From 6ccc19ac54a379504edeeaef26670fe774441b4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20G=C3=BCnther?= Date: Wed, 4 Nov 2020 17:51:33 +0100 Subject: [PATCH 1/2] created assertion directoryExist --- assertions/directoryExist.ts | 10 ++++++++++ assertions/index.ts | 8 +++++++- assertions/noErrorCode.ts | 4 ++-- assertions/noException.ts | 2 +- 4 files changed, 20 insertions(+), 4 deletions(-) create mode 100644 assertions/directoryExist.ts diff --git a/assertions/directoryExist.ts b/assertions/directoryExist.ts new file mode 100644 index 00000000..0eb2089f --- /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(result: RunResult, 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..09d5cb2a 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(result: RunResult, directory: string): Assertions { + DirectoryExist.run(result, 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."); } } From e8d67d7722fc840b0376cfab1f968d60752e8acc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20G=C3=BCnther?= Date: Thu, 5 Nov 2020 15:05:29 +0100 Subject: [PATCH 2/2] modified assertion directoryExist --- assertions/directoryExist.ts | 2 +- assertions/index.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/assertions/directoryExist.ts b/assertions/directoryExist.ts index 0eb2089f..8ef7c335 100644 --- a/assertions/directoryExist.ts +++ b/assertions/directoryExist.ts @@ -2,7 +2,7 @@ import { RunResult } from "../engine/run_result"; import * as fs from "fs"; export class DirectoryExist { - public static run(result: RunResult, directory: string): void { + public static run(directory: string): void { if(!fs.existsSync(directory)) { throw new Error("directory " + directory + " does not exist"); } diff --git a/assertions/index.ts b/assertions/index.ts index 09d5cb2a..6946937c 100644 --- a/assertions/index.ts +++ b/assertions/index.ts @@ -18,8 +18,8 @@ export class Assertions { return this; } - public directoryExits(result: RunResult, directory: string): Assertions { - DirectoryExist.run(result, directory); + public directoryExits(directory: string): Assertions { + DirectoryExist.run(directory); return this; } } \ No newline at end of file