Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[*.rs] Sort imports ; [*test*.rs] Use assert_ne! throughout #1121

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/lib/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
#[path = "cache_test.rs"]
mod cache_test;

use std::path::{Path, PathBuf};

use fsio::file::{read_text_file, write_text_file};

use crate::storage;
use crate::types::Cache;
use fsio::file::{read_text_file, write_text_file};
use std::path::{Path, PathBuf};

static CACHE_FILE: &'static str = "cache.toml";

Expand Down
3 changes: 2 additions & 1 deletion src/lib/cache_test.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use super::*;
use std::env;

use super::*;

#[test]
fn load_from_path_exists() {
let cwd = env::current_dir().unwrap();
Expand Down
3 changes: 2 additions & 1 deletion src/lib/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#[path = "cli_test.rs"]
mod cli_test;

use std::time::SystemTime;

use crate::cli_commands;
use crate::cli_parser;
use crate::config;
Expand All @@ -22,7 +24,6 @@ use crate::time_summary;
use crate::toolchain;
use crate::types::{CliArgs, GlobalConfig};
use crate::version;
use std::time::SystemTime;

pub(crate) static VERSION: &str = env!("CARGO_PKG_VERSION");
pub(crate) static AUTHOR: &str = env!("CARGO_PKG_AUTHORS");
Expand Down
10 changes: 6 additions & 4 deletions src/lib/cli_commands/diff_steps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,17 @@
#[path = "diff_steps_test.rs"]
mod diff_steps_test;

use std::fs::File;
use std::io;
use std::io::{BufWriter, Write};
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this considered sorted?
i just put everything in a pile and let the formatter do it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. std libraries
  2. third-party libraries
  3. crate (first-party) libraries

Much more readable. I think I got the idea from isort. You can configure rustfmt to do this, see https://rust-lang.github.io/rustfmt/?version=v1.7.1&search=#StdExternalCrate%5C%3A

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ya i get that but i don't want to configure anything and stay consistent with other projects out there.
when ecosystem defaults change, i'll get those and fix as needed.
the assert_ne! parts are fine so suggest to have a PR just for that.


use regex::Regex;

use crate::command;
use crate::error::CargoMakeError;
use crate::execution_plan::ExecutionPlanBuilder;
use crate::io::{create_file, delete_file};
use crate::types::{CliArgs, Config, CrateInfo, ExecutionPlan};
use regex::Regex;
use std::fs::File;
use std::io;
use std::io::{BufWriter, Write};

fn write_as_string(execution_plan: &ExecutionPlan, file: &File) -> io::Result<()> {
let mut writer = BufWriter::new(file);
Expand Down
3 changes: 2 additions & 1 deletion src/lib/cli_commands/list_steps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@
#[path = "list_steps_test.rs"]
mod list_steps_test;

use std::collections::{BTreeMap, BTreeSet};

use crate::error::CargoMakeError;
use crate::execution_plan;
use crate::io;
use crate::types::{Config, DeprecationInfo};
use std::collections::{BTreeMap, BTreeSet};

pub fn run(
config: &Config,
Expand Down
7 changes: 4 additions & 3 deletions src/lib/cli_commands/list_steps_test.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use super::*;
use std::path::PathBuf;

use crate::types::{ConfigSection, EnvValue, Task};
use expect_test::{expect, Expect};
use indexmap::IndexMap;
use std::path::PathBuf;

use super::*;
use crate::types::{ConfigSection, EnvValue, Task};

fn check(
config: &Config,
Expand Down
5 changes: 3 additions & 2 deletions src/lib/cli_commands/print_steps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@
#[path = "print_steps_test.rs"]
mod print_steps_test;

use crate::error::CargoMakeError;
use std::io;

use regex::Regex;

use crate::error::CargoMakeError;
use crate::execution_plan::ExecutionPlanBuilder;
use crate::types::{Config, CrateInfo, ExecutionPlan};
use regex::Regex;

#[derive(Debug)]
enum PrintFormat {
Expand Down
5 changes: 3 additions & 2 deletions src/lib/cli_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -467,10 +467,11 @@ pub fn parse_args(
args: Option<Vec<&str>>,
spec: CliSpec,
) -> Result<CliArgs, CargoMakeError> {
let cli_parsed = match args {
let cli_parsed_result = match args {
Some(args_vec) => cliparser::parse(&args_vec, &spec),
None => cliparser::parse_process(&spec),
}?;
};
let cli_parsed = cli_parsed_result?;

if cli_parsed.arguments.contains("help") {
// generate help text
Expand Down
31 changes: 16 additions & 15 deletions src/lib/cli_test.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use super::*;
use crate::cli_parser::create_cli;
use cliparser::types::CliSpec;
use std::env;
use std::path::Path;

use super::*;
use crate::cli_parser::create_cli;


#[test]
#[ignore]
#[should_panic]
Expand Down Expand Up @@ -437,7 +438,7 @@ fn run_valid() {
"arg2",
"arg3",
]),
create_cli(&global_config, CliSpec::new(), true),
create_cli(&global_config, cliparser::types::CliSpec::new(), true),
)
.unwrap();

Expand All @@ -456,7 +457,7 @@ fn run_with_global_config() {
&"make".to_string(),
true,
Some(vec!["cargo", "make"]),
create_cli(&global_config, CliSpec::new(), true),
create_cli(&global_config, cliparser::types::CliSpec::new(), true),
)
.unwrap();

Expand All @@ -482,7 +483,7 @@ fn run_log_level_override() {
"error",
"-v",
]),
create_cli(&global_config, CliSpec::new(), true),
create_cli(&global_config, cliparser::types::CliSpec::new(), true),
)
.unwrap();

Expand Down Expand Up @@ -511,7 +512,7 @@ fn run_set_env_values() {
"-t",
"empty",
]),
create_cli(&global_config, CliSpec::new(), true),
create_cli(&global_config, cliparser::types::CliSpec::new(), true),
)
.unwrap();

Expand Down Expand Up @@ -543,7 +544,7 @@ fn run_set_env_via_file() {
"-t",
"empty",
]),
create_cli(&global_config, CliSpec::new(), true),
create_cli(&global_config, cliparser::types::CliSpec::new(), true),
);

envmnt::set("ENV1_TEST", "EMPTY");
Expand Down Expand Up @@ -580,7 +581,7 @@ fn run_set_env_both() {
"-t",
"empty",
]),
create_cli(&global_config, CliSpec::new(), true),
create_cli(&global_config, cliparser::types::CliSpec::new(), true),
);

envmnt::set("ENV1_TEST", "EMPTY");
Expand Down Expand Up @@ -624,7 +625,7 @@ fn run_print_only() {
"--print-steps",
"--experimental",
]),
create_cli(&global_config, CliSpec::new(), true),
create_cli(&global_config, cliparser::types::CliSpec::new(), true),
);

run(&cli_args.unwrap(), &global_config).unwrap();
Expand All @@ -650,7 +651,7 @@ fn run_diff_steps() {
"--no-workspace",
"--diff-steps",
]),
create_cli(&global_config, CliSpec::new(), true),
create_cli(&global_config, cliparser::types::CliSpec::new(), true),
);

run(&cli_args.unwrap(), &global_config).unwrap();
Expand All @@ -671,7 +672,7 @@ fn run_protected_flow_example() {
"--makefile",
"./examples/on_error.toml",
]),
create_cli(&global_config, CliSpec::new(), true),
create_cli(&global_config, cliparser::types::CliSpec::new(), true),
);

run(&cli_args.unwrap(), &global_config).unwrap();
Expand All @@ -691,7 +692,7 @@ fn run_no_task_args() {
"--disable-check-for-updates",
"empty",
]),
create_cli(&global_config, CliSpec::new(), true),
create_cli(&global_config, cliparser::types::CliSpec::new(), true),
);

envmnt::set("CARGO_MAKE_TASK_ARGS", "EMPTY");
Expand All @@ -718,7 +719,7 @@ fn run_set_task_args() {
"arg2",
"arg3",
]),
create_cli(&global_config, CliSpec::new(), true),
create_cli(&global_config, cliparser::types::CliSpec::new(), true),
);

envmnt::set("CARGO_MAKE_TASK_ARGS", "EMPTY");
Expand All @@ -742,7 +743,7 @@ fn run_set_task_var_args() {
Some(vec![
"cargo", "make", "empty", "abc", "-p", "foo/bar/", "def",
]),
create_cli(&global_config, CliSpec::new(), true),
create_cli(&global_config, cliparser::types::CliSpec::new(), true),
)
.unwrap();

Expand Down
12 changes: 7 additions & 5 deletions src/lib/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,19 @@
#[path = "command_test.rs"]
mod command_test;

use crate::error::CargoMakeError;
use crate::logger;
use crate::toolchain;
use crate::types::{CommandSpec, Step, UnstableFeature};
use run_script::{IoOptions, ScriptError, ScriptOptions};
use std::io;
use std::io::{Error, ErrorKind, Read};
use std::process::{Command, ExitStatus, Output, Stdio};
use std::sync::atomic::{AtomicU32, Ordering};
use std::sync::Once;

use run_script::{IoOptions, ScriptError, ScriptOptions};

use crate::error::CargoMakeError;
use crate::logger;
use crate::toolchain;
use crate::types::{CommandSpec, Step, UnstableFeature};

/// Returns the exit code (-1 if no exit code found)
pub(crate) fn get_exit_code(exit_status: Result<ExitStatus, Error>, force: bool) -> i32 {
match exit_status {
Expand Down
12 changes: 7 additions & 5 deletions src/lib/condition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@
#[path = "condition_test.rs"]
mod condition_test;

use std::path::Path;

use fsio::path::from_path::FromPath;
use glob::glob;
use indexmap::IndexMap;
use rust_info::types::{RustChannel, RustInfo};

use crate::environment;
use crate::error::CargoMakeError;
use crate::profile;
Expand All @@ -17,11 +24,6 @@ use crate::types::{
TaskCondition,
};
use crate::version::{is_newer, is_same};
use fsio::path::from_path::FromPath;
use glob::glob;
use indexmap::IndexMap;
use rust_info::types::{RustChannel, RustInfo};
use std::path::Path;

fn validate_env_map(
env: Option<IndexMap<String, String>>,
Expand Down
6 changes: 4 additions & 2 deletions src/lib/condition_test.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
use std::{thread, time::Duration};

use git_info::types::GitInfo;

use super::*;
use crate::test::{get_temp_test_directory, should_test_unstable};
use crate::types::{Config, ConfigSection, CrateInfo, EnvInfo, FilesFilesModifiedCondition, Task};
use git_info::types::GitInfo;
use std::{thread, time::Duration};

fn setup_test_dir(subdir: &str) -> String {
let pathbuf = get_temp_test_directory(subdir);
Expand Down
8 changes: 5 additions & 3 deletions src/lib/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@
#[path = "config_test.rs"]
mod config_test;

use std::path::{Path, PathBuf};

use fsio::file::read_text_file;
use fsio::path::from_path::FromPath;

use crate::error::CargoMakeError;
use crate::storage;
use crate::types::GlobalConfig;
use fsio::file::read_text_file;
use fsio::path::from_path::FromPath;
use std::path::{Path, PathBuf};

pub static CONFIG_FILE: &'static str = "config.toml";

Expand Down
3 changes: 2 additions & 1 deletion src/lib/config_test.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use super::*;
use std::env;

use super::*;

#[test]
fn load_from_path_exists() {
let path: PathBuf = ["examples", "cargo-make"].iter().collect();
Expand Down
5 changes: 3 additions & 2 deletions src/lib/descriptor/cargo_alias.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@
#[path = "cargo_alias_test.rs"]
mod cargo_alias_test;

use std::collections::HashMap;
use std::path::Path;

use crate::error::CargoMakeError;
use crate::io;
use crate::types::{InstallCrate, Task};
use std::collections::HashMap;
use std::path::Path;

#[derive(Serialize, Deserialize, Debug)]
#[serde(untagged)]
Expand Down
10 changes: 6 additions & 4 deletions src/lib/descriptor/makefiles/mod_test.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
use std::cell::RefCell;
use std::rc::Rc;

use git_info::types::GitInfo;
use rust_info::types::RustInfo;

use crate::condition;
use crate::descriptor;
use crate::error::CargoMakeError;
Expand All @@ -6,10 +12,6 @@ use crate::scriptengine;
use crate::scriptengine::EngineType;
use crate::test;
use crate::types::{Config, CrateInfo, EnvInfo, FlowInfo, FlowState, RunTaskInfo, Step, Task};
use git_info::types::GitInfo;
use rust_info::types::RustInfo;
use std::cell::RefCell;
use std::rc::Rc;

fn load_descriptor() -> Result<Config, CargoMakeError> {
descriptor::load_internal_descriptors(true, false, None)
Expand Down
12 changes: 7 additions & 5 deletions src/lib/environment/crateinfo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,18 @@
#[path = "crateinfo_test.rs"]
mod crateinfo_test;

use crate::error::CargoMakeError;
use crate::types::{CrateDependency, CrateInfo, PackageInfo, Workspace};
use std::env;
use std::ffi::OsStr;
use std::path::{Path, PathBuf};

use cargo_metadata::camino::Utf8PathBuf;
use cargo_metadata::{Metadata, MetadataCommand};
use glob::glob;
use indexmap::IndexMap;
use itertools::Itertools;
use std::env;
use std::ffi::OsStr;
use std::path::{Path, PathBuf};

use crate::error::CargoMakeError;
use crate::types::{CrateDependency, CrateInfo, PackageInfo, Workspace};

#[derive(Debug, Deserialize)]
struct CargoConfig {
Expand Down
Loading