Skip to content

Fix realPathMap in test harness: Must be used in directoryExists #11957

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
Oct 31, 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
23 changes: 15 additions & 8 deletions src/harness/harness.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1029,21 +1029,15 @@ namespace Harness {
},
realpath: realPathMap && ((f: string) => {
const path = ts.toPath(f, currentDirectory, getCanonicalFileName);
return realPathMap.contains(path) ? realPathMap.get(path) : path;
return realPathMap.get(path) || path;
}),
directoryExists: dir => {
let path = ts.toPath(dir, currentDirectory, getCanonicalFileName);
// Strip trailing /, which may exist if the path is a drive root
if (path[path.length - 1] === "/") {
path = <ts.Path>path.substr(0, path.length - 1);
}
let exists = false;
fileMap.forEachValue(key => {
if (key.indexOf(path) === 0 && key[path.length] === "/") {
exists = true;
}
});
return exists;
return mapHasFileInDirectory(path, fileMap) || mapHasFileInDirectory(path, realPathMap);
},
getDirectories: d => {
const path = ts.toPath(d, currentDirectory, getCanonicalFileName);
Expand All @@ -1064,6 +1058,19 @@ namespace Harness {
};
}

function mapHasFileInDirectory(directoryPath: ts.Path, map: ts.FileMap<any>): boolean {
if (!map) {
return false;
}
let exists = false;
map.forEachValue(fileName => {
if (!exists && ts.startsWith(fileName, directoryPath) && fileName[directoryPath.length] === "/") {
exists = true;
}
});
return exists;
}

interface HarnessOptions {
useCaseSensitiveFileNames?: boolean;
includeBuiltFile?: string;
Expand Down
21 changes: 0 additions & 21 deletions tests/baselines/reference/moduleResolutionWithSymlinks.errors.txt

This file was deleted.

2 changes: 1 addition & 1 deletion tests/baselines/reference/moduleResolutionWithSymlinks.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

//// [index.ts]

export class MyClass{}
export class MyClass { private x: number; }

//// [index.ts]
import {MyClass} from "library-a";
Expand Down
37 changes: 37 additions & 0 deletions tests/baselines/reference/moduleResolutionWithSymlinks.symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
=== /src/app.ts ===
import { MyClass } from "./library-a";
>MyClass : Symbol(MyClass, Decl(app.ts, 0, 8))

import { MyClass2 } from "./library-b";
>MyClass2 : Symbol(MyClass2, Decl(app.ts, 1, 8))

let x: MyClass;
>x : Symbol(x, Decl(app.ts, 3, 3))
>MyClass : Symbol(MyClass, Decl(app.ts, 0, 8))

let y: MyClass2;
>y : Symbol(y, Decl(app.ts, 4, 3))
>MyClass2 : Symbol(MyClass2, Decl(app.ts, 1, 8))

x = y;
>x : Symbol(x, Decl(app.ts, 3, 3))
>y : Symbol(y, Decl(app.ts, 4, 3))

y = x;
>y : Symbol(y, Decl(app.ts, 4, 3))
>x : Symbol(x, Decl(app.ts, 3, 3))

=== /src/library-a/index.ts ===

export class MyClass { private x: number; }
>MyClass : Symbol(MyClass, Decl(index.ts, 0, 0))
>x : Symbol(MyClass.x, Decl(index.ts, 1, 22))

=== /src/library-b/index.ts ===
import {MyClass} from "library-a";
>MyClass : Symbol(MyClass, Decl(index.ts, 0, 8))

export { MyClass as MyClass2 }
>MyClass : Symbol(MyClass2, Decl(index.ts, 1, 8))
>MyClass2 : Symbol(MyClass2, Decl(index.ts, 1, 8))

73 changes: 3 additions & 70 deletions tests/baselines/reference/moduleResolutionWithSymlinks.trace.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,74 +26,7 @@
"File '/src/library-b/node_modules/library-a.tsx' does not exist.",
"File '/src/library-b/node_modules/library-a.d.ts' does not exist.",
"File '/src/library-b/node_modules/library-a/package.json' does not exist.",
"File '/src/library-b/node_modules/library-a/index.ts' does not exist.",
"File '/src/library-b/node_modules/library-a/index.tsx' does not exist.",
"File '/src/library-b/node_modules/library-a/index.d.ts' does not exist.",
"File '/src/library-b/node_modules/@types/library-a.ts' does not exist.",
"File '/src/library-b/node_modules/@types/library-a.tsx' does not exist.",
"File '/src/library-b/node_modules/@types/library-a.d.ts' does not exist.",
"File '/src/library-b/node_modules/@types/library-a/package.json' does not exist.",
"File '/src/library-b/node_modules/@types/library-a/index.ts' does not exist.",
"File '/src/library-b/node_modules/@types/library-a/index.tsx' does not exist.",
"File '/src/library-b/node_modules/@types/library-a/index.d.ts' does not exist.",
"File '/src/node_modules/library-a.ts' does not exist.",
"File '/src/node_modules/library-a.tsx' does not exist.",
"File '/src/node_modules/library-a.d.ts' does not exist.",
"File '/src/node_modules/library-a/package.json' does not exist.",
"File '/src/node_modules/library-a/index.ts' does not exist.",
"File '/src/node_modules/library-a/index.tsx' does not exist.",
"File '/src/node_modules/library-a/index.d.ts' does not exist.",
"File '/src/node_modules/@types/library-a.ts' does not exist.",
"File '/src/node_modules/@types/library-a.tsx' does not exist.",
"File '/src/node_modules/@types/library-a.d.ts' does not exist.",
"File '/src/node_modules/@types/library-a/package.json' does not exist.",
"File '/src/node_modules/@types/library-a/index.ts' does not exist.",
"File '/src/node_modules/@types/library-a/index.tsx' does not exist.",
"File '/src/node_modules/@types/library-a/index.d.ts' does not exist.",
"File '/node_modules/library-a.ts' does not exist.",
"File '/node_modules/library-a.tsx' does not exist.",
"File '/node_modules/library-a.d.ts' does not exist.",
"File '/node_modules/library-a/package.json' does not exist.",
"File '/node_modules/library-a/index.ts' does not exist.",
"File '/node_modules/library-a/index.tsx' does not exist.",
"File '/node_modules/library-a/index.d.ts' does not exist.",
"File '/node_modules/@types/library-a.ts' does not exist.",
"File '/node_modules/@types/library-a.tsx' does not exist.",
"File '/node_modules/@types/library-a.d.ts' does not exist.",
"File '/node_modules/@types/library-a/package.json' does not exist.",
"File '/node_modules/@types/library-a/index.ts' does not exist.",
"File '/node_modules/@types/library-a/index.tsx' does not exist.",
"File '/node_modules/@types/library-a/index.d.ts' does not exist.",
"Loading module 'library-a' from 'node_modules' folder.",
"File '/src/library-b/node_modules/library-a.js' does not exist.",
"File '/src/library-b/node_modules/library-a.jsx' does not exist.",
"File '/src/library-b/node_modules/library-a/package.json' does not exist.",
"File '/src/library-b/node_modules/library-a/index.js' does not exist.",
"File '/src/library-b/node_modules/library-a/index.jsx' does not exist.",
"File '/src/library-b/node_modules/@types/library-a.js' does not exist.",
"File '/src/library-b/node_modules/@types/library-a.jsx' does not exist.",
"File '/src/library-b/node_modules/@types/library-a/package.json' does not exist.",
"File '/src/library-b/node_modules/@types/library-a/index.js' does not exist.",
"File '/src/library-b/node_modules/@types/library-a/index.jsx' does not exist.",
"File '/src/node_modules/library-a.js' does not exist.",
"File '/src/node_modules/library-a.jsx' does not exist.",
"File '/src/node_modules/library-a/package.json' does not exist.",
"File '/src/node_modules/library-a/index.js' does not exist.",
"File '/src/node_modules/library-a/index.jsx' does not exist.",
"File '/src/node_modules/@types/library-a.js' does not exist.",
"File '/src/node_modules/@types/library-a.jsx' does not exist.",
"File '/src/node_modules/@types/library-a/package.json' does not exist.",
"File '/src/node_modules/@types/library-a/index.js' does not exist.",
"File '/src/node_modules/@types/library-a/index.jsx' does not exist.",
"File '/node_modules/library-a.js' does not exist.",
"File '/node_modules/library-a.jsx' does not exist.",
"File '/node_modules/library-a/package.json' does not exist.",
"File '/node_modules/library-a/index.js' does not exist.",
"File '/node_modules/library-a/index.jsx' does not exist.",
"File '/node_modules/@types/library-a.js' does not exist.",
"File '/node_modules/@types/library-a.jsx' does not exist.",
"File '/node_modules/@types/library-a/package.json' does not exist.",
"File '/node_modules/@types/library-a/index.js' does not exist.",
"File '/node_modules/@types/library-a/index.jsx' does not exist.",
"======== Module name 'library-a' was not resolved. ========"
"File '/src/library-b/node_modules/library-a/index.ts' exist - use it as a name resolution result.",
"Resolving real path for '/src/library-b/node_modules/library-a/index.ts', result '/src/library-a/index.ts'",
"======== Module name 'library-a' was successfully resolved to '/src/library-a/index.ts'. ========"
]
39 changes: 39 additions & 0 deletions tests/baselines/reference/moduleResolutionWithSymlinks.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
=== /src/app.ts ===
import { MyClass } from "./library-a";
>MyClass : typeof MyClass

import { MyClass2 } from "./library-b";
>MyClass2 : typeof MyClass

let x: MyClass;
>x : MyClass
>MyClass : MyClass

let y: MyClass2;
>y : MyClass
>MyClass2 : MyClass

x = y;
>x = y : MyClass
>x : MyClass
>y : MyClass

y = x;
>y = x : MyClass
>y : MyClass
>x : MyClass

=== /src/library-a/index.ts ===

export class MyClass { private x: number; }
>MyClass : MyClass
>x : number

=== /src/library-b/index.ts ===
import {MyClass} from "library-a";
>MyClass : typeof MyClass

export { MyClass as MyClass2 }
>MyClass : typeof MyClass
>MyClass2 : typeof MyClass

2 changes: 1 addition & 1 deletion tests/cases/compiler/moduleResolutionWithSymlinks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

// @filename: /src/library-a/index.ts
// @symlink: /src/library-b/node_modules/library-a/index.ts
export class MyClass{}
export class MyClass { private x: number; }

// @filename: /src/library-b/index.ts
import {MyClass} from "library-a";
Expand Down