Run cargo fmt on the whole code base (#9394)

* Run cargo fmt on the whole code base

* Second run

* Add CI check

* Fix compilation

* More unnecessary braces

* Handle weights

* Use --all

* Use correct attributes...

* Fix UI tests

* AHHHHHHHHH

* 🤦

* Docs

* Fix compilation

* 🤷

* Please stop

* 🤦 x 2

* More

* make rustfmt.toml consistent with polkadot

Co-authored-by: André Silva <andrerfosilva@gmail.com>
This commit is contained in:
Bastian Köcher
2021-07-21 16:32:32 +02:00
committed by GitHub
parent d451c38c1c
commit 7b56ab15b4
1010 changed files with 53339 additions and 51208 deletions
+12 -10
View File
@@ -18,11 +18,18 @@
#![cfg(unix)]
use std::{process::{Child, ExitStatus}, thread, time::Duration, path::Path};
use assert_cmd::cargo::cargo_bin;
use std::{convert::TryInto, process::Command};
use nix::sys::signal::{kill, Signal::SIGINT};
use nix::unistd::Pid;
use nix::{
sys::signal::{kill, Signal::SIGINT},
unistd::Pid,
};
use std::{
convert::TryInto,
path::Path,
process::{Child, Command, ExitStatus},
thread,
time::Duration,
};
/// Wait for the given `child` the given number of `secs`.
///
@@ -50,12 +57,7 @@ pub fn wait_for(child: &mut Child, secs: usize) -> Option<ExitStatus> {
pub fn run_dev_node_for_a_while(base_path: &Path) {
let mut cmd = Command::new(cargo_bin("substrate"));
let mut cmd = cmd
.args(&["--dev"])
.arg("-d")
.arg(base_path)
.spawn()
.unwrap();
let mut cmd = cmd.args(&["--dev"]).arg("-d").arg(base_path).spawn().unwrap();
// Let it produce some blocks.
thread::sleep(Duration::from_secs(30));
@@ -19,9 +19,9 @@
#![cfg(unix)]
use assert_cmd::cargo::cargo_bin;
use std::{process::Command, fs, path::PathBuf};
use tempfile::{tempdir, TempDir};
use regex::Regex;
use std::{fs, path::PathBuf, process::Command};
use tempfile::{tempdir, TempDir};
pub mod common;
@@ -63,26 +63,23 @@ impl<'a> ExportImportRevertExecutor<'a> {
fn new(
base_path: &'a TempDir,
exported_blocks_file: &'a PathBuf,
db_path: &'a PathBuf
db_path: &'a PathBuf,
) -> Self {
Self {
base_path,
exported_blocks_file,
db_path,
num_exported_blocks: None,
}
Self { base_path, exported_blocks_file, db_path, num_exported_blocks: None }
}
/// Helper method to run a command. Returns a string corresponding to what has been logged.
fn run_block_command(&self,
fn run_block_command(
&self,
sub_command: SubCommand,
format_opt: FormatOpt,
expected_to_fail: bool
expected_to_fail: bool,
) -> String {
let sub_command_str = sub_command.to_string();
// Adding "--binary" if need be.
let arguments: Vec<&str> = match format_opt {
FormatOpt::Binary => vec![&sub_command_str, "--dev", "--pruning", "archive", "--binary", "-d"],
FormatOpt::Binary =>
vec![&sub_command_str, "--dev", "--pruning", "archive", "--binary", "-d"],
FormatOpt::Json => vec![&sub_command_str, "--dev", "--pruning", "archive", "-d"],
};
@@ -94,7 +91,7 @@ impl<'a> ExportImportRevertExecutor<'a> {
SubCommand::ImportBlocks => {
tmp = tempdir().unwrap();
tmp.path()
}
},
};
// Running the command and capturing the output.
@@ -144,16 +141,13 @@ impl<'a> ExportImportRevertExecutor<'a> {
if !expected_to_fail {
// Using regex to find out how much block we imported,
// and what's the best current block.
let re = Regex::new(r"Imported (?P<imported>\d*) blocks. Best: #(?P<best>\d*)").unwrap();
let re =
Regex::new(r"Imported (?P<imported>\d*) blocks. Best: #(?P<best>\d*)").unwrap();
let caps = re.captures(&log).expect("capture should have succeeded");
let imported = caps["imported"].parse::<u64>().unwrap();
let best = caps["best"].parse::<u64>().unwrap();
assert_eq!(
imported,
best,
"numbers of blocks imported and best number differs"
);
assert_eq!(imported, best, "numbers of blocks imported and best number differs");
assert_eq!(
best,
self.num_exported_blocks.expect("number of exported blocks cannot be None; qed"),
@@ -195,11 +189,7 @@ fn export_import_revert() {
common::run_dev_node_for_a_while(base_path.path());
let mut executor = ExportImportRevertExecutor::new(
&base_path,
&exported_blocks_file,
&db_path,
);
let mut executor = ExportImportRevertExecutor::new(&base_path, &exported_blocks_file, &db_path);
// Binary and binary should work.
executor.run(FormatOpt::Binary, FormatOpt::Binary, false);
@@ -25,8 +25,13 @@ pub mod common;
#[test]
#[cfg(unix)]
fn running_the_node_works_and_can_be_interrupted() {
use nix::sys::signal::{kill, Signal::{self, SIGINT, SIGTERM}};
use nix::unistd::Pid;
use nix::{
sys::signal::{
kill,
Signal::{self, SIGINT, SIGTERM},
},
unistd::Pid,
};
fn run_command_and_kill(signal: Signal) {
let base_path = tempdir().expect("could not create a temp dir");
+13 -22
View File
@@ -17,10 +17,11 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>.
use assert_cmd::cargo::cargo_bin;
use nix::sys::signal::{kill, Signal::SIGINT};
use nix::unistd::Pid;
use std::convert::TryInto;
use std::process;
use nix::{
sys::signal::{kill, Signal::SIGINT},
unistd::Pid,
};
use std::{convert::TryInto, process};
pub mod common;
pub mod websocket_server;
@@ -45,27 +46,22 @@ async fn telemetry_works() {
Event::ConnectionOpen { address } => {
println!("New connection from {:?}", address);
server.accept();
}
},
// Received a message from a connection.
Event::BinaryFrame { message, .. } => {
let json: serde_json::Value = serde_json::from_slice(&message).unwrap();
let object = json
.as_object()
.unwrap()
.get("payload")
.unwrap()
.as_object()
.unwrap();
let object =
json.as_object().unwrap().get("payload").unwrap().as_object().unwrap();
if matches!(object.get("best"), Some(serde_json::Value::String(_))) {
break;
break
}
}
},
Event::TextFrame { .. } => panic!("Got a TextFrame over the socket, this is a bug"),
// Connection has been closed.
Event::ConnectionError { .. } => {}
Event::ConnectionError { .. } => {},
}
}
});
@@ -83,16 +79,11 @@ async fn telemetry_works() {
server_task.await;
assert!(
substrate.try_wait().unwrap().is_none(),
"the process should still be running"
);
assert!(substrate.try_wait().unwrap().is_none(), "the process should still be running");
// Stop the process
kill(Pid::from_raw(substrate.id().try_into().unwrap()), SIGINT).unwrap();
assert!(common::wait_for(&mut substrate, 40)
.map(|x| x.success())
.unwrap_or_default());
assert!(common::wait_for(&mut substrate, 40).map(|x| x.success()).unwrap_or_default());
let output = substrate.wait_with_output().unwrap();
@@ -19,15 +19,19 @@
#![cfg(unix)]
use assert_cmd::cargo::cargo_bin;
use nix::sys::signal::{kill, Signal::SIGINT};
use nix::unistd::Pid;
use nix::{
sys::signal::{kill, Signal::SIGINT},
unistd::Pid,
};
use regex::Regex;
use std::convert::TryInto;
use std::io::Read;
use std::path::PathBuf;
use std::process::{Command, Stdio};
use std::thread;
use std::time::Duration;
use std::{
convert::TryInto,
io::Read,
path::PathBuf,
process::{Command, Stdio},
thread,
time::Duration,
};
pub mod common;
@@ -44,29 +48,18 @@ fn temp_base_path_works() {
// Let it produce some blocks.
thread::sleep(Duration::from_secs(30));
assert!(
cmd.try_wait().unwrap().is_none(),
"the process should still be running"
);
assert!(cmd.try_wait().unwrap().is_none(), "the process should still be running");
// Stop the process
kill(Pid::from_raw(cmd.id().try_into().unwrap()), SIGINT).unwrap();
assert!(common::wait_for(&mut cmd, 40)
.map(|x| x.success())
.unwrap_or_default());
assert!(common::wait_for(&mut cmd, 40).map(|x| x.success()).unwrap_or_default());
// Ensure the database has been deleted
let mut stderr = String::new();
cmd.stderr.unwrap().read_to_string(&mut stderr).unwrap();
let re = Regex::new(r"Database: .+ at (\S+)").unwrap();
let db_path = PathBuf::from(
re.captures(stderr.as_str())
.unwrap()
.get(1)
.unwrap()
.as_str()
.to_string(),
);
let db_path =
PathBuf::from(re.captures(stderr.as_str()).unwrap().get(1).unwrap().as_str().to_string());
assert!(!db_path.exists());
}
+9 -25
View File
@@ -22,61 +22,45 @@ use regex::Regex;
use std::process::Command;
fn expected_regex() -> Regex {
Regex::new(r"^substrate (\d+\.\d+\.\d+(?:-.+?)?)-([a-f\d]+|unknown)-(.+?)-(.+?)(?:-(.+))?$").unwrap()
Regex::new(r"^substrate (\d+\.\d+\.\d+(?:-.+?)?)-([a-f\d]+|unknown)-(.+?)-(.+?)(?:-(.+))?$")
.unwrap()
}
#[test]
fn version_is_full() {
let expected = expected_regex();
let output = Command::new(cargo_bin("substrate"))
.args(&["--version"])
.output()
.unwrap();
let output = Command::new(cargo_bin("substrate")).args(&["--version"]).output().unwrap();
assert!(
output.status.success(),
"command returned with non-success exit code"
);
assert!(output.status.success(), "command returned with non-success exit code");
let output = String::from_utf8_lossy(&output.stdout).trim().to_owned();
let captures = expected
.captures(output.as_str())
.expect("could not parse version in output");
let captures = expected.captures(output.as_str()).expect("could not parse version in output");
assert_eq!(&captures[1], env!("CARGO_PKG_VERSION"));
assert_eq!(&captures[3], TARGET_ARCH.as_str());
assert_eq!(&captures[4], TARGET_OS.as_str());
assert_eq!(
captures.get(5).map(|x| x.as_str()),
TARGET_ENV.map(|x| x.as_str())
);
assert_eq!(captures.get(5).map(|x| x.as_str()), TARGET_ENV.map(|x| x.as_str()));
}
#[test]
fn test_regex_matches_properly() {
let expected = expected_regex();
let captures = expected
.captures("substrate 2.0.0-da487d19d-x86_64-linux-gnu")
.unwrap();
let captures = expected.captures("substrate 2.0.0-da487d19d-x86_64-linux-gnu").unwrap();
assert_eq!(&captures[1], "2.0.0");
assert_eq!(&captures[2], "da487d19d");
assert_eq!(&captures[3], "x86_64");
assert_eq!(&captures[4], "linux");
assert_eq!(captures.get(5).map(|x| x.as_str()), Some("gnu"));
let captures = expected
.captures("substrate 2.0.0-alpha.5-da487d19d-x86_64-linux-gnu")
.unwrap();
let captures = expected.captures("substrate 2.0.0-alpha.5-da487d19d-x86_64-linux-gnu").unwrap();
assert_eq!(&captures[1], "2.0.0-alpha.5");
assert_eq!(&captures[2], "da487d19d");
assert_eq!(&captures[3], "x86_64");
assert_eq!(&captures[4], "linux");
assert_eq!(captures.get(5).map(|x| x.as_str()), Some("gnu"));
let captures = expected
.captures("substrate 2.0.0-alpha.5-da487d19d-x86_64-linux")
.unwrap();
let captures = expected.captures("substrate 2.0.0-alpha.5-da487d19d-x86_64-linux").unwrap();
assert_eq!(&captures[1], "2.0.0-alpha.5");
assert_eq!(&captures[2], "da487d19d");
assert_eq!(&captures[3], "x86_64");
@@ -116,7 +116,6 @@ impl WsServer {
/// # Panic
///
/// Panics if no connection is pending.
///
pub fn accept(&mut self) {
let pending_incoming = self.pending_incoming.take().expect("no pending socket");
@@ -129,15 +128,10 @@ impl WsServer {
};
match server
.send_response(&{
Response::Accept {
key: &websocket_key,
protocol: None,
}
})
.send_response(&{ Response::Accept { key: &websocket_key, protocol: None } })
.await
{
Ok(()) => {}
Ok(()) => {},
Err(err) => return Err(Box::new(err) as Box<_>),
};
@@ -153,7 +147,6 @@ impl WsServer {
/// # Panic
///
/// Panics if no connection is pending.
///
pub fn reject(&mut self) {
let _ = self.pending_incoming.take().expect("no pending socket");
}