Skip to content

Commit 865cd5a

Browse files
committed
2 parents 0a3f2b4 + 88f3bb9 commit 865cd5a

File tree

2 files changed

+32
-20
lines changed

2 files changed

+32
-20
lines changed

src/cargo/core/source/mod.rs

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -264,11 +264,6 @@ impl<'src> SourceMap<'src> {
264264
}
265265
}
266266

267-
/// Like `HashMap::contains_key`.
268-
pub fn contains(&self, id: SourceId) -> bool {
269-
self.map.contains_key(&id)
270-
}
271-
272267
/// Like `HashMap::get`.
273268
pub fn get(&self, id: SourceId) -> Option<&(dyn Source + 'src)> {
274269
self.map.get(&id).map(|s| s.as_ref())
@@ -279,32 +274,17 @@ impl<'src> SourceMap<'src> {
279274
self.map.get_mut(&id).map(|s| s.as_mut())
280275
}
281276

282-
/// Like `HashMap::get`, but first calculates the `SourceId` from a `PackageId`.
283-
pub fn get_by_package_id(&self, pkg_id: PackageId) -> Option<&(dyn Source + 'src)> {
284-
self.get(pkg_id.source_id())
285-
}
286-
287277
/// Like `HashMap::insert`, but derives the `SourceId` key from the `Source`.
288278
pub fn insert(&mut self, source: Box<dyn Source + 'src>) {
289279
let id = source.source_id();
290280
self.map.insert(id, source);
291281
}
292282

293-
/// Like `HashMap::is_empty`.
294-
pub fn is_empty(&self) -> bool {
295-
self.map.is_empty()
296-
}
297-
298283
/// Like `HashMap::len`.
299284
pub fn len(&self) -> usize {
300285
self.map.len()
301286
}
302287

303-
/// Like `HashMap::values`.
304-
pub fn sources<'a>(&'a self) -> impl Iterator<Item = &'a Box<dyn Source + 'src>> {
305-
self.map.values()
306-
}
307-
308288
/// Like `HashMap::iter_mut`.
309289
pub fn sources_mut<'a>(
310290
&'a mut self,

tests/testsuite/registry.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ use cargo_test_support::{cargo_process, registry::registry_url};
88
use cargo_test_support::{git, install::cargo_home, t};
99
use cargo_util::paths::remove_dir_all;
1010
use std::fs::{self, File};
11+
use std::io::{BufRead, BufReader, Write};
1112
use std::path::Path;
13+
use std::process::Stdio;
1214

1315
#[cargo_test]
1416
fn simple() {
@@ -883,6 +885,36 @@ fn login_with_differently_sized_token() {
883885
assert_eq!(credentials, "[registry]\ntoken = \"lmaolmaolmao\"\n");
884886
}
885887

888+
#[cargo_test]
889+
fn login_with_token_on_stdin() {
890+
registry::init();
891+
let credentials = paths::home().join(".cargo/credentials");
892+
fs::remove_file(&credentials).unwrap();
893+
cargo_process("login lmao -v").run();
894+
let mut cargo = cargo_process("login").build_command();
895+
cargo
896+
.stdin(Stdio::piped())
897+
.stdout(Stdio::piped())
898+
.stderr(Stdio::piped());
899+
let mut child = cargo.spawn().unwrap();
900+
let out = BufReader::new(child.stdout.as_mut().unwrap())
901+
.lines()
902+
.next()
903+
.unwrap()
904+
.unwrap();
905+
assert!(out.starts_with("please paste the API Token found on "));
906+
assert!(out.ends_with("/me below"));
907+
child
908+
.stdin
909+
.as_ref()
910+
.unwrap()
911+
.write_all(b"some token\n")
912+
.unwrap();
913+
child.wait().unwrap();
914+
let credentials = fs::read_to_string(&credentials).unwrap();
915+
assert_eq!(credentials, "[registry]\ntoken = \"some token\"\n");
916+
}
917+
886918
#[cargo_test]
887919
fn bad_license_file() {
888920
Package::new("foo", "1.0.0").publish();

0 commit comments

Comments
 (0)