Skip to content

Commit aaa003e

Browse files
Merge pull request devonfw-tutorials#13 from GuentherJulian/feature_assertionDirectoryExist
created assertion directoryExist
2 parents a879756 + e8d67d7 commit aaa003e

File tree

4 files changed

+20
-4
lines changed

4 files changed

+20
-4
lines changed

assertions/directoryExist.ts

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { RunResult } from "../engine/run_result";
2+
import * as fs from "fs";
3+
4+
export class DirectoryExist {
5+
public static run(directory: string): void {
6+
if(!fs.existsSync(directory)) {
7+
throw new Error("directory " + directory + " does not exist");
8+
}
9+
}
10+
}

assertions/index.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ import { Step } from "../engine/step";
33
import { Command } from "../engine/command";
44
import { NoErrorCode } from "./noErrorCode";
55
import { NoException } from "./noException";
6+
import { DirectoryExist } from "./directoryExist";
67

78

8-
export class Assertions{
9+
export class Assertions {
910

1011
public noErrorCode(result: RunResult): Assertions {
1112
NoErrorCode.run(result);
@@ -16,4 +17,9 @@ export class Assertions{
1617
NoException.run(result);
1718
return this;
1819
}
20+
21+
public directoryExits(directory: string): Assertions {
22+
DirectoryExist.run(directory);
23+
return this;
24+
}
1925
}

assertions/noErrorCode.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { RunResult } from "../engine/run_result";
22

3-
export class NoErrorCode{
3+
export class NoErrorCode {
44
public static run(result: RunResult): void {
5-
if(result.returnCode != 0){
5+
if(result.returnCode != 0) {
66
throw new Error("returnCode is not 0");
77
}
88
}

assertions/noException.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { RunResult } from "../engine/run_result";
22

33
export class NoException {
44
public static run(result: RunResult): void {
5-
if(result.exceptions.length > 0){
5+
if(result.exceptions.length > 0) {
66
throw new Error("Unexpected exception.");
77
}
88
}

0 commit comments

Comments
 (0)