Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
xasopheno committed Dec 29, 2024
1 parent 78446ec commit 44f862e
Show file tree
Hide file tree
Showing 2 changed files with 104 additions and 33 deletions.
65 changes: 37 additions & 28 deletions .github/workflows/cool_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,43 +62,52 @@ jobs:
run: just test

macos:
runs-on: macos-latest
runs-on: macos-latest

steps:
- name: Install dependencies
run: |
brew update
brew install lame libvorbis just
- name: Debug environment
run: |
which lame
- name: Set library path
run: |
export LIBRARY_PATH=/opt/homebrew/lib:$LIBRARY_PATH
export LD_LIBRARY_PATH=/opt/homebrew/lib:$LD_LIBRARY_PATH
steps:
- name: install dependancies
run: brew install lame libvorbis just
- uses: actions/checkout@v2

- uses: actions-rs/toolchain@v1
with:
toolchain: stable
override: true
toolchain: stable
override: true

- uses: Swatinem/rust-cache@v2
with:
cache-on-failure: true
key: "weresocool-windows"
- name: run tests
key: "weresocool-macos"

- name: Run tests
env:
LIBRARY_PATH: /opt/homebrew/lib:$LIBRARY_PATH
LD_LIBRARY_PATH: /opt/homebrew/lib:$LD_LIBRARY_PATH
run: just test

windows:
runs-on: windows-latest
windows:
runs-on: windows-latest
steps:
- name: start audiosrv
run: net start audiosrv
- name: install scream
run: |
Invoke-WebRequest https://github.com/duncanthrax/scream/releases/download/3.8/Scream3.8.zip -OutFile Scream3.8.zip
Expand-Archive -Path Scream3.8.zip -DestinationPath Scream
Import-Certificate -FilePath Scream\Install\driver\x64\Scream.cat -CertStoreLocation Cert:\LocalMachine\TrustedPublisher
Scream\Install\helpers\devcon-x64.exe install Scream\Install\driver\x64\Scream.inf *Scream
- uses: actions-rs/toolchain@v1
with:
- name: Install VB-CABLE
uses: alekseymartynov/action-vbcable-win@main
- name: Checkout code
uses: actions/checkout@v2
- name: Set up Rust toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: stable
override: true

- uses: actions/checkout@v2
- uses: Swatinem/rust-cache@v2
with:
cache-on-failure: true
key: "weresocool-windows"
- name: run tests
run: cargo test --release
- name: Run tests
run: cargo test --release
72 changes: 67 additions & 5 deletions src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,10 @@ mod cli_tests {
#[cfg(target_os = "linux")]
let expected_filename = "src/test_data/play_unix.mp3";

dbg!(&expected_filename);

let written_filename = format!("{}/play.mp3", tmp_dir.path().display());
assert_same_bytes(expected_filename, &written_filename);
assert_same_length(expected_filename, &written_filename);
}

#[test]
Expand Down Expand Up @@ -188,12 +190,72 @@ mod cli_tests {
}

fn assert_same_bytes(expected_filename: &str, written_filename: &str) {
let tolerance = 5;

let written_read =
std::fs::read(written_filename).expect("Something went wrong reading file");
let expected_read =
std::fs::read(expected_filename).expect("Something went wrong reading file");
std::fs::read(written_filename).expect("Something went wrong reading the written file");
let expected_read = std::fs::read(expected_filename)
.expect("Something went wrong reading the expected file");

// Compare file sizes first
if written_read.len() != expected_read.len() {
eprintln!(
"File size mismatch: expected {} bytes, got {} bytes",
expected_read.len(),
written_read.len()
);
}

let mut differences = 0;
for (i, (w, e)) in written_read.iter().zip(expected_read.iter()).enumerate() {
if (w.abs_diff(*e)) > tolerance {
differences += 1;
if differences <= 10 {
eprintln!(
"Mismatch at byte {}: expected 0x{:02x}, got 0x{:02x} (diff: {})",
i,
e,
w,
w.abs_diff(*e)
);
}
}
}

let total_bytes = written_read.len().min(expected_read.len());
let similarity = 100.0 * (total_bytes - differences) as f64 / total_bytes as f64;

eprintln!(
"Comparison complete: {} bytes compared, {} differences (similarity: {:.2}%)",
total_bytes, differences, similarity
);

assert!(written_read == expected_read);
assert!(
similarity > 95.0,
"Files are not similar enough (similarity: {:.2}%)",
similarity
);
}

pub fn assert_same_length(expected_filename: &str, written_filename: &str) {
let written_read =
std::fs::read(written_filename).expect("Something went wrong reading the written file");
let expected_read = std::fs::read(expected_filename)
.expect("Something went wrong reading the expected file");

// Compare file sizes first
if written_read.len() != expected_read.len() {
eprintln!(
"File size mismatch: expected {} bytes, got {} bytes",
expected_read.len(),
written_read.len()
);
}

assert!(
written_read.len() == expected_read.len(),
"Files are not the same length"
);
}

fn assert_same_file_contents(expected_filename: &str, written_filename: &str) {
Expand Down

0 comments on commit 44f862e

Please sign in to comment.