Zach Lute 89f43938fe Print file paths instead of file:// URLs.
This change ensures cargo will output file paths in the expected format
(C:\foo\... on Windows, /foo/... elsewhere). Previously it would output
file:// URLs instead.

To support this change, additional changes were made to the test suite
string processing such that [ROOT] is now replaced with the appropriate
file path root for the platform.

The CWD template was also updated to use [CWD] like other replacement
templates and to do the replacement on the expected value rather than
the actual value to avoid replacing things we don't expect with CWD.
2018-09-07 19:42:59 -07:00

62 lines
1.4 KiB
Rust

use std::fs::{self, File};
use std::io::prelude::*;
use std::path::PathBuf;
use support::git::{repo, Repository};
use support::paths;
use url::Url;
pub fn setup() -> Repository {
let config = paths::root().join(".cargo/config");
t!(fs::create_dir_all(config.parent().unwrap()));
t!(t!(File::create(&config)).write_all(
format!(
r#"
[registry]
token = "api-token"
[registries.alternative]
index = "{registry}"
"#,
registry = registry().to_string()
).as_bytes()
));
let credentials = paths::root().join("home/.cargo/credentials");
t!(fs::create_dir_all(credentials.parent().unwrap()));
t!(t!(File::create(&credentials)).write_all(
br#"
[registries.alternative]
token = "api-token"
"#
));
t!(fs::create_dir_all(&upload_path().join("api/v1/crates")));
repo(&registry_path())
.file(
"config.json",
&format!(
r#"{{
"dl": "{0}",
"api": "{0}"
}}"#,
upload()
),
).build()
}
pub fn registry_path() -> PathBuf {
paths::root().join("registry")
}
pub fn registry() -> Url {
Url::from_file_path(&*registry_path()).ok().unwrap()
}
pub fn upload_path() -> PathBuf {
paths::root().join("upload")
}
fn upload() -> Url {
Url::from_file_path(&*upload_path()).ok().unwrap()
}