1 //! Tests for the `cargo search` command.
3 use cargo_test_support
::cargo_process
;
4 use cargo_test_support
::git
::repo
;
5 use cargo_test_support
::paths
;
6 use cargo_test_support
::registry
::{api_path, registry_path, registry_url}
;
7 use std
::collections
::HashSet
;
13 Url
::from_file_path(&*api_path()).ok().unwrap()
16 fn write_crates(dest
: &Path
) {
19 "created_at": "2014-11-16T20:17:35Z",
20 "description": "Design by contract style assertions for Rust",
21 "documentation": null,
28 "owners": "/api/v1/crates/hoare/owners",
29 "reverse_dependencies": "/api/v1/crates/hoare/reverse_dependencies",
30 "version_downloads": "/api/v1/crates/hoare/downloads",
31 "versions": "/api/v1/crates/hoare/versions"
33 "max_version": "0.1.1",
35 "repository": "https://github.com/nick29581/libhoare",
36 "updated_at": "2014-11-20T21:49:21Z",
42 "updated_at": "2020-05-01T23:17:54.335921+00:00",
48 "badge_type": "circle-ci",
50 "repository": "sfackler/rust-postgres",
55 "created_at": "2014-11-24T02:34:44.756689+00:00",
57 "recent_downloads": 88321,
58 "max_version": "0.17.3",
59 "newest_version": "0.17.3",
60 "description": "A native, synchronous PostgreSQL client",
62 "documentation": null
,
63 "repository": "https://github.com/sfackler/rust-postgres",
65 "version_downloads": "/api/v1/crates/postgres/downloads",
66 "versions": "/api/v1/crates/postgres/versions",
67 "owners": "/api/v1/crates/postgres/owners",
68 "owner_team": "/api/v1/crates/postgres/owner_team",
69 "owner_user": "/api/v1/crates/postgres/owner_user",
70 "reverse_dependencies": "/api/v1/crates/postgres/reverse_dependencies"
80 // Older versions of curl don't peel off query parameters when looking for
81 // filenames, so just make both files.
83 // On windows, though, `?` is an invalid character, but we always build curl
84 // from source there anyway!
85 fs::write(&dest, content).unwrap();
88 &dest.with_file_name("crates?q
=postgres
&per_page
=10"),
95 const SEARCH_RESULTS: &str = "\
96 hoare
= \"0.1.1\" # Design by contract style assertions for Rust
97 postgres
= \"0.17.3\" # A native, synchronous PostgreSQL client
101 let cargo_home = paths::root().join(".cargo
");
102 fs::create_dir_all(cargo_home).unwrap();
103 fs::create_dir_all(&api_path().join("api
/v1
")).unwrap();
105 // Init a new registry
106 let _ = repo(®istry_path())
109 &format!(r#"{{"dl":"{0}
","api
":"{0}
"}}"#, api()),
113 let base
= api_path().join("api/v1/crates");
117 fn set_cargo_config() {
118 let config
= paths
::root().join(".cargo/config");
125 registry = 'https://wut'
126 replace-with = 'dummy-registry'
128 [source.dummy-registry]
131 reg
= registry_url(),
142 use cargo
::core
::{Shell, Source, SourceId}
;
143 use cargo
::sources
::RegistrySource
;
144 use cargo
::util
::Config
;
146 let sid
= SourceId
::for_registry(®istry_url()).unwrap();
147 let cfg
= Config
::new(
148 Shell
::from_write(Box
::new(Vec
::new())),
150 paths
::home().join(".cargo"),
152 let lock
= cfg
.acquire_package_cache_lock().unwrap();
153 let mut regsrc
= RegistrySource
::remote(sid
, &HashSet
::new(), &cfg
);
154 regsrc
.update().unwrap();
157 cargo_process("search postgres")
158 .with_stdout_contains(SEARCH_RESULTS
)
159 .with_stderr("") // without "Updating ... index"
164 fn replace_default() {
168 cargo_process("search postgres")
169 .with_stdout_contains(SEARCH_RESULTS
)
170 .with_stderr_contains("[..]Updating [..] index")
178 cargo_process("search postgres --index")
179 .arg(registry_url().to_string())
180 .with_stdout_contains(SEARCH_RESULTS
)
185 // remove once it has been decided '--host' can be safely removed
187 fn simple_with_host() {
190 cargo_process("search postgres --host")
191 .arg(registry_url().to_string())
194 [WARNING] The flag '--host' is no longer valid.
196 Previous versions of Cargo accepted this flag, but it is being
197 deprecated. The flag is being renamed to 'index', as the flag
198 wants the location of the index. Please use '--index' instead.
200 This will soon become a hard error, so it's either recommended
201 to update to a fixed version or contact the upstream maintainer
203 [UPDATING] `[CWD]/registry` index
206 .with_stdout_contains(SEARCH_RESULTS
)
211 // remove once it has been decided '--host' can be safely removed
213 fn simple_with_index_and_host() {
216 cargo_process("search postgres --index")
217 .arg(registry_url().to_string())
219 .arg(registry_url().to_string())
222 [WARNING] The flag '--host' is no longer valid.
224 Previous versions of Cargo accepted this flag, but it is being
225 deprecated. The flag is being renamed to 'index', as the flag
226 wants the location of the index. Please use '--index' instead.
228 This will soon become a hard error, so it's either recommended
229 to update to a fixed version or contact the upstream maintainer
231 [UPDATING] `[CWD]/registry` index
234 .with_stdout_contains(SEARCH_RESULTS
)
239 fn multiple_query_params() {
242 cargo_process("search postgres sql --index")
243 .arg(registry_url().to_string())
244 .with_stdout_contains(SEARCH_RESULTS
)