diff --git a/tests/cli-exact.rs b/tests/cli-exact.rs index cea9a94270..f274c617fe 100644 --- a/tests/cli-exact.rs +++ b/tests/cli-exact.rs @@ -1,7 +1,7 @@ //! Yet more cli test cases. These are testing that the output //! is exactly as expected. -pub mod mock; +pub(crate) mod mock; use crate::mock::clitools::{ self, check_update_setup, expect_err_ex, expect_ok, expect_ok_ex, expect_stdout_ok, diff --git a/tests/cli-inst-interactive.rs b/tests/cli-inst-interactive.rs index 3cb2048d9a..95c261ef49 100644 --- a/tests/cli-inst-interactive.rs +++ b/tests/cli-inst-interactive.rs @@ -1,6 +1,6 @@ //! Tests of the interactive console installer -pub mod mock; +pub(crate) mod mock; use std::env::consts::EXE_SUFFIX; use std::io::Write; diff --git a/tests/cli-misc.rs b/tests/cli-misc.rs index 25212f93bc..2159ab83dd 100644 --- a/tests/cli-misc.rs +++ b/tests/cli-misc.rs @@ -1,7 +1,7 @@ //! Test cases of the rustup command that do not depend on the //! dist server, mostly derived from multirust/test-v2.sh -pub mod mock; +pub(crate) mod mock; use std::env::consts::EXE_SUFFIX; use std::str; @@ -16,7 +16,7 @@ use crate::mock::clitools::{ expect_stderr_ok, expect_stdout_ok, run, set_current_dist_date, Config, Scenario, }; -pub fn setup(f: &dyn Fn(&mut Config)) { +pub(crate) fn setup(f: &dyn Fn(&mut Config)) { clitools::setup(Scenario::SimpleV2, f); } diff --git a/tests/cli-paths.rs b/tests/cli-paths.rs index 3fea4ef1a2..e9b55a07b7 100644 --- a/tests/cli-paths.rs +++ b/tests/cli-paths.rs @@ -1,7 +1,7 @@ //! This file contains tests relevant to Rustup's handling of updating PATHs. //! It depends on self-update working, so if absolutely everything here breaks, //! check those tests as well. -pub mod mock; +pub(crate) mod mock; // Prefer omitting actually unpacking content while just testing paths. const INIT_NONE: [&str; 4] = ["rustup-init", "-y", "--default-toolchain", "none"]; diff --git a/tests/cli-rustup.rs b/tests/cli-rustup.rs index 34ec14ede0..8642afac86 100644 --- a/tests/cli-rustup.rs +++ b/tests/cli-rustup.rs @@ -1,6 +1,6 @@ //! Test cases for new rustup UI -pub mod mock; +pub(crate) mod mock; use std::env::consts::EXE_SUFFIX; use std::fs; @@ -21,7 +21,7 @@ macro_rules! for_host_and_home { }; } -pub fn setup(f: &dyn Fn(&Config)) { +pub(crate) fn setup(f: &dyn Fn(&Config)) { clitools::setup(Scenario::ArchivesV2, &|config| { f(config); }); diff --git a/tests/cli-self-upd.rs b/tests/cli-self-upd.rs index 916a37fc8e..ee2239b4a7 100644 --- a/tests/cli-self-upd.rs +++ b/tests/cli-self-upd.rs @@ -1,6 +1,6 @@ //! Testing self install, uninstall and update -pub mod mock; +pub(crate) mod mock; use std::env; use std::env::consts::EXE_SUFFIX; @@ -24,7 +24,7 @@ use crate::mock::dist::calc_hash; const TEST_VERSION: &str = "1.1.1"; -pub fn update_setup(f: &dyn Fn(&Config, &Path)) { +pub(crate) fn update_setup(f: &dyn Fn(&Config, &Path)) { self_update_setup(f, TEST_VERSION) } diff --git a/tests/cli-v1.rs b/tests/cli-v1.rs index c6b11eedd1..4947cfd2d1 100644 --- a/tests/cli-v1.rs +++ b/tests/cli-v1.rs @@ -1,7 +1,7 @@ //! Test cases of the rustup command, using v1 manifests, mostly //! derived from multirust/test-v2.sh -pub mod mock; +pub(crate) mod mock; use std::fs; @@ -12,7 +12,7 @@ use crate::mock::clitools::{ Scenario, }; -pub fn setup(f: &dyn Fn(&mut Config)) { +pub(crate) fn setup(f: &dyn Fn(&mut Config)) { clitools::setup(Scenario::SimpleV1, f); } diff --git a/tests/cli-v2.rs b/tests/cli-v2.rs index d2d9284156..8dd248e4bc 100644 --- a/tests/cli-v2.rs +++ b/tests/cli-v2.rs @@ -1,7 +1,7 @@ //! Test cases of the rustup command, using v2 manifests, mostly //! derived from multirust/test-v2.sh -pub mod mock; +pub(crate) mod mock; use std::fs; use std::io::Write; @@ -16,11 +16,11 @@ use crate::mock::clitools::{ expect_stdout_ok, set_current_dist_date, Config, Scenario, }; -pub fn setup(f: &dyn Fn(&mut Config)) { +pub(crate) fn setup(f: &dyn Fn(&mut Config)) { clitools::setup(Scenario::SimpleV2, f); } -pub fn setup_complex(f: &dyn Fn(&mut Config)) { +pub(crate) fn setup_complex(f: &dyn Fn(&mut Config)) { clitools::setup(Scenario::UnavailableRls, f); } diff --git a/tests/dist.rs b/tests/dist.rs index 012b8c1706..5a98bc1786 100644 --- a/tests/dist.rs +++ b/tests/dist.rs @@ -1,7 +1,7 @@ // Tests of installation and updates from a v2 Rust distribution // server (mocked on the file system) -pub mod mock; +pub(crate) mod mock; use std::cell::Cell; use std::collections::HashMap; @@ -33,7 +33,7 @@ use crate::mock::{MockComponentBuilder, MockFile, MockInstallerBuilder}; const SHA256_HASH_LEN: usize = 64; // Creates a mock dist server populated with some test data -pub fn create_mock_dist_server( +pub(crate) fn create_mock_dist_server( path: &Path, edit: Option<&dyn Fn(&str, &mut MockChannel)>, ) -> MockDistServer { @@ -46,7 +46,7 @@ pub fn create_mock_dist_server( } } -pub fn create_mock_channel( +pub(crate) fn create_mock_channel( channel: &str, date: &str, edit: Option<&dyn Fn(&str, &mut MockChannel)>, diff --git a/tests/dist_install.rs b/tests/dist_install.rs index 4f294c6cd4..c097bbf190 100644 --- a/tests/dist_install.rs +++ b/tests/dist_install.rs @@ -1,4 +1,4 @@ -pub mod mock; +pub(crate) mod mock; use crate::mock::{MockComponentBuilder, MockFile, MockInstallerBuilder}; use rustup::dist::component::Components; diff --git a/tests/mock/clitools.rs b/tests/mock/clitools.rs index 3b33b774c0..9455db3460 100644 --- a/tests/mock/clitools.rs +++ b/tests/mock/clitools.rs @@ -28,31 +28,31 @@ use crate::mock::topical_doc_data; use crate::mock::{MockComponentBuilder, MockFile, MockInstallerBuilder}; /// The configuration used by the tests in this module -pub struct Config { +pub(crate) struct Config { /// Where we put the rustup / rustc / cargo bins - pub exedir: PathBuf, + pub(crate) exedir: PathBuf, /// The distribution server - pub distdir: PathBuf, + pub(crate) distdir: PathBuf, /// RUSTUP_HOME - pub rustupdir: rustup_test::RustupHome, + pub(crate) rustupdir: rustup_test::RustupHome, /// Custom toolchains - pub customdir: PathBuf, + pub(crate) customdir: PathBuf, /// CARGO_HOME - pub cargodir: PathBuf, + pub(crate) cargodir: PathBuf, /// ~ - pub homedir: PathBuf, + pub(crate) homedir: PathBuf, /// An empty directory. Tests should not write to this. - pub emptydir: PathBuf, + pub(crate) emptydir: PathBuf, /// Root for updates to rustup itself aka RUSTUP_UPDATE_ROOT - pub rustup_update_root: Option, + pub(crate) rustup_update_root: Option, /// This is cwd for the test - pub workdir: RefCell, + pub(crate) workdir: RefCell, } // Describes all the features of the mock dist server. // Building the mock server is slow, so use simple scenario when possible. #[derive(PartialEq, Copy, Clone)] -pub enum Scenario { +pub(crate) enum Scenario { /// No dist server content Empty, /// Two dates, two manifests @@ -82,18 +82,18 @@ pub enum Scenario { MissingComponentMulti, } -pub static CROSS_ARCH1: &str = "x86_64-unknown-linux-musl"; -pub static CROSS_ARCH2: &str = "arm-linux-androideabi"; +pub(crate) static CROSS_ARCH1: &str = "x86_64-unknown-linux-musl"; +pub(crate) static CROSS_ARCH2: &str = "arm-linux-androideabi"; // Architecture for testing 'multi-host' installation. #[cfg(target_pointer_width = "64")] -pub static MULTI_ARCH1: &str = "i686-unknown-linux-gnu"; +pub(crate) static MULTI_ARCH1: &str = "i686-unknown-linux-gnu"; #[cfg(not(target_pointer_width = "64"))] -pub static MULTI_ARCH1: &str = "x86_64-unknown-linux-gnu"; +pub(crate) static MULTI_ARCH1: &str = "x86_64-unknown-linux-gnu"; /// Run this to create the test environment containing rustup, and /// a mock dist server. -pub fn setup(s: Scenario, f: &dyn Fn(&mut Config)) { +pub(crate) fn setup(s: Scenario, f: &dyn Fn(&mut Config)) { // Unset env variables that will break our testing env::remove_var("RUSTUP_UPDATE_ROOT"); env::remove_var("RUSTUP_TOOLCHAIN"); @@ -203,7 +203,7 @@ fn create_local_update_server(self_dist: &Path, config: &mut Config, version: &s config.rustup_update_root = Some(root_url); } -pub fn check_update_setup(f: &dyn Fn(&mut Config)) { +pub(crate) fn check_update_setup(f: &dyn Fn(&mut Config)) { let version = env!("CARGO_PKG_VERSION"); setup(Scenario::ArchivesV2, &|config| { @@ -219,7 +219,7 @@ pub fn check_update_setup(f: &dyn Fn(&mut Config)) { }); } -pub fn self_update_setup(f: &dyn Fn(&Config, &Path), version: &str) { +pub(crate) fn self_update_setup(f: &dyn Fn(&Config, &Path), version: &str) { setup(Scenario::SimpleV2, &|config| { // Create a mock self-update server let self_dist_tmp = tempfile::Builder::new() @@ -241,7 +241,7 @@ pub fn self_update_setup(f: &dyn Fn(&Config, &Path), version: &str) { }); } -pub fn output_release_file(dist_dir: &Path, schema: &str, version: &str) { +pub(crate) fn output_release_file(dist_dir: &Path, schema: &str, version: &str) { let contents = format!( r#" schema-version = "{}" @@ -254,11 +254,11 @@ version = "{}" } impl Config { - pub fn current_dir(&self) -> PathBuf { + pub(crate) fn current_dir(&self) -> PathBuf { self.workdir.borrow().clone() } - pub fn change_dir(&self, path: &Path, mut f: F) + pub(crate) fn change_dir(&self, path: &Path, mut f: F) where F: FnMut(), { @@ -271,7 +271,7 @@ impl Config { *self.workdir.borrow_mut() = prev; } - pub fn create_rustup_sh_metadata(&self) { + pub(crate) fn create_rustup_sh_metadata(&self) { let rustup_dir = self.homedir.join(".rustup"); fs::create_dir_all(&rustup_dir).unwrap(); let version_file = rustup_dir.join("rustup-version"); @@ -280,14 +280,14 @@ impl Config { } /// Change the current distribution manifest to a particular date -pub fn set_current_dist_date(config: &Config, date: &str) { +pub(crate) fn set_current_dist_date(config: &Config, date: &str) { let url = Url::from_file_path(&config.distdir).unwrap(); for channel in &["nightly", "beta", "stable"] { change_channel_date(&url, channel, date); } } -pub fn expect_ok(config: &Config, args: &[&str]) { +pub(crate) fn expect_ok(config: &Config, args: &[&str]) { let out = run(config, args[0], &args[1..], &[]); if !out.ok { print_command(args, &out); @@ -296,7 +296,7 @@ pub fn expect_ok(config: &Config, args: &[&str]) { } } -pub fn expect_err(config: &Config, args: &[&str], expected: &str) { +pub(crate) fn expect_err(config: &Config, args: &[&str], expected: &str) { let out = run(config, args[0], &args[1..], &[]); if out.ok || !out.stderr.contains(expected) { print_command(args, &out); @@ -306,7 +306,7 @@ pub fn expect_err(config: &Config, args: &[&str], expected: &str) { } } -pub fn expect_stdout_ok(config: &Config, args: &[&str], expected: &str) { +pub(crate) fn expect_stdout_ok(config: &Config, args: &[&str], expected: &str) { let out = run(config, args[0], &args[1..], &[]); if !out.ok || !out.stdout.contains(expected) { print_command(args, &out); @@ -316,7 +316,7 @@ pub fn expect_stdout_ok(config: &Config, args: &[&str], expected: &str) { } } -pub fn expect_not_stdout_ok(config: &Config, args: &[&str], expected: &str) { +pub(crate) fn expect_not_stdout_ok(config: &Config, args: &[&str], expected: &str) { let out = run(config, args[0], &args[1..], &[]); if !out.ok || out.stdout.contains(expected) { print_command(args, &out); @@ -326,7 +326,7 @@ pub fn expect_not_stdout_ok(config: &Config, args: &[&str], expected: &str) { } } -pub fn expect_not_stderr_ok(config: &Config, args: &[&str], expected: &str) { +pub(crate) fn expect_not_stderr_ok(config: &Config, args: &[&str], expected: &str) { let out = run(config, args[0], &args[1..], &[]); if !out.ok || out.stderr.contains(expected) { print_command(args, &out); @@ -336,7 +336,7 @@ pub fn expect_not_stderr_ok(config: &Config, args: &[&str], expected: &str) { } } -pub fn expect_not_stderr_err(config: &Config, args: &[&str], expected: &str) { +pub(crate) fn expect_not_stderr_err(config: &Config, args: &[&str], expected: &str) { let out = run(config, args[0], &args[1..], &[]); if out.ok || out.stderr.contains(expected) { print_command(args, &out); @@ -346,7 +346,7 @@ pub fn expect_not_stderr_err(config: &Config, args: &[&str], expected: &str) { } } -pub fn expect_stderr_ok(config: &Config, args: &[&str], expected: &str) { +pub(crate) fn expect_stderr_ok(config: &Config, args: &[&str], expected: &str) { let out = run(config, args[0], &args[1..], &[]); if !out.ok || !out.stderr.contains(expected) { print_command(args, &out); @@ -356,7 +356,7 @@ pub fn expect_stderr_ok(config: &Config, args: &[&str], expected: &str) { } } -pub fn expect_ok_ex(config: &Config, args: &[&str], stdout: &str, stderr: &str) { +pub(crate) fn expect_ok_ex(config: &Config, args: &[&str], stdout: &str, stderr: &str) { let out = run(config, args[0], &args[1..], &[]); if !out.ok || out.stdout != stdout || out.stderr != stderr { print_command(args, &out); @@ -369,7 +369,7 @@ pub fn expect_ok_ex(config: &Config, args: &[&str], stdout: &str, stderr: &str) } } -pub fn expect_err_ex(config: &Config, args: &[&str], stdout: &str, stderr: &str) { +pub(crate) fn expect_err_ex(config: &Config, args: &[&str], stdout: &str, stderr: &str) { let out = run(config, args[0], &args[1..], &[]); if out.ok || out.stdout != stdout || out.stderr != stderr { print_command(args, &out); @@ -380,7 +380,7 @@ pub fn expect_err_ex(config: &Config, args: &[&str], stdout: &str, stderr: &str) } } -pub fn expect_ok_contains(config: &Config, args: &[&str], stdout: &str, stderr: &str) { +pub(crate) fn expect_ok_contains(config: &Config, args: &[&str], stdout: &str, stderr: &str) { let out = run(config, args[0], &args[1..], &[]); if !out.ok || !out.stdout.contains(stdout) || !out.stderr.contains(stderr) { print_command(args, &out); @@ -391,7 +391,7 @@ pub fn expect_ok_contains(config: &Config, args: &[&str], stdout: &str, stderr: } } -pub fn expect_ok_eq(config: &Config, args1: &[&str], args2: &[&str]) { +pub(crate) fn expect_ok_eq(config: &Config, args1: &[&str], args2: &[&str]) { let out1 = run(config, args1[0], &args1[1..], &[]); let out2 = run(config, args2[0], &args2[1..], &[]); if !out1.ok || !out2.ok || out1.stdout != out2.stdout || out1.stderr != out2.stderr { @@ -403,7 +403,7 @@ pub fn expect_ok_eq(config: &Config, args1: &[&str], args2: &[&str]) { } } -pub fn expect_component_executable(config: &Config, cmd: &str) { +pub(crate) fn expect_component_executable(config: &Config, cmd: &str) { let out1 = run(config, cmd, &["--version"], &[]); if !out1.ok { print_command(&[cmd, "--version"], &out1); @@ -412,7 +412,7 @@ pub fn expect_component_executable(config: &Config, cmd: &str) { } } -pub fn expect_component_not_executable(config: &Config, cmd: &str) { +pub(crate) fn expect_component_not_executable(config: &Config, cmd: &str) { let out1 = run(config, cmd, &["--version"], &[]); if out1.ok { print_command(&[cmd, "--version"], &out1); @@ -445,20 +445,20 @@ fn print_indented(heading: &str, text: &str) { ); } -pub struct Output { - pub status: Option, - pub stdout: Vec, - pub stderr: Vec, +pub(crate) struct Output { + pub(crate) status: Option, + pub(crate) stdout: Vec, + pub(crate) stderr: Vec, } #[derive(Debug)] -pub struct SanitizedOutput { - pub ok: bool, - pub stdout: String, - pub stderr: String, +pub(crate) struct SanitizedOutput { + pub(crate) ok: bool, + pub(crate) stdout: String, + pub(crate) stderr: String, } -pub fn cmd(config: &Config, name: &str, args: I) -> Command +pub(crate) fn cmd(config: &Config, name: &str, args: I) -> Command where I: IntoIterator, A: AsRef, @@ -471,7 +471,7 @@ where cmd } -pub fn env(config: &Config, cmd: &mut E) { +pub(crate) fn env(config: &Config, cmd: &mut E) { // Ensure PATH is prefixed with the rustup-exe directory let prev_path = env::var_os("PATH"); let mut new_path = config.exedir.clone().into_os_string(); @@ -531,7 +531,7 @@ use std::sync::RwLock; /// environments. In doing this we can ensure that new test environment creation /// does not result in ETXTBSY because the FDs in question happen to be in /// newly `fork()`d but not yet `exec()`d subprocesses of other tests. -pub fn cmd_lock() -> &'static RwLock<()> { +pub(crate) fn cmd_lock() -> &'static RwLock<()> { lazy_static! { static ref LOCK: RwLock<()> = RwLock::new(()); }; @@ -575,7 +575,12 @@ where !(run || self_cmd || version || (is_update && !no_self_update)) } -pub fn run(config: &Config, name: &str, args: I, env: &[(&str, &str)]) -> SanitizedOutput +pub(crate) fn run( + config: &Config, + name: &str, + args: I, + env: &[(&str, &str)], +) -> SanitizedOutput where I: IntoIterator + Clone, A: AsRef, @@ -600,7 +605,12 @@ where output } -pub fn run_inprocess(config: &Config, name: &str, args: I, env: &[(&str, &str)]) -> Output +pub(crate) fn run_inprocess( + config: &Config, + name: &str, + args: I, + env: &[(&str, &str)], +) -> Output where I: IntoIterator, A: AsRef, @@ -643,7 +653,12 @@ where } } -pub fn run_subprocess(config: &Config, name: &str, args: I, env: &[(&str, &str)]) -> Output +pub(crate) fn run_subprocess( + config: &Config, + name: &str, + args: I, + env: &[(&str, &str)], +) -> Output where I: IntoIterator, A: AsRef, @@ -1343,7 +1358,7 @@ fn create_custom_toolchains(customdir: &Path) { } } -pub fn hard_link(a: A, b: B) -> io::Result<()> +pub(crate) fn hard_link(a: A, b: B) -> io::Result<()> where A: AsRef, B: AsRef, @@ -1358,7 +1373,7 @@ where inner(a.as_ref(), b.as_ref()) } -pub fn copy_binary(a: A, b: B) -> io::Result<()> +pub(crate) fn copy_binary(a: A, b: B) -> io::Result<()> where A: AsRef, B: AsRef, diff --git a/tests/mock/dist.rs b/tests/mock/dist.rs index 437f261304..a6eb8e7601 100644 --- a/tests/mock/dist.rs +++ b/tests/mock/dist.rs @@ -16,7 +16,7 @@ use crate::mock::clitools::hard_link; // This function changes the mock manifest for a given channel to that // of a particular date. For advancing the build from e.g. 2016-02-1 // to 2016-02-02 -pub fn change_channel_date(dist_server: &Url, channel: &str, date: &str) { +pub(crate) fn change_channel_date(dist_server: &Url, channel: &str, date: &str) { let path = dist_server.to_file_path().unwrap(); // V2 @@ -61,67 +61,67 @@ pub fn change_channel_date(dist_server: &Url, channel: &str, date: &str) { } // The manifest version created by this mock -pub const MOCK_MANIFEST_VERSION: &str = "2"; +pub(crate) const MOCK_MANIFEST_VERSION: &str = "2"; // A mock Rust v2 distribution server. Create it and and run `write` // to write its structure to a directory. -pub struct MockDistServer { +pub(crate) struct MockDistServer { // The local path to the dist server root - pub path: PathBuf, - pub channels: Vec, + pub(crate) path: PathBuf, + pub(crate) channels: Vec, } // A Rust distribution channel -pub struct MockChannel { +pub(crate) struct MockChannel { // e.g. "nightly" - pub name: String, + pub(crate) name: String, // YYYY-MM-DD - pub date: String, - pub packages: Vec, - pub renames: HashMap, + pub(crate) date: String, + pub(crate) packages: Vec, + pub(crate) renames: HashMap, } // A single rust-installer package #[derive(Debug, Hash, Eq, PartialEq)] -pub struct MockPackage { +pub(crate) struct MockPackage { // rust, rustc, rust-std-$triple, rust-doc, etc. - pub name: &'static str, - pub version: String, - pub targets: Vec, + pub(crate) name: &'static str, + pub(crate) version: String, + pub(crate) targets: Vec, } #[derive(Debug, Hash, Eq, PartialEq, Clone)] -pub struct MockTargetedPackage { +pub(crate) struct MockTargetedPackage { // Target triple - pub target: String, + pub(crate) target: String, // Whether the file actually exists (could be due to build failure) - pub available: bool, - pub components: Vec, + pub(crate) available: bool, + pub(crate) components: Vec, // The mock rust-installer - pub installer: MockInstallerBuilder, + pub(crate) installer: MockInstallerBuilder, } #[derive(Debug, PartialEq, Eq, Hash, Clone)] -pub struct MockComponent { - pub name: String, - pub target: String, - pub is_extension: bool, +pub(crate) struct MockComponent { + pub(crate) name: String, + pub(crate) target: String, + pub(crate) is_extension: bool, } #[derive(Clone)] -pub struct MockHashes { - pub gz: String, - pub xz: Option, - pub zst: Option, +pub(crate) struct MockHashes { + pub(crate) gz: String, + pub(crate) xz: Option, + pub(crate) zst: Option, } -pub enum ManifestVersion { +pub(crate) enum ManifestVersion { V1, V2, } impl MockDistServer { - pub fn write(&self, vs: &[ManifestVersion], enable_xz: bool, enable_zst: bool) { + pub(crate) fn write(&self, vs: &[ManifestVersion], enable_xz: bool, enable_zst: bool) { fs::create_dir_all(&self.path).unwrap(); for channel in self.channels.iter() { @@ -506,7 +506,7 @@ fn create_tarball(relpath: &Path, src: &Path, dst: &Path) -> io::Result<()> { tar.finish() } -pub fn calc_hash(src: &Path) -> String { +pub(crate) fn calc_hash(src: &Path) -> String { let mut buf = Vec::new(); File::open(src).unwrap().read_to_end(&mut buf).unwrap(); let mut hasher = Sha256::new(); @@ -514,7 +514,7 @@ pub fn calc_hash(src: &Path) -> String { format!("{:x}", hasher.finalize()) } -pub fn create_hash(src: &Path, dst: &Path) -> String { +pub(crate) fn create_hash(src: &Path, dst: &Path) -> String { let hex = calc_hash(src); let src_file = src.file_name().unwrap(); let file_contents = format!("{} *{}\n", hex, src_file.to_string_lossy()); @@ -522,7 +522,7 @@ pub fn create_hash(src: &Path, dst: &Path) -> String { hex } -pub fn write_file(dst: &Path, contents: &str) { +pub(crate) fn write_file(dst: &Path, contents: &str) { drop(fs::remove_file(dst)); File::create(dst) .and_then(|mut f| f.write_all(contents.as_bytes())) @@ -539,7 +539,7 @@ fn get_secret_key() -> pgp::SignedSecretKey { key } -pub fn get_public_key() -> pgp::SignedPublicKey { +pub(crate) fn get_public_key() -> pgp::SignedPublicKey { use pgp::Deserializable; let (key, _) = pgp::SignedPublicKey::from_armor_single(std::io::Cursor::new(PUB_SIGNING_KEY_BYTES)) @@ -547,7 +547,7 @@ pub fn get_public_key() -> pgp::SignedPublicKey { key } -pub fn create_signature(data: &[u8]) -> std::result::Result { +pub(crate) fn create_signature(data: &[u8]) -> std::result::Result { let key = get_secret_key(); let msg = pgp::Message::new_literal_bytes("message", data); diff --git a/tests/mock/mod.rs b/tests/mock/mod.rs index 6407783faa..b351148de1 100644 --- a/tests/mock/mod.rs +++ b/tests/mock/mod.rs @@ -1,8 +1,8 @@ //! Mocks for testing -pub mod clitools; -pub mod dist; -pub mod topical_doc_data; +pub(crate) mod clitools; +pub(crate) mod dist; +pub(crate) mod topical_doc_data; use std::fs::{self, File, OpenOptions}; use std::io::Write; @@ -11,18 +11,18 @@ use std::sync::Arc; // Mock of the on-disk structure of rust-installer installers #[derive(Debug, PartialEq, Eq, Hash, Clone)] -pub struct MockInstallerBuilder { - pub components: Vec, +pub(crate) struct MockInstallerBuilder { + pub(crate) components: Vec, } #[derive(Debug, PartialEq, Eq, Hash, Clone)] -pub struct MockComponentBuilder { - pub name: String, - pub files: Vec, +pub(crate) struct MockComponentBuilder { + pub(crate) name: String, + pub(crate) files: Vec, } #[derive(Debug, PartialEq, Eq, Hash, Clone)] -pub struct MockFile { +pub(crate) struct MockFile { path: String, contents: Contents, } @@ -49,7 +49,7 @@ impl std::fmt::Debug for MockContents { } impl MockInstallerBuilder { - pub fn build(&self, path: &Path) { + pub(crate) fn build(&self, path: &Path) { for component in &self.components { // Update the components file let comp_file = path.join("components"); @@ -88,11 +88,11 @@ impl MockInstallerBuilder { } impl MockFile { - pub fn new>(path: S, contents: &[u8]) -> MockFile { + pub(crate) fn new>(path: S, contents: &[u8]) -> MockFile { MockFile::_new(path.into(), Arc::new(contents.to_vec())) } - pub fn new_arc>(path: S, contents: Arc>) -> MockFile { + pub(crate) fn new_arc>(path: S, contents: Arc>) -> MockFile { MockFile::_new(path.into(), contents) } @@ -106,7 +106,7 @@ impl MockFile { } } - pub fn new_dir(path: &str, files: &[(&'static str, &'static [u8], bool)]) -> MockFile { + pub(crate) fn new_dir(path: &str, files: &[(&'static str, &'static [u8], bool)]) -> MockFile { MockFile { path: path.to_string(), contents: Contents::Dir( @@ -126,14 +126,14 @@ impl MockFile { } } - pub fn executable(mut self, exe: bool) -> Self { + pub(crate) fn executable(mut self, exe: bool) -> Self { if let Contents::File(c) = &mut self.contents { c.executable = exe; } self } - pub fn build(&self, path: &Path) { + pub(crate) fn build(&self, path: &Path) { let path = path.join(&self.path); match self.contents { Contents::Dir(ref files) => { diff --git a/tests/mock/topical_doc_data.rs b/tests/mock/topical_doc_data.rs index 818e5f4c04..1e8bb39494 100644 --- a/tests/mock/topical_doc_data.rs +++ b/tests/mock/topical_doc_data.rs @@ -29,11 +29,11 @@ fn repath(origin: &str) -> String { repathed.into_os_string().into_string().unwrap() } -pub fn test_cases<'a>() -> impl Iterator { +pub(crate) fn test_cases<'a>() -> impl Iterator { TEST_CASES.iter().map(|x| (x[0], repath(x[1]))) } -pub fn unique_paths() -> impl Iterator { +pub(crate) fn unique_paths() -> impl Iterator { // Hashset used to test uniqueness of values through insert method. let mut unique_paths = HashSet::new(); TEST_CASES