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 06208b6
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 25 deletions.
70 changes: 49 additions & 21 deletions .github/workflows/cool_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,43 +62,71 @@ 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
steps:
- name: start audiosrv
run: net start audiosrv
- name: install scream
runs-on: windows-latest

steps:
- name: Download VB-CABLE Driver
shell: pwsh
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
# Download the latest VB-CABLE driver package
Invoke-WebRequest -Uri https://vb-audio.com/Cable/VBCABLE_Driver_Pack45.zip -OutFile VBCABLE_Driver_Pack45.zip
# Extract the driver package
Expand-Archive -Path VBCABLE_Driver_Pack45.zip -DestinationPath VBCABLE
- name: Install VB-CABLE Driver
shell: cmd
run: |
# Run the setup in silent mode
VBCABLE\VBCABLE_Setup_x64.exe /silent
- uses: actions/checkout@v2

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

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

- name: Run tests
run: cargo test --release
49 changes: 45 additions & 4 deletions src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ 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);
}
Expand Down Expand Up @@ -188,12 +190,51 @@ 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;

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

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

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

0 comments on commit 06208b6

Please sign in to comment.