Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Commit

Permalink
Getting the TFVC folder to 100% (#116)
Browse files Browse the repository at this point in the history
  • Loading branch information
jpricket authored and Jeff Young committed Feb 18, 2017
1 parent b36c088 commit 05bd3bd
Show file tree
Hide file tree
Showing 3 changed files with 203 additions and 13 deletions.
24 changes: 11 additions & 13 deletions src/tfvc/tfvcerror.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ export class TfvcError {
}

public constructor(data: ITfvcErrorData) {
if (!data) {
throw TfvcError.CreateArgumentMissingError("data");
}

if (data.error) {
this.error = data.error;
this.message = data.error.message;
Expand All @@ -59,20 +63,14 @@ export class TfvcError {
}

public toString(): string {
let result = this.message + " " +
JSON.stringify(
{
exitCode: this.exitCode,
TfvcErrorCode: this.tfvcErrorCode,
gitCommand: this.tfvcCommand,
stdout: this.stdout,
stderr: this.stderr
},
[],
2);

let result = this.message + " Details: " +
`exitCode: ${this.exitCode}, ` +
`errorCode: ${this.tfvcErrorCode}, ` +
`command: ${this.tfvcCommand}, ` +
`stdout: ${this.stdout}, ` +
`stderr: ${this.stderr}`;
if (this.error) {
result += (<any>this.error).stack;
result += " Stack: " + (<any>this.error).stack;
}

return result;
Expand Down
145 changes: 145 additions & 0 deletions test/tfvc/tfvcerror.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
"use strict";

import { assert } from "chai";

import { Strings } from "../../src/helpers/strings";
import { TfvcError, TfvcErrorCodes } from "../../src/tfvc/tfvcerror";

describe("Tfvc-Error", function() {
beforeEach(function() {
//
});

it("should verify constructor - undefined", function() {
assert.throws(() => new TfvcError(undefined), TfvcError, /Argument is required/);
});

it("should verify constructor - empty data", function() {
let error: TfvcError = new TfvcError({
error: undefined,
exitCode: 0,
message: undefined,
stderr: undefined,
stdout: undefined,
tfvcCommand: undefined,
tfvcErrorCode: undefined
});
assert.equal(error.error, undefined);
assert.equal(error.exitCode, 0);
assert.equal(error.message, Strings.TfExecFailedError);
assert.equal(error.stderr, undefined);
assert.equal(error.stdout, undefined);
assert.equal(error.tfvcCommand, undefined);
assert.equal(error.tfvcErrorCode, undefined);
});

it("should verify constructor - error not empty", function() {
let error: TfvcError = new TfvcError({
error: { name: "err1", message: "error1 message" },
exitCode: 0,
message: undefined,
stderr: undefined,
stdout: undefined,
tfvcCommand: undefined,
tfvcErrorCode: undefined
});
assert.equal(error.error.name, "err1");
assert.equal(error.error.message, "error1 message");
assert.equal(error.exitCode, 0);
assert.equal(error.message, "error1 message");
assert.equal(error.stderr, undefined);
assert.equal(error.stdout, undefined);
assert.equal(error.tfvcCommand, undefined);
assert.equal(error.tfvcErrorCode, undefined);
});

it("should verify constructor - error.message over message", function() {
let error: TfvcError = new TfvcError({
error: { name: "err1", message: "error1 message" },
exitCode: 0,
message: "other message",
stderr: undefined,
stdout: undefined,
tfvcCommand: undefined,
tfvcErrorCode: undefined
});
assert.equal(error.error.name, "err1");
assert.equal(error.error.message, "error1 message");
assert.equal(error.exitCode, 0);
assert.equal(error.message, "error1 message");
assert.equal(error.stderr, undefined);
assert.equal(error.stdout, undefined);
assert.equal(error.tfvcCommand, undefined);
assert.equal(error.tfvcErrorCode, undefined);
});

it("should verify constructor - no error", function() {
let error: TfvcError = new TfvcError({
error: undefined,
exitCode: 100,
message: "other message",
stderr: "standard error",
stdout: "standard output",
tfvcCommand: "command1",
tfvcErrorCode: TfvcErrorCodes.TfvcLocationMissing
});
assert.equal(error.error, undefined);
assert.equal(error.exitCode, 100);
assert.equal(error.message, "other message");
assert.equal(error.stderr, "standard error");
assert.equal(error.stdout, "standard output");
assert.equal(error.tfvcCommand, "command1");
assert.equal(error.tfvcErrorCode, TfvcErrorCodes.TfvcLocationMissing);
});

it("should verify CreateArgumentMissingError", function() {
let error: TfvcError = TfvcError.CreateArgumentMissingError("arg1");
assert.equal(error.error, undefined);
assert.equal(error.exitCode, undefined);
assert.equal(error.message, "Argument is required: arg1");
assert.equal(error.stderr, undefined);
assert.equal(error.stdout, undefined);
assert.equal(error.tfvcCommand, undefined);
assert.equal(error.tfvcErrorCode, TfvcErrorCodes.MissingArgument);
});

it("should verify CreateInvalidStateError", function() {
let error: TfvcError = TfvcError.CreateInvalidStateError();
assert.equal(error.error, undefined);
assert.equal(error.exitCode, undefined);
assert.equal(error.message, "The TFVC SCMProvider is in an invalid state for this action.");
assert.equal(error.stderr, undefined);
assert.equal(error.stdout, undefined);
assert.equal(error.tfvcCommand, undefined);
assert.equal(error.tfvcErrorCode, TfvcErrorCodes.TfvcInInvalidState);
});

it("should verify CreateUnknownError", function() {
let error: TfvcError = TfvcError.CreateUnknownError({ name: "err1", message: "error1 message" });
assert.equal(error.error.name, "err1");
assert.equal(error.error.message, "error1 message");
assert.equal(error.exitCode, undefined);
assert.equal(error.message, "error1 message");
assert.equal(error.stderr, undefined);
assert.equal(error.stdout, undefined);
assert.equal(error.tfvcCommand, undefined);
assert.equal(error.tfvcErrorCode, TfvcErrorCodes.UnknownError);
});

it("should verify toString", function() {
let error: TfvcError = new TfvcError({
error: { name: "err1", message: "error1 message", stack: "here; then there" },
exitCode: 11,
message: undefined,
stderr: "standard error",
stdout: "standard output",
tfvcCommand: "command1",
tfvcErrorCode: TfvcErrorCodes.TfvcMinVersionWarning
});
assert.equal(error.toString(), "error1 message Details: exitCode: 11, errorCode: TfvcMinVersionWarning, command: command1, stdout: standard output, stderr: standard error Stack: here; then there");
});
});
47 changes: 47 additions & 0 deletions test/tfvc/tfvcversion.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,31 +16,64 @@ describe("Tfvc-Version", function() {
it("should verify constructor", function() {
let version: TfvcVersion = new TfvcVersion(12, 11, 10, "");
assert.equal(version.ToString(), "12.11.10");
assert.equal(version.Major, 12);
assert.equal(version.Minor, 11);
assert.equal(version.Revision, 10);
assert.equal(version.Build, "");
});

it("should verify constructor - with build", function() {
let version: TfvcVersion = new TfvcVersion(12, 11, 10, "buildpart");
assert.equal(version.ToString(), "12.11.10.buildpart");
assert.equal(version.Major, 12);
assert.equal(version.Minor, 11);
assert.equal(version.Revision, 10);
assert.equal(version.Build, "buildpart");
});

it("should verify constructor - with dotted build", function() {
let version: TfvcVersion = new TfvcVersion(12, 11, 10, "build.part.");
assert.equal(version.ToString(), "12.11.10.build.part.");
assert.equal(version.Major, 12);
assert.equal(version.Minor, 11);
assert.equal(version.Revision, 10);
assert.equal(version.Build, "build.part.");
});

it("should verify FromString", function() {
let version: TfvcVersion = TfvcVersion.FromString("12.11.10.build.part.");
assert.equal(version.ToString(), "12.11.10.build.part.");
assert.equal(version.Major, 12);
assert.equal(version.Minor, 11);
assert.equal(version.Revision, 10);
assert.equal(version.Build, "build.part.");
});

it("should verify FromString - missing build", function() {
let version: TfvcVersion = TfvcVersion.FromString("12.11.10");
assert.equal(version.ToString(), "12.11.10");
assert.equal(version.Major, 12);
assert.equal(version.Minor, 11);
assert.equal(version.Revision, 10);
assert.equal(version.Build, "");
});

it("should verify FromString - missing revision", function() {
let version: TfvcVersion = TfvcVersion.FromString("12.11");
assert.equal(version.ToString(), "12.11.0");
assert.equal(version.Major, 12);
assert.equal(version.Minor, 11);
assert.equal(version.Revision, 0);
assert.equal(version.Build, "");
});

it("should verify FromString - undefined", function() {
let version: TfvcVersion = TfvcVersion.FromString(undefined);
assert.equal(version.ToString(), "0.0.0");
assert.equal(version.Major, 0);
assert.equal(version.Minor, 0);
assert.equal(version.Revision, 0);
assert.equal(version.Build, "");
});

it("should verify Compare", function() {
Expand All @@ -50,6 +83,20 @@ describe("Tfvc-Version", function() {
assert.isTrue(TfvcVersion.Compare(version2, version1) > 0);
});

it("should verify Compare - major difference", function() {
let version1: TfvcVersion = TfvcVersion.FromString("12.11");
let version2: TfvcVersion = TfvcVersion.FromString("13.1.1");
assert.isTrue(TfvcVersion.Compare(version1, version2) < 0);
assert.isTrue(TfvcVersion.Compare(version2, version1) > 0);
});

it("should verify Compare - minor difference", function() {
let version1: TfvcVersion = TfvcVersion.FromString("12.11");
let version2: TfvcVersion = TfvcVersion.FromString("12.13.1");
assert.isTrue(TfvcVersion.Compare(version1, version2) < 0);
assert.isTrue(TfvcVersion.Compare(version2, version1) > 0);
});

it("should verify Compare - equals", function() {
let version1: TfvcVersion = TfvcVersion.FromString("12.11.10");
let version2: TfvcVersion = TfvcVersion.FromString("12.11.10");
Expand Down

0 comments on commit 05bd3bd

Please sign in to comment.