Skip to content

Commit

Permalink
Bump test dependencies
Browse files Browse the repository at this point in the history
This required changing the implementation of creating test projects. The `.tmp`
prefix can be used in Windows but the cargo project name cannot. Thus, the
`--name <NAME>` option needed to be used for creating a test package because the
`TempDir` type from the assert_fs package does not support the tempfile TempDir
builder or changing the prefix in newer versions. See Issues [#46] and [#48]
from the `assert_fs` project for more information.

[#46]: assert-rs/assert_fs#46
[#48]: assert-rs/assert_fs#48
  • Loading branch information
volks73 committed Sep 3, 2019
1 parent daef816 commit 5b21853
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 25 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ toml = "0.4"
uuid = { version = "0.7", features = ["v4"] }

[dev-dependencies]
assert_fs = "0.9"
assert_fs = "0.11"
lazy_static = "1"
predicates = "0.9"
predicates = "1.0"
tempfile = "3"
sxd-document = "0.3"
sxd-xpath = "0.4"
Expand Down
75 changes: 70 additions & 5 deletions tests/common/mod.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
extern crate assert_fs;
extern crate sxd_document;
extern crate sxd_xpath;
extern crate tempfile;
// extern crate tempfile;

use std::fs::File;
use std::io::Read;
use assert_fs::prelude::*;

use assert_fs::TempDir;
use std::fs;
use std::fs::{File, OpenOptions};
use std::io::{Read, Write};
use std::path::Path;
use std::process::Command;
use self::sxd_document::parser;
Expand All @@ -12,6 +17,9 @@ use self::sxd_xpath::{Context, Factory};
#[allow(dead_code)]
pub const TARGET_NAME: &str = "target";

#[allow(dead_code)]
pub const PACKAGE_NAME: &str = "cargowixtest";

/// Create a new cargo project/package for a binary project in a temporary
/// directory.
///
Expand All @@ -34,25 +42,82 @@ pub const TARGET_NAME: &str = "target";
/// This will panic if a temporary directory fails to be created or if cargo
/// fails to create the project/package.
#[allow(dead_code)]
pub fn create_test_package() -> tempfile::TempDir {
// pub fn create_test_package() -> tempfile::TempDir {
pub fn create_test_package() -> TempDir {
// Use a prefix because the default `.tmp` is an invalid name for a Cargo package.
//
// Cannot use dashes. WiX Toolset only allows A-Z, a-z, digits, underscores (_), or periods (.)
// for attribute IDs.
let temp_dir = tempfile::Builder::new().prefix("cargo_wix_test_").tempdir().unwrap();
// let temp_dir = tempfile::Builder::new().prefix("cargo_wix_test_").tempdir().unwrap();
let temp_dir = TempDir::new().unwrap();
let cargo_init_status = Command::new("cargo")
.arg("init")
.arg("--bin")
.arg("--quiet")
.arg("--vcs")
.arg("none")
.arg("--name")
.arg(PACKAGE_NAME)
.arg(temp_dir.path())
.status()
.expect("Creation of test Cargo package");
assert!(cargo_init_status.success());
temp_dir
}

/// Create a new cargo project/package for a project with multiple binaries in a
/// temporary directory. See the [create_test_package] function for more
/// information.
///
/// Following creation of the project, the manifest file (Cargo.toml) is
/// modified to include multiple `[[bin]]` sections for multiple binaries. The
/// original `main.rs` file that is created for the first binary is copied for
/// each of the other binaries. A total of three (3) binaries will be created
/// and added to the manifest file.
///
/// [create_test_package]: fn.create_test_package.html
///
/// # Panics
///
/// This will panic if a temporary directory fails to be created or if cargo
/// fails to create the project/package.
///
/// It will also panic if it cannot modify the manifest file (Cargo.toml) or the
/// project layout for multiple binaries.
#[allow(dead_code)]
pub fn create_test_package_multiple_binaries() -> assert_fs::TempDir {
let package = create_test_package();
let package_manifest = package.child("Cargo.toml");
let package_src = package.child("src");
{
let mut cargo_toml_handle = OpenOptions::new()
.read(true)
.append(true)
.open(package_manifest.path())
.unwrap();
cargo_toml_handle.write_all(
r#"[[bin]]
name = "main1"
path = "src/main1.rs"
[[bin]]
name = "main2"
path = "src/main2.rs"
[[bin]]
name = "main3"
path = "src/main3.rs"
"#.as_bytes()
).unwrap();
}
let package_original_main = package_src.child("main.rs");
fs::copy(package_original_main.path(), package_src.child("main1.rs").path()).unwrap();
fs::copy(package_original_main.path(), package_src.child("main2.rs").path()).unwrap();
fs::copy(package_original_main.path(), package_src.child("main3.rs").path()).unwrap();
fs::remove_file(package_original_main.path()).unwrap();
package
}

/// Evaluates an XPath expression for a WiX Source file.
///
/// This registers the WiX XML namespace with the `wix` prefix. So, XPath
Expand Down
34 changes: 17 additions & 17 deletions tests/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ mod common;
use assert_fs::prelude::*;
use predicates::prelude::*;

use common::TARGET_NAME;
use common::{PACKAGE_NAME, TARGET_NAME};
use std::env;
use std::fs::{self, File};
use std::io::{Read, Write};
Expand All @@ -47,7 +47,7 @@ fn default_works() {
let original_working_directory = env::current_dir().unwrap();
let package = common::create_test_package();
let expected_msi_file = TARGET_WIX_DIR.join(format!(
"{}-0.1.0-x86_64.msi", package.path().file_name().and_then(|o| o.to_str()).unwrap()
"{}-0.1.0-x86_64.msi", PACKAGE_NAME
));
env::set_current_dir(package.path()).unwrap();
initialize::Execution::default().run().unwrap();
Expand All @@ -63,7 +63,7 @@ fn init_with_package_section_fields_works() {
let original_working_directory = env::current_dir().unwrap();
let package = common::create_test_package();
let expected_msi_file = TARGET_WIX_DIR.join(format!(
"{}-0.1.0-x86_64.msi", package.path().file_name().and_then(|o| o.to_str()).unwrap()
"{}-0.1.0-x86_64.msi", PACKAGE_NAME
));
env::set_current_dir(package.path()).unwrap();
let package_manifest = package.child("Cargo.toml");
Expand Down Expand Up @@ -106,7 +106,7 @@ fn init_with_all_options_works() {
let original_working_directory = env::current_dir().unwrap();
let package = common::create_test_package();
let expected_msi_file = TARGET_WIX_DIR.join(format!(
"{}-0.1.0-x86_64.msi", package.path().file_name().and_then(|o| o.to_str()).unwrap()
"{}-0.1.0-x86_64.msi", PACKAGE_NAME
));
env::set_current_dir(package.path()).unwrap();
let bin_example_path = package.path().join("bin").join("Example.exe");
Expand Down Expand Up @@ -161,7 +161,7 @@ fn init_with_banner_option_works() {
let original_working_directory = env::current_dir().unwrap();
let package = common::create_test_package();
let expected_msi_file = TARGET_WIX_DIR.join(format!(
"{}-0.1.0-x86_64.msi", package.path().file_name().and_then(|o| o.to_str()).unwrap()
"{}-0.1.0-x86_64.msi", PACKAGE_NAME
));
env::set_current_dir(package.path()).unwrap();
let banner_path = package.path().join("img").join("Banner.bmp");
Expand All @@ -186,7 +186,7 @@ fn init_with_binary_option_works() {
let original_working_directory = env::current_dir().unwrap();
let package = common::create_test_package();
let expected_msi_file = TARGET_WIX_DIR.join(format!(
"{}-0.1.0-x86_64.msi", package.path().file_name().and_then(|o| o.to_str()).unwrap()
"{}-0.1.0-x86_64.msi", PACKAGE_NAME
));
env::set_current_dir(package.path()).unwrap();
let bin_example_path = package.path().join("bin").join("Example.exe");
Expand All @@ -211,7 +211,7 @@ fn init_with_description_option_works() {
let original_working_directory = env::current_dir().unwrap();
let package = common::create_test_package();
let expected_msi_file = TARGET_WIX_DIR.join(format!(
"{}-0.1.0-x86_64.msi", package.path().file_name().and_then(|o| o.to_str()).unwrap()
"{}-0.1.0-x86_64.msi", PACKAGE_NAME
));
env::set_current_dir(package.path()).unwrap();
initialize::Builder::new()
Expand All @@ -231,7 +231,7 @@ fn init_with_dialog_option_works() {
let original_working_directory = env::current_dir().unwrap();
let package = common::create_test_package();
let expected_msi_file = TARGET_WIX_DIR.join(format!(
"{}-0.1.0-x86_64.msi", package.path().file_name().and_then(|o| o.to_str()).unwrap()
"{}-0.1.0-x86_64.msi", PACKAGE_NAME
));
env::set_current_dir(package.path()).unwrap();
let dialog_path = package.path().join("img").join("Dialog.bmp");
Expand All @@ -257,7 +257,7 @@ fn init_with_eula_in_cwd_works() {
let original_working_directory = env::current_dir().unwrap();
let package = common::create_test_package();
let expected_msi_file = TARGET_WIX_DIR.join(format!(
"{}-0.1.0-x86_64.msi", package.path().file_name().and_then(|o| o.to_str()).unwrap()
"{}-0.1.0-x86_64.msi", PACKAGE_NAME
));
env::set_current_dir(package.path()).unwrap();
let package_eula = package.child(EULA_FILE);
Expand All @@ -282,7 +282,7 @@ fn init_with_eula_in_docs_works() {
let original_working_directory = env::current_dir().unwrap();
let package = common::create_test_package();
let expected_msi_file = TARGET_WIX_DIR.join(format!(
"{}-0.1.0-x86_64.msi", package.path().file_name().and_then(|o| o.to_str()).unwrap()
"{}-0.1.0-x86_64.msi", PACKAGE_NAME
));
env::set_current_dir(package.path()).unwrap();
let package_docs = package.child("docs");
Expand All @@ -308,7 +308,7 @@ fn init_with_help_url_option_works() {
let original_working_directory = env::current_dir().unwrap();
let package = common::create_test_package();
let expected_msi_file = TARGET_WIX_DIR.join(format!(
"{}-0.1.0-x86_64.msi", package.path().file_name().and_then(|o| o.to_str()).unwrap()
"{}-0.1.0-x86_64.msi", PACKAGE_NAME
));
env::set_current_dir(package.path()).unwrap();
initialize::Builder::new()
Expand All @@ -329,7 +329,7 @@ fn init_with_license_in_cwd_works() {
let original_working_directory = env::current_dir().unwrap();
let package = common::create_test_package();
let expected_msi_file = TARGET_WIX_DIR.join(format!(
"{}-0.1.0-x86_64.msi", package.path().file_name().and_then(|o| o.to_str()).unwrap()
"{}-0.1.0-x86_64.msi", PACKAGE_NAME
));
env::set_current_dir(package.path()).unwrap();
let package_license = package.child(LICENSE_FILE);
Expand All @@ -354,7 +354,7 @@ fn init_with_license_in_docs_works() {
let original_working_directory = env::current_dir().unwrap();
let package = common::create_test_package();
let expected_msi_file = TARGET_WIX_DIR.join(format!(
"{}-0.1.0-x86_64.msi", package.path().file_name().and_then(|o| o.to_str()).unwrap()
"{}-0.1.0-x86_64.msi", PACKAGE_NAME
));
env::set_current_dir(package.path()).unwrap();
let package_docs = package.child("docs");
Expand All @@ -380,7 +380,7 @@ fn init_with_manufacturer_option_works() {
let original_working_directory = env::current_dir().unwrap();
let package = common::create_test_package();
let expected_msi_file = TARGET_WIX_DIR.join(format!(
"{}-0.1.0-x86_64.msi", package.path().file_name().and_then(|o| o.to_str()).unwrap()
"{}-0.1.0-x86_64.msi", PACKAGE_NAME
));
env::set_current_dir(package.path()).unwrap();
initialize::Builder::new()
Expand All @@ -400,7 +400,7 @@ fn init_with_product_icon_option_works() {
let original_working_directory = env::current_dir().unwrap();
let package = common::create_test_package();
let expected_msi_file = TARGET_WIX_DIR.join(format!(
"{}-0.1.0-x86_64.msi", package.path().file_name().and_then(|o| o.to_str()).unwrap()
"{}-0.1.0-x86_64.msi", PACKAGE_NAME
));
env::set_current_dir(package.path()).unwrap();
let product_icon_path = package.path().join("img").join("Product.ico");
Expand All @@ -425,7 +425,7 @@ fn init_with_product_name_option_works() {
let original_working_directory = env::current_dir().unwrap();
let package = common::create_test_package();
let expected_msi_file = TARGET_WIX_DIR.join(format!(
"{}-0.1.0-x86_64.msi", package.path().file_name().and_then(|o| o.to_str()).unwrap()
"{}-0.1.0-x86_64.msi", PACKAGE_NAME
));
env::set_current_dir(package.path()).unwrap();
initialize::Builder::new()
Expand Down Expand Up @@ -453,7 +453,7 @@ fn input_works() {
fs::create_dir(output.parent().unwrap()).unwrap();
fs::create_dir(&output).unwrap();
let expected_msi_file = TARGET_WIX_DIR.join(format!(
"{}-0.1.0-x86_64.msi", package.path().file_name().and_then(|o| o.to_str()).unwrap()
"{}-0.1.0-x86_64.msi", PACKAGE_NAME
));
let mut toml: Value = {
let mut cargo_toml_handle = File::open(package_manifest.path()).unwrap();
Expand Down
4 changes: 3 additions & 1 deletion tests/initialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ mod common;
use assert_fs::prelude::*;
use predicates::prelude::*;

use assert_fs::fixture::ChildPath;
use std::env;
use std::fs::{self, File};
use std::io::{Read, Write};
Expand Down Expand Up @@ -166,7 +167,8 @@ fn input_works() {
fn output_works() {
let original_working_directory = env::current_dir().unwrap();
let package = common::create_test_package();
let output = tempfile::Builder::new().prefix("cargo_wix_test_output_").tempdir().unwrap();
let temp_dir = tempfile::Builder::new().prefix("cargo_wix_test_output_").tempdir().unwrap();
let output = ChildPath::new(temp_dir.path());
env::set_current_dir(package.path()).unwrap();
let result = Builder::default()
.output(output.path().to_str())
Expand Down

0 comments on commit 5b21853

Please sign in to comment.