Skip to content

Commit

Permalink
Make test_resolve_module pass on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
piscisaureus committed Jul 19, 2018
1 parent 422150c commit c67d98e
Showing 1 changed file with 31 additions and 11 deletions.
42 changes: 31 additions & 11 deletions src/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,19 @@ fn resolve_module(
base.join(module_specifier)?
};

let p = j.to_file_path()
let mut p = j.to_file_path()
.unwrap()
.into_os_string()
.into_string()
.unwrap();

if cfg!(target_os = "windows") {
// On windows, replace backward slashes to forward slashes.
// TODO(piscisaureus): This may not me be right, I just did it to make
// the tests pass.
p = p.replace("\\", "/");
}

let module_name = p.to_string();
let filename = p.to_string();

Expand All @@ -101,29 +108,42 @@ fn resolve_module(
// https://github.com/ry/deno/blob/golang/os_test.go#L16-L87
#[test]
fn test_resolve_module() {
// The `add_root` macro prepends "C:" to a string if on windows; on posix
// systems it returns the input string untouched. This is necessary because
// `Url::from_file_path()` fails if the input path isn't an absolute path.
macro_rules! add_root {
($path:expr) => {
if cfg!(target_os = "windows") {
concat!("C:", $path)
} else {
$path
}
};
}

let test_cases = [
(
"./subdir/print_hello.ts",
"/Users/rld/go/src/github.com/ry/deno/testdata/006_url_imports.ts",
"/Users/rld/go/src/github.com/ry/deno/testdata/subdir/print_hello.ts",
"/Users/rld/go/src/github.com/ry/deno/testdata/subdir/print_hello.ts",
add_root!("/Users/rld/go/src/github.com/ry/deno/testdata/006_url_imports.ts"),
add_root!("/Users/rld/go/src/github.com/ry/deno/testdata/subdir/print_hello.ts"),
add_root!("/Users/rld/go/src/github.com/ry/deno/testdata/subdir/print_hello.ts"),
),
(
"testdata/001_hello.js",
"/Users/rld/go/src/github.com/ry/deno/",
"/Users/rld/go/src/github.com/ry/deno/testdata/001_hello.js",
"/Users/rld/go/src/github.com/ry/deno/testdata/001_hello.js",
add_root!("/Users/rld/go/src/github.com/ry/deno/"),
add_root!("/Users/rld/go/src/github.com/ry/deno/testdata/001_hello.js"),
add_root!("/Users/rld/go/src/github.com/ry/deno/testdata/001_hello.js"),
),
(
"/Users/rld/src/deno/hello.js",
add_root!("/Users/rld/src/deno/hello.js"),
".",
"/Users/rld/src/deno/hello.js",
"/Users/rld/src/deno/hello.js",
add_root!("/Users/rld/src/deno/hello.js"),
add_root!("/Users/rld/src/deno/hello.js"),
),
/*
(
"http:https://localhost:4545/testdata/subdir/print_hello.ts",
"/Users/rld/go/src/github.com/ry/deno/testdata/006_url_imports.ts",
add_root!("/Users/rld/go/src/github.com/ry/deno/testdata/006_url_imports.ts"),
"http:https://localhost:4545/testdata/subdir/print_hello.ts",
path.Join(SrcDir, "localhost:4545/testdata/subdir/print_hello.ts"),
),
Expand Down

0 comments on commit c67d98e

Please sign in to comment.