Skip to content

Commit

Permalink
WIP tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nrc committed Feb 26, 2019
1 parent b999849 commit 63cd03e
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 13 deletions.
16 changes: 4 additions & 12 deletions src/rustup-cli/rustup_mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,7 @@ pub fn cli() -> App<'static, 'static> {
.about("Show the active toolchain")
.after_help(SHOW_ACTIVE_TOOLCHAIN_HELP),
)
.subcommand(
SubCommand::with_name("profile")
.about("Show the current profile"),
),
.subcommand(SubCommand::with_name("profile").about("Show the current profile")),
)
.subcommand(
SubCommand::with_name("install")
Expand Down Expand Up @@ -1054,10 +1051,6 @@ fn self_uninstall(m: &ArgMatches<'_>) -> Result<()> {
self_update::uninstall(no_prompt)
}

<<<<<<< HEAD
fn set_default_host_triple(cfg: &Cfg, m: &ArgMatches<'_>) -> Result<()> {
cfg.set_default_host_triple(m.value_of("host_triple").expect(""))?;
=======
fn set_telemetry(cfg: &Cfg, t: TelemetryMode) -> Result<()> {
match t {
TelemetryMode::On => Ok(cfg.set_telemetry(true)?),
Expand All @@ -1070,8 +1063,8 @@ fn analyze_telemetry(cfg: &Cfg) -> Result<()> {
common::show_telemetry(analysis)
}

fn set_default_host_triple(cfg: &Cfg, m: &ArgMatches) -> Result<()> {
cfg.set_default_host_triple(m.value_of("host_triple").unwrap())?;
fn set_default_host_triple(cfg: &Cfg, m: &ArgMatches<'_>) -> Result<()> {
cfg.set_default_host_triple(m.value_of("host_triple").expect(""))?;
Ok(())
}

Expand All @@ -1081,7 +1074,6 @@ fn set_profile(cfg: &Cfg, m: &ArgMatches) -> Result<()> {
}

fn show_profile(cfg: &Cfg) -> Result<()> {
println!("{}", cfg.get_profile()?);
>>>>>>> show and set profiles in the CLI
println!("{}", cfg.get_profile()?);
Ok(())
}
2 changes: 2 additions & 0 deletions src/rustup-mock/src/clitools.rs
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,7 @@ fn build_mock_channel(
date: date.to_string(),
packages,
renames,
has_profiles: false,
}
}

Expand Down Expand Up @@ -655,6 +656,7 @@ fn build_mock_unavailable_channel(channel: &str, date: &str, version: &'static s
date: date.to_string(),
packages,
renames: HashMap::new(),
has_profiles: false,
}
}

Expand Down
21 changes: 21 additions & 0 deletions src/rustup-mock/src/dist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ pub struct MockChannel {
pub date: String,
pub packages: Vec<MockPackage>,
pub renames: HashMap<String, String>,
pub has_profiles: bool,
}

// A single rust-installer package
Expand Down Expand Up @@ -399,6 +400,26 @@ impl MockDistServer {
}
toml_manifest.insert(String::from("renames"), toml::Value::Table(toml_renames));

if channel.has_profiles {
let mut toml_profiles = toml::value::Table::new();
let profiles = &[
("minimal", vec!["rustc", "cargo", "rust-std"]),
("default", vec!["rustc", "cargo", "rust-std", "rust-docs"]),
(
"complete",
vec!["rustc", "cargo", "rust-std", "rust-docs", "rust-src"],
),
];
for (profile, values) in profiles {
let array = values
.into_iter()
.map(|v| toml::Value::String((**v).to_owned()))
.collect();
toml_profiles.insert(profile.to_string(), toml::Value::Array(array));
}
toml_manifest.insert(String::from("profiles"), toml::Value::Table(toml_profiles));
}

let manifest_name = format!("dist/channel-rust-{}", channel.name);
let ref manifest_path = self.path.join(format!("{}.toml", manifest_name));
write_file(manifest_path, &toml::to_string(&toml_manifest).unwrap());
Expand Down
6 changes: 5 additions & 1 deletion tests/cli-misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -794,6 +794,10 @@ fn profiles() {
expect_stdout_ok(config, &["rustup", "show", "profile"], "default");
expect_ok(config, &["rustup", "set", "profile", "minimal"]);
expect_stdout_ok(config, &["rustup", "show", "profile"], "minimal");
expect_err(config, &["rustup", "set", "profile", "maximal"], "unknown profile");
expect_err(
config,
&["rustup", "set", "profile", "maximal"],
"unknown profile",
);
});
}

0 comments on commit 63cd03e

Please sign in to comment.