Skip to content

Remove many uses of 'null' in harness #8828

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
2 commits merged into from
May 26, 2016
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
1 change: 1 addition & 0 deletions src/harness/compilerRunner.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/// <reference path="harness.ts" />
/// <reference path="runnerbase.ts" />
/// <reference path="typeWriter.ts" />
// In harness baselines, null is different than undefined. See `generateActual` in `harness.ts`.
/* tslint:disable:no-null-keyword */

const enum CompilerTestType {
Expand Down
3 changes: 1 addition & 2 deletions src/harness/external/chai.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,6 @@ declare module chai {
function notEqual(actual: any, expected: any, message?: string): void;
function isTrue(value: any, message?: string): void;
function isFalse(value: any, message?: string): void;
function isNull(value: any, message?: string): void;
function isNotNull(value: any, message?: string): void;
function isOk(actual: any, message?: string): void;
}
}
43 changes: 21 additions & 22 deletions src/harness/fourslash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
/// <reference path="harnessLanguageService.ts" />
/// <reference path="harness.ts" />
/// <reference path="fourslashRunner.ts" />
/* tslint:disable:no-null-keyword */

namespace FourSlash {
ts.disableIncrementalParsing = false;
Expand Down Expand Up @@ -198,7 +197,7 @@ namespace FourSlash {
public lastKnownMarker: string = "";

// The file that's currently 'opened'
public activeFile: FourSlashFile = null;
public activeFile: FourSlashFile;

// Whether or not we should format on keystrokes
public enableFormatting = true;
Expand Down Expand Up @@ -922,7 +921,7 @@ namespace FourSlash {

public verifyCurrentParameterIsletiable(isVariable: boolean) {
const signature = this.getActiveSignatureHelpItem();
assert.isNotNull(signature);
assert.isOk(signature);
assert.equal(isVariable, signature.isVariadic);
}

Expand Down Expand Up @@ -1911,7 +1910,7 @@ namespace FourSlash {
public verifyNavigationItemsCount(expected: number, searchValue: string, matchKind?: string) {
const items = this.languageService.getNavigateToItems(searchValue);
let actual = 0;
let item: ts.NavigateToItem = null;
let item: ts.NavigateToItem;

// Count only the match that match the same MatchKind
for (let i = 0; i < items.length; i++) {
Expand Down Expand Up @@ -2183,7 +2182,7 @@ namespace FourSlash {
}

private findFile(indexOrName: any) {
let result: FourSlashFile = null;
let result: FourSlashFile;
if (typeof indexOrName === "number") {
const index = <number>indexOrName;
if (index >= this.testData.files.length) {
Expand Down Expand Up @@ -2352,10 +2351,16 @@ ${code}
const ranges: Range[] = [];

// Stuff related to the subfile we're parsing
let currentFileContent: string = null;
let currentFileContent: string = undefined;
let currentFileName = fileName;
let currentFileOptions: { [s: string]: string } = {};

function resetLocalData() {
currentFileContent = undefined;
currentFileOptions = {};
currentFileName = fileName;
}

for (let i = 0; i < lines.length; i++) {
let line = lines[i];
const lineLength = line.length;
Expand All @@ -2368,7 +2373,7 @@ ${code}
// Subfile content line

// Append to the current subfile content, inserting a newline needed
if (currentFileContent === null) {
if (currentFileContent === undefined) {
currentFileContent = "";
}
else {
Expand Down Expand Up @@ -2400,10 +2405,7 @@ ${code}
// Store result file
files.push(file);

// Reset local data
currentFileContent = null;
currentFileOptions = {};
currentFileName = fileName;
resetLocalData();
}

currentFileName = basePath + "/" + match[2];
Expand All @@ -2430,10 +2432,7 @@ ${code}
// Store result file
files.push(file);

// Reset local data
currentFileContent = null;
currentFileOptions = {};
currentFileName = fileName;
resetLocalData();
}
}
}
Expand Down Expand Up @@ -2498,7 +2497,7 @@ ${code}

if (markerValue === undefined) {
reportError(fileName, location.sourceLine, location.sourceColumn, "Object markers can not be empty");
return null;
return undefined;
}

const marker: Marker = {
Expand Down Expand Up @@ -2527,7 +2526,7 @@ ${code}
if (markerMap[name] !== undefined) {
const message = "Marker '" + name + "' is duplicated in the source file contents.";
reportError(marker.fileName, location.sourceLine, location.sourceColumn, message);
return null;
return undefined;
}
else {
markerMap[name] = marker;
Expand All @@ -2546,7 +2545,7 @@ ${code}
let output = "";

/// The current marker (or maybe multi-line comment?) we're parsing, possibly
let openMarker: LocationInformation = null;
let openMarker: LocationInformation = undefined;

/// A stack of the open range markers that are still unclosed
const openRanges: RangeLocationInformation[] = [];
Expand Down Expand Up @@ -2654,7 +2653,7 @@ ${code}
difference += i + 1 - openMarker.sourcePosition;

// Reset the state
openMarker = null;
openMarker = undefined;
state = State.none;
}
break;
Expand All @@ -2676,7 +2675,7 @@ ${code}
difference += i + 1 - openMarker.sourcePosition;

// Reset the state
openMarker = null;
openMarker = undefined;
state = State.none;
}
else if (validMarkerChars.indexOf(currentChar) < 0) {
Expand All @@ -2688,7 +2687,7 @@ ${code}
// Bail out the text we've gathered so far back into the output
flush(i);
lastNormalCharPosition = i;
openMarker = null;
openMarker = undefined;

state = State.none;
}
Expand Down Expand Up @@ -2719,7 +2718,7 @@ ${code}
reportError(fileName, openRange.sourceLine, openRange.sourceColumn, "Unterminated range.");
}

if (openMarker !== null) {
if (openMarker) {
reportError(fileName, openMarker.sourceLine, openMarker.sourceColumn, "Unterminated marker.");
}

Expand Down
1 change: 0 additions & 1 deletion src/harness/fourslashRunner.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
///<reference path="fourslash.ts" />
///<reference path="harness.ts"/>
///<reference path="runnerbase.ts" />
/* tslint:disable:no-null-keyword */

const enum FourSlashTestType {
Native,
Expand Down
39 changes: 19 additions & 20 deletions src/harness/harness.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
/// <reference path="external\chai.d.ts"/>
/// <reference path="sourceMapRecorder.ts"/>
/// <reference path="runnerbase.ts"/>
/* tslint:disable:no-null-keyword */

// Block scoped definitions work poorly for global variables, temporarily enable var
/* tslint:disable:no-var-keyword */
Expand All @@ -32,7 +31,7 @@
var _chai: typeof chai = require("chai");
var assert: typeof _chai.assert = _chai.assert;
declare var __dirname: string; // Node-specific
var global = <any>Function("return this").call(null);
var global = <any>Function("return this").call(undefined);
/* tslint:enable:no-var-keyword */

namespace Utils {
Expand Down Expand Up @@ -558,15 +557,9 @@ namespace Harness {
}

export function directoryName(path: string) {
let dirPath = pathModule.dirname(path);

const dirPath = pathModule.dirname(path);
// Node will just continue to repeat the root path, rather than return null
if (dirPath === path) {
dirPath = null;
}
else {
return dirPath;
}
return dirPath === path ? undefined : dirPath;
}

export let listFiles: typeof IO.listFiles = (path, spec?, options?) => {
Expand Down Expand Up @@ -634,7 +627,7 @@ namespace Harness {
xhr.send();
}
catch (e) {
return { status: 404, responseText: null };
return { status: 404, responseText: undefined };
}

return waitForXHR(xhr);
Expand All @@ -651,7 +644,7 @@ namespace Harness {
}
catch (e) {
log(`XHR Error: ${e}`);
return { status: 500, responseText: null };
return { status: 500, responseText: undefined };
}

return waitForXHR(xhr);
Expand All @@ -663,7 +656,7 @@ namespace Harness {
}

export function deleteFile(path: string) {
Http.writeToServerSync(serverRoot + path, "DELETE", null);
Http.writeToServerSync(serverRoot + path, "DELETE");
}

export function directoryExists(path: string): boolean {
Expand All @@ -674,7 +667,7 @@ namespace Harness {
let dirPath = path;
// root of the server
if (dirPath.match(/localhost:\d+$/) || dirPath.match(/localhost:\d+\/$/)) {
dirPath = null;
dirPath = undefined;
// path + fileName
}
else if (dirPath.indexOf(".") === -1) {
Expand Down Expand Up @@ -722,7 +715,7 @@ namespace Harness {
return response.responseText;
}
else {
return null;
return undefined;
}
}

Expand Down Expand Up @@ -1418,7 +1411,9 @@ namespace Harness {
const opts: CompilerSettings = {};

let match: RegExpExecArray;
while ((match = optionRegex.exec(content)) != null) {
/* tslint:disable:no-null-keyword */
while ((match = optionRegex.exec(content)) !== null) {
/* tslint:enable:no-null-keyword */
opts[match[1]] = match[2];
}

Expand All @@ -1435,9 +1430,9 @@ namespace Harness {
const lines = Utils.splitContentByNewlines(code);

// Stuff related to the subfile we're parsing
let currentFileContent: string = null;
let currentFileContent: string = undefined;
let currentFileOptions: any = {};
let currentFileName: any = null;
let currentFileName: any = undefined;
let refs: string[] = [];

for (let i = 0; i < lines.length; i++) {
Expand Down Expand Up @@ -1465,7 +1460,7 @@ namespace Harness {
testUnitData.push(newTestFile);

// Reset local data
currentFileContent = null;
currentFileContent = undefined;
currentFileOptions = {};
currentFileName = testMetaData[2];
refs = [];
Expand All @@ -1478,7 +1473,7 @@ namespace Harness {
else {
// Subfile content line
// Append to the current subfile content, inserting a newline needed
if (currentFileContent === null) {
if (currentFileContent === undefined) {
currentFileContent = "";
}
else {
Expand Down Expand Up @@ -1601,7 +1596,9 @@ namespace Harness {

// Store the content in the 'local' folder so we
// can accept it later (manually)
/* tslint:disable:no-null-keyword */
if (actual !== null) {
/* tslint:enable:no-null-keyword */
IO.writeFile(actualFileName, actual);
}

Expand All @@ -1618,7 +1615,9 @@ namespace Harness {

const refFileName = referencePath(relativeFileName, opts && opts.Baselinefolder, opts && opts.Subfolder);

/* tslint:disable:no-null-keyword */
if (actual === null) {
/* tslint:enable:no-null-keyword */
actual = "<no content>";
}

Expand Down
2 changes: 1 addition & 1 deletion src/harness/harnessLanguageService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ namespace Harness.LanguageService {
*/
public positionToLineAndCharacter(fileName: string, position: number): ts.LineAndCharacter {
const script: ScriptInfo = this.fileNameToScript[fileName];
assert.isNotNull(script);
assert.isOk(script);

return ts.computeLineAndCharacterOfPosition(script.getLineMap(), position);
}
Expand Down
6 changes: 3 additions & 3 deletions src/harness/loggedIO.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/// <reference path="..\..\src\compiler\sys.ts" />
/// <reference path="..\..\src\harness\harness.ts" />
/// <reference path="..\..\src\harness\runnerbase.ts" />
/* tslint:disable:no-null-keyword */

interface FileInformation {
contents: string;
Expand Down Expand Up @@ -94,7 +93,7 @@ namespace Playback {
return lookup[s] = func(s);
});
run.reset = () => {
lookup = null;
lookup = undefined;
};

return run;
Expand Down Expand Up @@ -170,7 +169,8 @@ namespace Playback {
path => callAndRecord(underlying.fileExists(path), recordLog.fileExists, { path }),
memoize(path => {
// If we read from the file, it must exist
if (findResultByPath(wrapper, replayLog.filesRead, path, null) !== null) {
const noResult = {};
if (findResultByPath(wrapper, replayLog.filesRead, path, noResult) !== noResult) {
return true;
}
else {
Expand Down
3 changes: 1 addition & 2 deletions src/harness/projectsRunner.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
///<reference path="harness.ts" />
///<reference path="runnerbase.ts" />
/* tslint:disable:no-null-keyword */

// Test case is json of below type in tests/cases/project/
interface ProjectRunnerTestCase {
Expand Down Expand Up @@ -53,7 +52,7 @@ class ProjectRunner extends RunnerBase {
private runProjectTestCase(testCaseFileName: string) {
let testCase: ProjectRunnerTestCase & ts.CompilerOptions;

let testFileText: string = null;
let testFileText: string;
try {
testFileText = Harness.IO.readFile(testCaseFileName);
}
Expand Down
2 changes: 0 additions & 2 deletions src/harness/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
/// <reference path="rwcRunner.ts" />
/// <reference path="harness.ts" />

/* tslint:disable:no-null-keyword */

let runners: RunnerBase[] = [];
let iterations = 1;

Expand Down
Loading