Skip to content

Commit

Permalink
Run tests on all platforms (#76)
Browse files Browse the repository at this point in the history
* Run tests on all platforms

* CI: Actually use ARM macs for running the ARM macs tests

* Use `{:?}` to print different strings on tests

* Strip `\r` character on integration_test.rs

* Add changelog entries

* CI: Merge `run_tests` and `release` jobs to try to improve CI times
  • Loading branch information
AngheloAlf authored Aug 14, 2024
1 parent dd613bb commit d11da86
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 33 deletions.
31 changes: 8 additions & 23 deletions .github/workflows/publish_crate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,23 +40,6 @@ jobs:
- name: Run clippy
run: cargo clippy --all-targets -- -D warnings

run_tests:
name: Run tests
runs-on: ubuntu-latest

steps:
- name: Checkout reposistory
uses: actions/checkout@v4

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

- name: Run tests
run: cargo test --workspace

msrv:
runs-on: ubuntu-latest
steps:
Expand All @@ -70,10 +53,9 @@ jobs:
run: cargo hack check --rust-version --workspace --all-targets --ignore-private


release:
name: release artifact for ${{ matrix.builder.target }}
test_and_release:
name: Run tests and release artifact for ${{ matrix.builder.target }}
runs-on: ${{ matrix.builder.runner }}
needs: [run_tests, msrv]

strategy:
fail-fast: false
Expand All @@ -97,7 +79,7 @@ jobs:
{
name: mac,
target: aarch64-apple-darwin,
runner: macos-12
runner: macos-14 # ARM
},
{
name: linux,
Expand All @@ -120,8 +102,11 @@ jobs:
with:
targets: ${{ matrix.builder.target }}

- name: Run tests
run: cargo test --workspace --target ${{ matrix.builder.target }}

- name: Build cli
run: cargo build --release --target ${{ matrix.builder.target }}
run: cargo build --release --bins --target ${{ matrix.builder.target }}

- name: Move files for packaging (unix)
if: matrix.builder.name == 'linux' || matrix.builder.name == 'mac'
Expand Down Expand Up @@ -160,7 +145,7 @@ jobs:
publish:
name: Publish
runs-on: ubuntu-latest
needs: [run_tests, msrv]
needs: [test_and_release, msrv]

steps:
- name: Checkout reposistory
Expand Down
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Produce an error if the user specifies an empty conditional
inclusion/exclusion for any entry.
- Tests now strip the `\r` character from the expected files before compaing
them.
- This is done to normalize the tests files accross all platforms, including
the ones where git may add `\r` characters when cloning the repository
(like Windows).
- Github Actions:
- Change CI to run tests on all platforms we generate builds artifacts for.
- Use the ARM Mac Github runner to build and test the ARM Mac builds.
- Merge `run_tests` and `release` jobs to try to improve CI times.

## [0.2.5] - 2024-07-17

Expand Down
32 changes: 22 additions & 10 deletions slinky/tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,37 +7,49 @@ use std::path::{Path, PathBuf};
use rstest::rstest;
use slinky::{RuntimeSettings, ScriptExporter, ScriptImporter, SlinkyError};

fn compare_multiline_strings(left: &str, right: &str) {
if left == right {
fn compare_multiline_strings(expected: &str, generated: &str) {
// We manually strip the CARRIAGE RETURN (`\r`/`U+000D`) character only from
// expected because it may get included into the test files when cloning this
// repository on Windows with a git configured with its default settings.
//
// Rust never writes a `\r` character using the `writeln!` macro, so it is
// not like this character would get added automatically on Windows builds
// of slinky, so the simplest solution is to just strip this character from
// `expected`.
//
// What can go wrong?
let expected_cleaned = expected.replace('\r', "");

if expected_cleaned == generated {
return;
}

// both strings are not the same, try to figure out where the issue is.
println!("Not equal strings :c");
println!();

let mut left_splitted = left.split("\n");
let mut right_splitted = right.split("\n");
let mut expected_splitted = expected_cleaned.split("\n");
let mut generated_splitted = generated.split("\n");

// https://stackoverflow.com/a/38168890/6292472
loop {
match (left_splitted.next(), right_splitted.next()) {
match (expected_splitted.next(), generated_splitted.next()) {
(Some(l), Some(r)) => {
if l != r {
println!(" Different lines:");
println!(" left: {}", l);
println!(" right: {}", r);
println!(" expected: {:?}", l);
println!(" generated: {:?}", r);
println!();
}
}
(Some(l), None) => {
println!(" Only one line:");
println!(" left: {}", l);
println!(" expected: {:?}", l);
println!();
}
(None, Some(r)) => {
println!(" Only one line:");
println!(" right: {}", r);
println!(" generated: {:?}", r);
println!();
}
(None, None) => break,
Expand All @@ -48,7 +60,7 @@ fn compare_multiline_strings(left: &str, right: &str) {
println!("full inequality:");
println!();

assert_eq!(left, right);
assert_eq!(expected_cleaned, generated);
}

fn create_runtime_settings() -> RuntimeSettings {
Expand Down

0 comments on commit d11da86

Please sign in to comment.