From f904a91318f6b859b1ef60a6bcef6c3a6c2888b1 Mon Sep 17 00:00:00 2001 From: Cerulan Lumina Date: Mon, 22 Jul 2024 16:24:02 -0400 Subject: [PATCH] Add determinism ensurance tests --- .github/workflows/ci.yml | 21 +++++++++++++++++++++ tests/.gitignore | 2 ++ tests/data/determinism-base.rs | 16 ++++++++++++++++ tests/justfile | 19 +++++++++++++++++++ 4 files changed, 58 insertions(+) create mode 100644 tests/.gitignore create mode 100644 tests/data/determinism-base.rs create mode 100644 tests/justfile diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d33dae9e..3e9bceb8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -40,6 +40,27 @@ jobs: toolchain: ${{ matrix.rust }} - run: rustup run ${{ matrix.rust }} cargo test --all-features + + check-deterministic: + name: Ensure Deterministic Output + runs-on: ubuntu-latest + strategy: + matrix: + rust: + - stable + steps: + - uses: actions/checkout@v2 + - uses: extractions/setup-just@v1 + with: + just-version: 1 + - uses: kenji-miyake/setup-sd@v2 + - uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: ${{ matrix.rust }} + - run: rustup toolchain install ${{ matrix.rust }} + - run: just --justfile tests/justfile determinism + fmt: name: Rustfmt diff --git a/tests/.gitignore b/tests/.gitignore new file mode 100644 index 00000000..53087960 --- /dev/null +++ b/tests/.gitignore @@ -0,0 +1,2 @@ +input +out diff --git a/tests/data/determinism-base.rs b/tests/data/determinism-base.rs new file mode 100644 index 00000000..f4706493 --- /dev/null +++ b/tests/data/determinism-base.rs @@ -0,0 +1,16 @@ +#[typeshare] +pub struct CustomType {} + +#[typeshare] +pub struct Types { + pub s: String, + pub static_s: &'static str, + pub int8: i8, + pub float: f32, + pub double: f64, + pub array: Vec, + pub fixed_length_array: [String; 4], + pub dictionary: HashMap, + pub optional_dictionary: Option>, + pub custom_type: CustomType, +} diff --git a/tests/justfile b/tests/justfile new file mode 100644 index 00000000..65335df9 --- /dev/null +++ b/tests/justfile @@ -0,0 +1,19 @@ +determinism_qty := '100' + +all: determinism + +generate-determinism-files: + #!/bin/sh + mkdir -p input + for i in $(seq 1 {{determinism_qty}}); do + cat data/determinism-base.rs | sd '(struct )(\w+)' "\${1}\${2}$i" > "input/input$i.rs" + done +determinism: clean generate-determinism-files + mkdir -p out + cargo run -p typeshare-cli -- -l typescript -o "out/output1.ts" input + cargo run -p typeshare-cli -- -l typescript -o "out/output2.ts" input + diff -q out/*.ts + +clean: + rm -rf out + rm -rf input