Skip to content

Commit

Permalink
Merge pull request #186 from 1Password/lumina/determinism-tests
Browse files Browse the repository at this point in the history
Add determinism ensurance tests
  • Loading branch information
Cerulan Lumina authored Jul 23, 2024
2 parents ecc8ce7 + f904a91 commit 1316485
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 0 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions tests/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
input
out
16 changes: 16 additions & 0 deletions tests/data/determinism-base.rs
Original file line number Diff line number Diff line change
@@ -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<String>,
pub fixed_length_array: [String; 4],
pub dictionary: HashMap<String, i32>,
pub optional_dictionary: Option<HashMap<String, i32>>,
pub custom_type: CustomType,
}
19 changes: 19 additions & 0 deletions tests/justfile
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 1316485

Please sign in to comment.