Skip to content

Commit

Permalink
Migrate to supercilex-tests
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Saveau <[email protected]>
  • Loading branch information
SUPERCILEX committed Jan 1, 2023
1 parent 114f380 commit 641e54a
Show file tree
Hide file tree
Showing 15 changed files with 89 additions and 207 deletions.
35 changes: 4 additions & 31 deletions .github/workflows/cid.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Install Rust
run: rustup component add rustfmt clippy
- name: Cargo Cache
uses: actions/cache@v3
with:
Expand All @@ -47,37 +49,8 @@ jobs:
- name: Run tests
run: cargo test

lint:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Install Rust
run: rustup component add rustfmt clippy
- name: Cargo Cache
uses: actions/cache@v3
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: ${{ runner.os }}-cargo-lint-${{ hashFiles('**/Cargo.lock') }}
restore-keys: ${{ runner.os }}-cargo-
- name: Run lint
run: |
cargo fmt --check
cargo clippy --all-targets --all-features -- -D warnings \
-W clippy::all \
-W clippy::float_cmp_const \
-W clippy::empty_structs_with_brackets \
-W clippy::pedantic \
-W clippy::nursery \
-W clippy::cargo
deploy_release:
needs: [build, test, lint]
needs: [build, test]
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/')
steps:
Expand Down Expand Up @@ -111,7 +84,7 @@ jobs:
- target: aarch64-pc-windows-msvc
os: windows-latest
tool: cross
needs: [build, test, lint]
needs: [build, test]
runs-on: ${{ matrix.os }}
if: startsWith(github.ref, 'refs/tags/')
steps:
Expand Down
52 changes: 24 additions & 28 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ edition = "2021"
repository = "https://github.com/SUPERCILEX/fuc"
license = "Apache-2.0"

[package]
name = "lint"
version = "0.0.0"
publish = false

[dev-dependencies]
supercilex-tests = "0.1.2"

[profile.release]
lto = true
codegen-units = 1
Expand Down
3 changes: 1 addition & 2 deletions cpz/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,10 @@ thiserror = "1.0.38"
[dev-dependencies]
cache-size = "0.6.0"
criterion = "0.4.0"
expect-test = "1.4.0"
memmap2 = "0.5.8"
nix = "0.26.1"
rand = "0.8.5"
rustix = { version = "0.36.6", features = ["fs"] }
supercilex-tests = "0.1.2"
tempfile = "3.3.0"
trycmd = "0.14.6"

Expand Down
35 changes: 16 additions & 19 deletions cpz/benches/copy_methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use std::{
fs::{copy, File, OpenOptions},
io::{BufRead, BufReader, Read, Write},
path::{Path, PathBuf},
thread,
time::Duration,
};

Expand Down Expand Up @@ -32,7 +31,13 @@ impl NormalTempFile {

let buf = create_random_buffer(usize::try_from(bytes).unwrap(), direct_io);

open_standard(&from, direct_io).write_all(&buf).unwrap();
open_standard(
&from,
#[cfg(target_os = "linux")]
direct_io,
)
.write_all(&buf)
.unwrap();

Self {
to: dir.path().join("to"),
Expand Down Expand Up @@ -207,7 +212,11 @@ fn just_writes(c: &mut Criterion) {
(dir, buf)
},
|(dir, buf)| {
let mut out = open_standard(dir.path().join("file").as_ref(), true);
let mut out = open_standard(
dir.path().join("file").as_ref(),
#[cfg(target_os = "linux")]
true,
);
out.set_len(*num_bytes).unwrap();

out.write_all(&buf).unwrap();
Expand Down Expand Up @@ -334,7 +343,7 @@ fn add_benches(group: &mut BenchmarkGroup<WallTime>, num_bytes: u64, direct_io:
b.iter_batched(
|| NormalTempFile::create(*num_bytes, direct_io),
|files| {
use std::os::unix::fs::FileExt;
use std::{os::unix::fs::FileExt, thread};

let threads =
u64::try_from(thread::available_parallelism().unwrap().get()).unwrap();
Expand Down Expand Up @@ -516,29 +525,17 @@ fn add_benches(group: &mut BenchmarkGroup<WallTime>, num_bytes: u64, direct_io:
);
}

fn open_standard(path: &Path, direct_io: bool) -> File {
fn open_standard(path: &Path, #[cfg(target_os = "linux")] direct_io: bool) -> File {
let mut options = OpenOptions::new();
options.write(true).create(true).truncate(true);

#[cfg(target_os = "linux")]
if direct_io {
use std::os::unix::fs::OpenOptionsExt;
options.custom_flags(nix::libc::O_DIRECT);
}

let file = options.open(path).unwrap();

#[cfg(target_os = "macos")]
if direct_io {
use nix::{
errno::Errno,
libc::{fcntl, F_NOCACHE},
};
Errno::result(unsafe { fcntl(file.as_raw_fd(), F_NOCACHE) }).unwrap();
options.custom_flags(i32::try_from(rustix::io::PipeFlags::DIRECT.bits()).unwrap());
}

#[allow(clippy::let_and_return)]
file
options.open(path).unwrap()
}

fn write_from_buffer(to: PathBuf, mut reader: BufReader<File>) {
Expand Down
45 changes: 2 additions & 43 deletions cpz/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,7 @@ fn main() -> Result<(), CliError> {

#[cfg(test)]
mod cli_tests {
use std::fmt::Write;

use clap::{Command, CommandFactory};
use expect_test::expect_file;
use clap::CommandFactory;

use super::*;

Expand All @@ -78,45 +75,7 @@ mod cli_tests {
}

#[test]
#[cfg_attr(miri, ignore)] // wrap_help breaks miri
fn help_for_review() {
let mut command = Cpz::command();

command.build();

let mut long = String::new();
let mut short = String::new();

write_help(&mut long, &mut command, LongOrShortHelp::Long);
write_help(&mut short, &mut command, LongOrShortHelp::Short);

expect_file!["../command-reference.golden"].assert_eq(&long);
expect_file!["../command-reference-short.golden"].assert_eq(&short);
}

#[derive(Copy, Clone)]
enum LongOrShortHelp {
Long,
Short,
}

fn write_help(buffer: &mut impl Write, cmd: &mut Command, long_or_short_help: LongOrShortHelp) {
write!(
buffer,
"{}",
match long_or_short_help {
LongOrShortHelp::Long => cmd.render_long_help(),
LongOrShortHelp::Short => cmd.render_help(),
}
)
.unwrap();

for sub in cmd.get_subcommands_mut() {
writeln!(buffer).unwrap();
writeln!(buffer, "---").unwrap();
writeln!(buffer).unwrap();

write_help(buffer, sub, long_or_short_help);
}
supercilex_tests::help_for_review(Cpz::command());
}
}
4 changes: 1 addition & 3 deletions fuc_engine/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ rayon = "1.6.1"
remove_dir_all = "0.7.0"

[dev-dependencies]
expect-test = "1.4.0"
ftzz = "1.1.4"
public-api = "0.25.0"
rstest = "0.16.0"
rustdoc-json = "0.7.4"
supercilex-tests = "0.1.2"
tempfile = "3.3.0"
17 changes: 14 additions & 3 deletions fuc_engine/src/ops/copy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,13 @@ mod compat {

impl DirectoryOp<(Cow<'_, Path>, Cow<'_, Path>)> for Impl {
fn run(&self, (from, to): (Cow<Path>, Cow<Path>)) -> Result<(), Error> {
copy_dir(&from, &to, None).map_io_err(|| format!("Failed to copy directory: {from:?}"))
copy_dir(
&from,
to,
#[cfg(unix)]
None,
)
.map_io_err(|| format!("Failed to copy directory: {from:?}"))
}

fn finish(self) -> Result<(), Error> {
Expand All @@ -316,7 +322,7 @@ mod compat {
fn copy_dir<P: AsRef<Path>, Q: AsRef<Path>>(
from: P,
to: Q,
root_to_inode: Option<u64>,
#[cfg(unix)] root_to_inode: Option<u64>,
) -> Result<(), io::Error> {
let to = to.as_ref();
fs::create_dir(to)?;
Expand All @@ -339,7 +345,12 @@ mod compat {

let to = to.join(dir_entry.file_name());
if dir_entry.file_type()?.is_dir() {
copy_dir(dir_entry.path(), to, root_to_inode)?;
copy_dir(
dir_entry.path(),
to,
#[cfg(unix)]
root_to_inode,
)?;
} else {
fs::copy(dir_entry.path(), to)?;
}
Expand Down
Loading

0 comments on commit 641e54a

Please sign in to comment.