From c2c93e4ecd891c5d930f4b52a6ef2c60843012fc Mon Sep 17 00:00:00 2001 From: Dzmitry Malyshau Date: Wed, 14 Apr 2021 14:20:48 -0400 Subject: [PATCH] Remove cargo-insta --- .github/workflows/pipeline.yml | 2 + Cargo.toml | 3 +- Makefile | 42 ++-- README.md | 6 +- tests/errors.rs | 114 ++++----- tests/out/{boids.msl.snap => boids.msl} | 5 - tests/out/{boids.spvasm.snap => boids.spvasm} | 6 +- ...collatz.info.ron.snap => collatz.info.ron} | 6 +- tests/out/{collatz.msl.snap => collatz.msl} | 5 - tests/out/{collatz.ron.snap => collatz.ron} | 6 +- .../{collatz.spvasm.snap => collatz.spvasm} | 6 +- ...y-Compute.glsl.snap => empty.Compute.glsl} | 5 - tests/out/empty.hlsl | 5 + tests/out/empty.hlsl.snap | 11 - tests/out/{empty.msl.snap => empty.msl} | 5 - tests/out/{empty.spvasm.snap => empty.spvasm} | 6 +- .../{image-copy.msl.snap => image-copy.msl} | 5 - tests/out/quad-glsl.ron.snap | 224 ------------------ tests/out/quad-glsl.spvasm.snap | 63 ----- .../out/{quad-vert.msl.snap => quad-vert.msl} | 5 - ...-Fragment.glsl.snap => quad.Fragment.glsl} | 5 - ...quad-Vertex.glsl.snap => quad.Vertex.glsl} | 5 - tests/out/{quad.dot.snap => quad.dot} | 5 - tests/out/{quad.msl.snap => quad.msl} | 5 - tests/out/{quad.spvasm.snap => quad.spvasm} | 6 +- ...ragment.glsl.snap => shadow.Fragment.glsl} | 5 - .../{shadow.info.ron.snap => shadow.info.ron} | 6 +- tests/out/{shadow.msl.snap => shadow.msl} | 5 - tests/out/{shadow.ron.snap => shadow.ron} | 6 +- .../out/{shadow.spvasm.snap => shadow.spvasm} | 6 +- ...ragment.glsl.snap => skybox.Fragment.glsl} | 5 - ...ox-Vertex.glsl.snap => skybox.Vertex.glsl} | 5 - tests/out/{skybox.msl.snap => skybox.msl} | 5 - .../out/{skybox.spvasm.snap => skybox.spvasm} | 6 +- ...xture-array.msl.snap => texture-array.msl} | 5 - ...array.spvasm.snap => texture-array.spvasm} | 6 +- tests/snapshots.rs | 87 ++++--- 37 files changed, 139 insertions(+), 564 deletions(-) rename tests/out/{boids.msl.snap => boids.msl} (98%) rename tests/out/{boids.spvasm.snap => boids.spvasm} (99%) rename tests/out/{collatz.info.ron.snap => collatz.info.ron} (99%) rename tests/out/{collatz.msl.snap => collatz.msl} (93%) rename tests/out/{collatz.ron.snap => collatz.ron} (99%) rename tests/out/{collatz.spvasm.snap => collatz.spvasm} (97%) rename tests/out/{empty-Compute.glsl.snap => empty.Compute.glsl} (71%) create mode 100644 tests/out/empty.hlsl delete mode 100644 tests/out/empty.hlsl.snap rename tests/out/{empty.msl.snap => empty.msl} (62%) rename tests/out/{empty.spvasm.snap => empty.spvasm} (83%) rename tests/out/{image-copy.msl.snap => image-copy.msl} (91%) delete mode 100644 tests/out/quad-glsl.ron.snap delete mode 100644 tests/out/quad-glsl.spvasm.snap rename tests/out/{quad-vert.msl.snap => quad-vert.msl} (96%) rename tests/out/{quad-Fragment.glsl.snap => quad.Fragment.glsl} (89%) rename tests/out/{quad-Vertex.glsl.snap => quad.Vertex.glsl} (89%) rename tests/out/{quad.dot.snap => quad.dot} (98%) rename tests/out/{quad.msl.snap => quad.msl} (95%) rename tests/out/{quad.spvasm.snap => quad.spvasm} (97%) rename tests/out/{shadow-Fragment.glsl.snap => shadow.Fragment.glsl} (96%) rename tests/out/{shadow.info.ron.snap => shadow.info.ron} (99%) rename tests/out/{shadow.msl.snap => shadow.msl} (97%) rename tests/out/{shadow.ron.snap => shadow.ron} (99%) rename tests/out/{shadow.spvasm.snap => shadow.spvasm} (98%) rename tests/out/{skybox-Fragment.glsl.snap => skybox.Fragment.glsl} (88%) rename tests/out/{skybox-Vertex.glsl.snap => skybox.Vertex.glsl} (95%) rename tests/out/{skybox.msl.snap => skybox.msl} (97%) rename tests/out/{skybox.spvasm.snap => skybox.spvasm} (98%) rename tests/out/{texture-array.msl.snap => texture-array.msl} (94%) rename tests/out/{texture-array.spvasm.snap => texture-array.spvasm} (96%) diff --git a/.github/workflows/pipeline.yml b/.github/workflows/pipeline.yml index 5ee486280..3d9ca0f6a 100644 --- a/.github/workflows/pipeline.yml +++ b/.github/workflows/pipeline.yml @@ -24,6 +24,8 @@ jobs: with: command: test args: --all-features + - name: Check snapshots + run: git diff --exit-code -- tests/out clippy: name: Clippy runs-on: ubuntu-latest diff --git a/Cargo.toml b/Cargo.toml index c96aa733f..ca412e4e9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -46,9 +46,8 @@ name = "convert" path = "bin/convert.rs" [dev-dependencies] -difference = "2.0" +diff = "0.1" ron = "0.6" serde = { version = "1.0", features = ["derive"] } spirv = { package = "spirv_headers", version = "1.5", features = ["deserialize"] } -insta = { version = "1.6", features = ["glob"] } rspirv = "0.7" diff --git a/Makefile b/Makefile index 94e512e84..2eeec5eb0 100644 --- a/Makefile +++ b/Makefile @@ -26,38 +26,34 @@ clean: %.png: %.dot dot -Tpng $< -o $@ -# A command to remove the '---' YAML document start markers from the snapshots -# before passing their contents to a validator. -TRIM=sed -e '1d' -e '2,/---/d' - -validate-spv: $(SNAPSHOTS_OUT)/*.spvasm.snap +validate-spv: $(SNAPSHOTS_OUT)/*.spvasm @set -e && for file in $^ ; do \ - echo "Validating" $${file#"$(SNAPSHOTS_OUT)/snapshots__"}; \ - $(TRIM) $${file} | spirv-as --target-env vulkan1.0 -o - | spirv-val; \ + echo "Validating" $${file#"$(SNAPSHOTS_OUT)"}; \ + cat $${file} | spirv-as --target-env vulkan1.0 -o - | spirv-val; \ done -validate-msl: $(SNAPSHOTS_OUT)/*.msl.snap +validate-msl: $(SNAPSHOTS_OUT)/*.msl @set -e && for file in $^ ; do \ - echo "Validating" $${file#"$(SNAPSHOTS_OUT)/snapshots__"}; \ - $(TRIM) $${file} | xcrun -sdk macosx metal -mmacosx-version-min=10.11 -x metal - -o /dev/null; \ + echo "Validating" $${file#"$(SNAPSHOTS_OUT)"}; \ + cat $${file} | xcrun -sdk macosx metal -mmacosx-version-min=10.11 -x metal - -o /dev/null; \ done -validate-glsl: $(SNAPSHOTS_OUT)/*.glsl.snap - @set -e && for file in $(SNAPSHOTS_OUT)/*-Vertex.glsl.snap ; do \ - echo "Validating" $${file#"$(SNAPSHOTS_OUT)/snapshots__"};\ - $(TRIM) $${file} | glslangValidator --stdin -S vert; \ +validate-glsl: $(SNAPSHOTS_OUT)/*.glsl + @set -e && for file in $(SNAPSHOTS_OUT)/*.Vertex.glsl ; do \ + echo "Validating" $${file#"$(SNAPSHOTS_OUT)"};\ + cat $${file} | glslangValidator --stdin -S vert; \ done - @set -e && for file in $(SNAPSHOTS_OUT)/*-Fragment.glsl.snap ; do \ - echo "Validating" $${file#"$(SNAPSHOTS_OUT)/snapshots__"};\ - $(TRIM) $${file} | glslangValidator --stdin -S frag; \ + @set -e && for file in $(SNAPSHOTS_OUT)/*.Fragment.glsl ; do \ + echo "Validating" $${file#"$(SNAPSHOTS_OUT)"};\ + cat $${file} | glslangValidator --stdin -S frag; \ done - @set -e && for file in $(SNAPSHOTS_OUT)/*-Compute.glsl.snap ; do \ - echo "Validating" $${file#"$(SNAPSHOTS_OUT)/snapshots__"};\ - $(TRIM) $${file} | glslangValidator --stdin -S comp; \ + @set -e && for file in $(SNAPSHOTS_OUT)/*.Compute.glsl ; do \ + echo "Validating" $${file#"$(SNAPSHOTS_OUT)"};\ + cat $${file} | glslangValidator --stdin -S comp; \ done -validate-dot: $(SNAPSHOTS_OUT)/*.dot.snap +validate-dot: $(SNAPSHOTS_OUT)/*.dot @set -e && for file in $^ ; do \ - echo "Validating" $${file#"$(SNAPSHOTS_OUT)/snapshots__"}; \ - $(TRIM) $${file} | dot -o /dev/null; \ + echo "Validating" $${file#"$(SNAPSHOTS_OUT)"}; \ + cat $${file} | dot -o /dev/null; \ done diff --git a/README.md b/README.md index 9a83e18d8..5873d8eff 100644 --- a/README.md +++ b/README.md @@ -44,9 +44,8 @@ cargo run --features wgsl-in,glsl-out -- my_shader.wgsl my_shader.vert --profile ## Development workflow The main instrument aiding the development is the good old `cargo test --all-features`, -which will run the snapshot tests as well as the unit tests. -Any changes in the snapshots would then have to be reviewed with `cargo insta review` -before being accepted into the code. +which will run the unit tests, and also update all the snapshots. You'll see these +changes in git before committing the code. If working on a particular front-end or back-end, it may be convenient to enable the relevant features in `Cargo.toml`, e.g. @@ -61,4 +60,5 @@ are indeed valid for the target platforms they are compiled for. We automate thi make validate-spv # for Vulkan shaders, requires SPIRV-Tools installed make validate-msl # for Metal shaders, requires XCode command-line tools installed make validate-glsl # for OpenGL shaders, requires GLSLang installed +make validate-dot # for dot files, requires GraphViz installed ``` diff --git a/tests/errors.rs b/tests/errors.rs index 437288ab5..7567b203b 100644 --- a/tests/errors.rs +++ b/tests/errors.rs @@ -1,99 +1,99 @@ #[cfg(feature = "wgsl-in")] -macro_rules! err { - ($value:expr, @$snapshot:literal) => { - ::insta::assert_snapshot!( - naga::front::wgsl::parse_str($value) - .expect_err("expected parser error") - .emit_to_string(), - @$snapshot - ); - }; +fn check(input: &str, snapshot: &str) { + let output = naga::front::wgsl::parse_str(input) + .expect_err("expected parser error") + .emit_to_string(); + if output != snapshot { + for diff in diff::lines(&output, snapshot) { + match diff { + diff::Result::Left(l) => println!("-{}", l), + diff::Result::Both(l, _) => println!(" {}", l), + diff::Result::Right(r) => println!("+{}", r), + } + } + panic!("Error snapshot failed"); + } } #[cfg(feature = "wgsl-in")] #[test] fn function_without_identifier() { - err!( + check( "fn () {}", - @r###" - error: expected identifier, found '(' - ┌─ wgsl:1:4 - │ - 1 │ fn () {} - │ ^ expected identifier +r###"error: expected identifier, found '(' + ┌─ wgsl:1:4 + │ +1 │ fn () {} + │ ^ expected identifier - "### +"###, ); } #[cfg(feature = "wgsl-in")] #[test] fn invalid_integer() { - err!( + check( "fn foo([location(1.)] x: i32) {}", - @r###" - error: expected identifier, found '[' - ┌─ wgsl:1:8 - │ - 1 │ fn foo([location(1.)] x: i32) {} - │ ^ expected identifier +r###"error: expected identifier, found '[' + ┌─ wgsl:1:8 + │ +1 │ fn foo([location(1.)] x: i32) {} + │ ^ expected identifier - "### +"###, ); } #[cfg(feature = "wgsl-in")] #[test] fn invalid_float() { - err!( + check( "let scale: f32 = 1.1.;", - @r###" - error: expected floating-point literal, found `1.1.` - ┌─ wgsl:1:18 - │ - 1 │ let scale: f32 = 1.1.; - │ ^^^^ expected floating-point literal +r###"error: expected floating-point literal, found `1.1.` + ┌─ wgsl:1:18 + │ +1 │ let scale: f32 = 1.1.; + │ ^^^^ expected floating-point literal - "### +"###, ); } #[cfg(feature = "wgsl-in")] #[test] fn invalid_scalar_width() { - err!( + check( "let scale: f32 = 1.1f1000;", - @r###" - error: invalid width of `1000` for literal - ┌─ wgsl:1:18 - │ - 1 │ let scale: f32 = 1.1f1000; - │ ^^^^^^^^ invalid width - │ - = note: valid width is 32 +r###"error: invalid width of `1000` for literal + ┌─ wgsl:1:18 + │ +1 │ let scale: f32 = 1.1f1000; + │ ^^^^^^^^ invalid width + │ + = note: valid width is 32 - "### +"###, ); } #[cfg(feature = "wgsl-in")] #[test] fn invalid_accessor() { - err!( + check( r###" - [[stage(vertex)]] - fn vs_main() { - var color: vec3 = vec3(1.0, 2.0, 3.0); - var i: f32 = color.a; - } - "###, - @r###" - error: invalid field accessor `a` - ┌─ wgsl:5:32 - │ - 5 │ var i: f32 = color.a; - │ ^ invalid accessor +[[stage(vertex)]] +fn vs_main() { + var color: vec3 = vec3(1.0, 2.0, 3.0); + var i: f32 = color.a; +} +"###, +r###"error: invalid field accessor `a` + ┌─ wgsl:5:24 + │ +5 │ var i: f32 = color.a; + │ ^ invalid accessor - "### +"###, ); } diff --git a/tests/out/boids.msl.snap b/tests/out/boids.msl similarity index 98% rename from tests/out/boids.msl.snap rename to tests/out/boids.msl index d59f82aea..24e7d2ca0 100644 --- a/tests/out/boids.msl.snap +++ b/tests/out/boids.msl @@ -1,7 +1,3 @@ ---- -source: tests/snapshots.rs -expression: msl ---- #include #include @@ -101,4 +97,3 @@ kernel void main1( particlesDst.particles[global_invocation_id.x].vel = vVel; return; } - diff --git a/tests/out/boids.spvasm.snap b/tests/out/boids.spvasm similarity index 99% rename from tests/out/boids.spvasm.snap rename to tests/out/boids.spvasm index ded452eae..7df829a38 100644 --- a/tests/out/boids.spvasm.snap +++ b/tests/out/boids.spvasm @@ -1,7 +1,3 @@ ---- -source: tests/snapshots.rs -expression: dis ---- ; SPIR-V ; Version: 1.0 ; Generator: rspirv @@ -332,4 +328,4 @@ OpStore %200 %199 %202 = OpAccessChain %53 %25 %7 %46 %10 OpStore %202 %201 OpReturn -OpFunctionEnd +OpFunctionEnd \ No newline at end of file diff --git a/tests/out/collatz.info.ron.snap b/tests/out/collatz.info.ron similarity index 99% rename from tests/out/collatz.info.ron.snap rename to tests/out/collatz.info.ron index 4f5c1ef92..6bea48630 100644 --- a/tests/out/collatz.info.ron.snap +++ b/tests/out/collatz.info.ron @@ -1,7 +1,3 @@ ---- -source: tests/snapshots.rs -expression: output ---- ( functions: [ ( @@ -498,4 +494,4 @@ expression: output ], ), ], -) +) \ No newline at end of file diff --git a/tests/out/collatz.msl.snap b/tests/out/collatz.msl similarity index 93% rename from tests/out/collatz.msl.snap rename to tests/out/collatz.msl index efded439e..403789659 100644 --- a/tests/out/collatz.msl.snap +++ b/tests/out/collatz.msl @@ -1,7 +1,3 @@ ---- -source: tests/snapshots.rs -expression: msl ---- #include #include @@ -40,4 +36,3 @@ kernel void main1( v_indices.data[global_id.x] = _e9; return; } - diff --git a/tests/out/collatz.ron.snap b/tests/out/collatz.ron similarity index 99% rename from tests/out/collatz.ron.snap rename to tests/out/collatz.ron index b86183c22..65f98a6e8 100644 --- a/tests/out/collatz.ron.snap +++ b/tests/out/collatz.ron @@ -1,7 +1,3 @@ ---- -source: tests/snapshots.rs -expression: output ---- ( types: [ ( @@ -347,4 +343,4 @@ expression: output ), ), ], -) +) \ No newline at end of file diff --git a/tests/out/collatz.spvasm.snap b/tests/out/collatz.spvasm similarity index 97% rename from tests/out/collatz.spvasm.snap rename to tests/out/collatz.spvasm index 9d56582b9..cc4698fa4 100644 --- a/tests/out/collatz.spvasm.snap +++ b/tests/out/collatz.spvasm @@ -1,7 +1,3 @@ ---- -source: tests/snapshots.rs -expression: dis ---- ; SPIR-V ; Version: 1.0 ; Generator: rspirv @@ -109,4 +105,4 @@ OpBranch %50 %60 = OpAccessChain %53 %11 %56 %52 OpStore %60 %59 OpReturn -OpFunctionEnd +OpFunctionEnd \ No newline at end of file diff --git a/tests/out/empty-Compute.glsl.snap b/tests/out/empty.Compute.glsl similarity index 71% rename from tests/out/empty-Compute.glsl.snap rename to tests/out/empty.Compute.glsl index 4fbc229db..63328eab1 100644 --- a/tests/out/empty-Compute.glsl.snap +++ b/tests/out/empty.Compute.glsl @@ -1,7 +1,3 @@ ---- -source: tests/snapshots.rs -expression: string ---- #version 310 es precision highp float; @@ -13,4 +9,3 @@ void main() { return; } - diff --git a/tests/out/empty.hlsl b/tests/out/empty.hlsl new file mode 100644 index 000000000..d1d3c9cb2 --- /dev/null +++ b/tests/out/empty.hlsl @@ -0,0 +1,5 @@ + +void main() +{ + return; +} diff --git a/tests/out/empty.hlsl.snap b/tests/out/empty.hlsl.snap deleted file mode 100644 index 2cfc16ce6..000000000 --- a/tests/out/empty.hlsl.snap +++ /dev/null @@ -1,11 +0,0 @@ ---- -source: tests/snapshots.rs -expression: hlsl - ---- - -void main() -{ - return; -} - diff --git a/tests/out/empty.msl.snap b/tests/out/empty.msl similarity index 62% rename from tests/out/empty.msl.snap rename to tests/out/empty.msl index 9d081189a..9b4ad4862 100644 --- a/tests/out/empty.msl.snap +++ b/tests/out/empty.msl @@ -1,7 +1,3 @@ ---- -source: tests/snapshots.rs -expression: msl ---- #include #include @@ -10,4 +6,3 @@ kernel void main1( ) { return; } - diff --git a/tests/out/empty.spvasm.snap b/tests/out/empty.spvasm similarity index 83% rename from tests/out/empty.spvasm.snap rename to tests/out/empty.spvasm index bd9279de9..47d3c1756 100644 --- a/tests/out/empty.spvasm.snap +++ b/tests/out/empty.spvasm @@ -1,7 +1,3 @@ ---- -source: tests/snapshots.rs -expression: dis ---- ; SPIR-V ; Version: 1.1 ; Generator: rspirv @@ -18,4 +14,4 @@ OpExecutionMode %4 LocalSize 1 1 1 OpBranch %6 %6 = OpLabel OpReturn -OpFunctionEnd +OpFunctionEnd \ No newline at end of file diff --git a/tests/out/image-copy.msl.snap b/tests/out/image-copy.msl similarity index 91% rename from tests/out/image-copy.msl.snap rename to tests/out/image-copy.msl index 893768a9b..73407ceef 100644 --- a/tests/out/image-copy.msl.snap +++ b/tests/out/image-copy.msl @@ -1,7 +1,3 @@ ---- -source: tests/snapshots.rs -expression: msl ---- #include #include @@ -18,4 +14,3 @@ kernel void main1( image_dst.write(_e13, metal::uint(_e12.x)); return; } - diff --git a/tests/out/quad-glsl.ron.snap b/tests/out/quad-glsl.ron.snap deleted file mode 100644 index 2b8256eee..000000000 --- a/tests/out/quad-glsl.ron.snap +++ /dev/null @@ -1,224 +0,0 @@ ---- -source: tests/snapshots.rs -expression: output ---- -( - types: [ - ( - name: None, - inner: Scalar( - kind: Float, - width: 4, - ), - ), - ( - name: None, - inner: Vector( - size: Bi, - kind: Float, - width: 4, - ), - ), - ( - name: None, - inner: Vector( - size: Quad, - kind: Float, - width: 4, - ), - ), - ], - constants: [ - ( - name: None, - specialization: None, - inner: Scalar( - width: 4, - value: Float(1.2000000476837158), - ), - ), - ( - name: Some("c_scale"), - specialization: None, - inner: Scalar( - width: 4, - value: Float(1.2000000476837158), - ), - ), - ( - name: None, - specialization: None, - inner: Scalar( - width: 4, - value: Float(0), - ), - ), - ( - name: None, - specialization: None, - inner: Scalar( - width: 4, - value: Float(1), - ), - ), - ], - global_variables: [ - ( - name: Some("a_pos"), - class: Input, - binding: Some(Location(0)), - ty: 2, - init: None, - interpolation: None, - storage_access: ( - bits: 0, - ), - ), - ( - name: Some("a_uv"), - class: Input, - binding: Some(Location(1)), - ty: 2, - init: None, - interpolation: None, - storage_access: ( - bits: 0, - ), - ), - ( - name: Some("v_uv"), - class: Output, - binding: Some(Location(0)), - ty: 2, - init: None, - interpolation: None, - storage_access: ( - bits: 0, - ), - ), - ( - name: Some("gl_Position"), - class: Output, - binding: Some(BuiltIn(Position)), - ty: 3, - init: None, - interpolation: None, - storage_access: ( - bits: 0, - ), - ), - ( - name: Some("v_uv"), - class: Input, - binding: Some(Location(0)), - ty: 2, - init: None, - interpolation: None, - storage_access: ( - bits: 0, - ), - ), - ( - name: Some("o_color"), - class: Output, - binding: Some(Location(0)), - ty: 3, - init: None, - interpolation: None, - storage_access: ( - bits: 0, - ), - ), - ], - functions: [], - entry_points: { - (Fragment, "frag_main"): ( - early_depth_test: None, - workgroup_size: (0, 0, 0), - function: ( - name: Some("frag_main"), - arguments: [], - return_type: None, - local_variables: [], - expressions: [ - GlobalVariable(1), - GlobalVariable(2), - GlobalVariable(3), - GlobalVariable(4), - GlobalVariable(5), - GlobalVariable(6), - Constant(2), - Constant(4), - Constant(4), - Constant(4), - Constant(4), - Compose( - ty: 3, - components: [ - 8, - 9, - 10, - 11, - ], - ), - ], - body: [ - Store( - pointer: 6, - value: 12, - ), - Return( - value: None, - ), - ], - ), - ), - (Vertex, "vert_main"): ( - early_depth_test: None, - workgroup_size: (0, 0, 0), - function: ( - name: Some("vert_main"), - arguments: [], - return_type: None, - local_variables: [], - expressions: [ - Constant(1), - Constant(2), - GlobalVariable(1), - GlobalVariable(2), - GlobalVariable(3), - Constant(2), - GlobalVariable(4), - Binary( - op: Multiply, - left: 6, - right: 3, - ), - Constant(3), - Constant(4), - Compose( - ty: 3, - components: [ - 8, - 9, - 10, - ], - ), - ], - body: [ - Store( - pointer: 5, - value: 4, - ), - Store( - pointer: 7, - value: 11, - ), - Return( - value: None, - ), - ], - ), - ), - }, -) diff --git a/tests/out/quad-glsl.spvasm.snap b/tests/out/quad-glsl.spvasm.snap deleted file mode 100644 index 1c68ac044..000000000 --- a/tests/out/quad-glsl.spvasm.snap +++ /dev/null @@ -1,63 +0,0 @@ ---- -source: tests/snapshots.rs -expression: dis ---- -; SPIR-V -; Version: 1.0 -; Generator: rspirv -; Bound: 28 -OpCapability Shader -%1 = OpExtInstImport "GLSL.std.450" -OpMemoryModel Logical GLSL450 -OpEntryPoint Fragment %8 "frag_main" %12 -OpEntryPoint Vertex %15 "vert_main" %25 %20 %18 %23 -OpExecutionMode %8 OriginUpperLeft -OpSource GLSL 450 -OpName %5 "c_scale" -OpName %8 "frag_main" -OpName %12 "o_color" -OpName %8 "frag_main" -OpName %15 "vert_main" -OpName %18 "v_uv" -OpName %20 "a_uv" -OpName %23 "gl_Position" -OpName %25 "a_pos" -OpName %15 "vert_main" -OpDecorate %12 Location 0 -OpDecorate %18 Location 0 -OpDecorate %20 Location 1 -OpDecorate %23 BuiltIn Position -OpDecorate %25 Location 0 -%2 = OpTypeVoid -%4 = OpTypeFloat 32 -%3 = OpConstant %4 1.2 -%5 = OpConstant %4 1.2 -%6 = OpConstant %4 0.0 -%7 = OpConstant %4 1.0 -%9 = OpTypeFunction %2 -%11 = OpTypeVector %4 4 -%13 = OpTypePointer Output %11 -%12 = OpVariable %13 Output -%17 = OpTypeVector %4 2 -%19 = OpTypePointer Output %17 -%18 = OpVariable %19 Output -%21 = OpTypePointer Input %17 -%20 = OpVariable %21 Input -%23 = OpVariable %13 Output -%25 = OpVariable %21 Input -%8 = OpFunction %2 None %9 -%10 = OpLabel -%14 = OpCompositeConstruct %11 %7 %7 %7 %7 -OpStore %12 %14 -OpReturn -OpFunctionEnd -%15 = OpFunction %2 None %9 -%16 = OpLabel -%22 = OpLoad %17 %20 -OpStore %18 %22 -%26 = OpLoad %17 %25 -%24 = OpVectorTimesScalar %17 %26 %5 -%27 = OpCompositeConstruct %11 %24 %6 %7 -OpStore %23 %27 -OpReturn -OpFunctionEnd diff --git a/tests/out/quad-vert.msl.snap b/tests/out/quad-vert.msl similarity index 96% rename from tests/out/quad-vert.msl.snap rename to tests/out/quad-vert.msl index bc5e83c4a..f616b1526 100644 --- a/tests/out/quad-vert.msl.snap +++ b/tests/out/quad-vert.msl @@ -1,7 +1,3 @@ ---- -source: tests/snapshots.rs -expression: msl ---- #include #include @@ -56,4 +52,3 @@ vertex main2Output main2( const auto _tmp = type10 {v_uv, _.gl_Position, _.gl_PointSize, {_.gl_ClipDistance[0]}}; return main2Output { _tmp.member, _tmp.gl_Position1, _tmp.gl_PointSize1, {_tmp.gl_ClipDistance1[0]} }; } - diff --git a/tests/out/quad-Fragment.glsl.snap b/tests/out/quad.Fragment.glsl similarity index 89% rename from tests/out/quad-Fragment.glsl.snap rename to tests/out/quad.Fragment.glsl index 7d873bc76..7122843b3 100644 --- a/tests/out/quad-Fragment.glsl.snap +++ b/tests/out/quad.Fragment.glsl @@ -1,7 +1,3 @@ ---- -source: tests/snapshots.rs -expression: string ---- #version 310 es precision highp float; @@ -26,4 +22,3 @@ void main() { return; } - diff --git a/tests/out/quad-Vertex.glsl.snap b/tests/out/quad.Vertex.glsl similarity index 89% rename from tests/out/quad-Vertex.glsl.snap rename to tests/out/quad.Vertex.glsl index 99ff87ef1..b35cf16eb 100644 --- a/tests/out/quad-Vertex.glsl.snap +++ b/tests/out/quad.Vertex.glsl @@ -1,7 +1,3 @@ ---- -source: tests/snapshots.rs -expression: string ---- #version 310 es precision highp float; @@ -26,4 +22,3 @@ void main() { return; } - diff --git a/tests/out/quad.dot.snap b/tests/out/quad.dot similarity index 98% rename from tests/out/quad.dot.snap rename to tests/out/quad.dot index b839e856d..6e8c54164 100644 --- a/tests/out/quad.dot.snap +++ b/tests/out/quad.dot @@ -1,7 +1,3 @@ ---- -source: tests/snapshots.rs -expression: string ---- digraph Module { subgraph cluster_globals { label="Globals" @@ -108,4 +104,3 @@ digraph Module { ep1_s8 -> ep1_e9 [ style=dotted ] } } - diff --git a/tests/out/quad.msl.snap b/tests/out/quad.msl similarity index 95% rename from tests/out/quad.msl.snap rename to tests/out/quad.msl index fb4f8421a..17f225b0d 100644 --- a/tests/out/quad.msl.snap +++ b/tests/out/quad.msl @@ -1,7 +1,3 @@ ---- -source: tests/snapshots.rs -expression: msl ---- #include #include @@ -50,4 +46,3 @@ fragment main2Output main2( } return main2Output { _e4.w * _e4 }; } - diff --git a/tests/out/quad.spvasm.snap b/tests/out/quad.spvasm similarity index 97% rename from tests/out/quad.spvasm.snap rename to tests/out/quad.spvasm index 800c4f612..676aee116 100644 --- a/tests/out/quad.spvasm.snap +++ b/tests/out/quad.spvasm @@ -1,7 +1,3 @@ ---- -source: tests/snapshots.rs -expression: dis ---- ; SPIR-V ; Version: 1.0 ; Generator: rspirv @@ -118,4 +114,4 @@ OpKill %64 = OpVectorTimesScalar %8 %57 %63 OpStore %50 %64 OpReturn -OpFunctionEnd +OpFunctionEnd \ No newline at end of file diff --git a/tests/out/shadow-Fragment.glsl.snap b/tests/out/shadow.Fragment.glsl similarity index 96% rename from tests/out/shadow-Fragment.glsl.snap rename to tests/out/shadow.Fragment.glsl index 14501be8d..6178ae100 100644 --- a/tests/out/shadow-Fragment.glsl.snap +++ b/tests/out/shadow.Fragment.glsl @@ -1,7 +1,3 @@ ---- -source: tests/snapshots.rs -expression: string ---- #version 310 es precision highp float; @@ -53,4 +49,3 @@ void main() { return; } - diff --git a/tests/out/shadow.info.ron.snap b/tests/out/shadow.info.ron similarity index 99% rename from tests/out/shadow.info.ron.snap rename to tests/out/shadow.info.ron index 3260f6134..661a8655b 100644 --- a/tests/out/shadow.info.ron.snap +++ b/tests/out/shadow.info.ron @@ -1,7 +1,3 @@ ---- -source: tests/snapshots.rs -expression: output ---- ( functions: [ ( @@ -2873,4 +2869,4 @@ expression: output ], ), ], -) +) \ No newline at end of file diff --git a/tests/out/shadow.msl.snap b/tests/out/shadow.msl similarity index 97% rename from tests/out/shadow.msl.snap rename to tests/out/shadow.msl index 92cd9e83d..2cb78ff8d 100644 --- a/tests/out/shadow.msl.snap +++ b/tests/out/shadow.msl @@ -1,7 +1,3 @@ ---- -source: tests/snapshots.rs -expression: msl ---- #include #include @@ -67,4 +63,3 @@ fragment fs_mainOutput fs_main( } return fs_mainOutput { metal::float4(color1, 1.0) }; } - diff --git a/tests/out/shadow.ron.snap b/tests/out/shadow.ron similarity index 99% rename from tests/out/shadow.ron.snap rename to tests/out/shadow.ron index 0d57ef42e..4d1e38a3b 100644 --- a/tests/out/shadow.ron.snap +++ b/tests/out/shadow.ron @@ -1,7 +1,3 @@ ---- -source: tests/snapshots.rs -expression: output ---- ( types: [ ( @@ -1572,4 +1568,4 @@ expression: output ), ), ], -) +) \ No newline at end of file diff --git a/tests/out/shadow.spvasm.snap b/tests/out/shadow.spvasm similarity index 98% rename from tests/out/shadow.spvasm.snap rename to tests/out/shadow.spvasm index e478f288e..1f6f80039 100644 --- a/tests/out/shadow.spvasm.snap +++ b/tests/out/shadow.spvasm @@ -1,7 +1,3 @@ ---- -source: tests/snapshots.rs -expression: dis ---- ; SPIR-V ; Version: 1.2 ; Generator: rspirv @@ -209,4 +205,4 @@ OpBranch %87 %135 = OpCompositeConstruct %16 %134 %5 OpStore %79 %135 OpReturn -OpFunctionEnd +OpFunctionEnd \ No newline at end of file diff --git a/tests/out/skybox-Fragment.glsl.snap b/tests/out/skybox.Fragment.glsl similarity index 88% rename from tests/out/skybox-Fragment.glsl.snap rename to tests/out/skybox.Fragment.glsl index 2975a920b..11f715ee7 100644 --- a/tests/out/skybox-Fragment.glsl.snap +++ b/tests/out/skybox.Fragment.glsl @@ -1,7 +1,3 @@ ---- -source: tests/snapshots.rs -expression: string ---- #version 310 es precision highp float; @@ -23,4 +19,3 @@ void main() { return; } - diff --git a/tests/out/skybox-Vertex.glsl.snap b/tests/out/skybox.Vertex.glsl similarity index 95% rename from tests/out/skybox-Vertex.glsl.snap rename to tests/out/skybox.Vertex.glsl index 8c27eed33..b30eced32 100644 --- a/tests/out/skybox-Vertex.glsl.snap +++ b/tests/out/skybox.Vertex.glsl @@ -1,7 +1,3 @@ ---- -source: tests/snapshots.rs -expression: string ---- #version 310 es precision highp float; @@ -34,4 +30,3 @@ void main() { return; } - diff --git a/tests/out/skybox.msl.snap b/tests/out/skybox.msl similarity index 97% rename from tests/out/skybox.msl.snap rename to tests/out/skybox.msl index 5be5f5459..bd43ac6f6 100644 --- a/tests/out/skybox.msl.snap +++ b/tests/out/skybox.msl @@ -1,7 +1,3 @@ ---- -source: tests/snapshots.rs -expression: msl ---- #include #include @@ -61,4 +57,3 @@ fragment fs_mainOutput fs_main( metal::float4 _e5 = r_texture.sample(r_sampler, in.uv); return fs_mainOutput { _e5 }; } - diff --git a/tests/out/skybox.spvasm.snap b/tests/out/skybox.spvasm similarity index 98% rename from tests/out/skybox.spvasm.snap rename to tests/out/skybox.spvasm index d41aa067b..7455b1294 100644 --- a/tests/out/skybox.spvasm.snap +++ b/tests/out/skybox.spvasm @@ -1,7 +1,3 @@ ---- -source: tests/snapshots.rs -expression: dis ---- ; SPIR-V ; Version: 1.0 ; Generator: rspirv @@ -154,4 +150,4 @@ OpBranch %106 %110 = OpImageSampleImplicitLod %10 %109 %107 OpStore %102 %110 OpReturn -OpFunctionEnd +OpFunctionEnd \ No newline at end of file diff --git a/tests/out/texture-array.msl.snap b/tests/out/texture-array.msl similarity index 94% rename from tests/out/texture-array.msl.snap rename to tests/out/texture-array.msl index 3e98f7a0c..06c758842 100644 --- a/tests/out/texture-array.msl.snap +++ b/tests/out/texture-array.msl @@ -1,7 +1,3 @@ ---- -source: tests/snapshots.rs -expression: msl ---- #include #include @@ -31,4 +27,3 @@ fragment main1Output main1( return main1Output { _e10 }; } } - diff --git a/tests/out/texture-array.spvasm.snap b/tests/out/texture-array.spvasm similarity index 96% rename from tests/out/texture-array.spvasm.snap rename to tests/out/texture-array.spvasm index 2a5b56ef9..dfc2b1f4d 100644 --- a/tests/out/texture-array.spvasm.snap +++ b/tests/out/texture-array.spvasm @@ -1,7 +1,3 @@ ---- -source: tests/snapshots.rs -expression: dis ---- ; SPIR-V ; Version: 1.5 ; Generator: rspirv @@ -82,4 +78,4 @@ OpStore %22 %44 OpReturn %37 = OpLabel OpBranch %29 -OpFunctionEnd +OpFunctionEnd \ No newline at end of file diff --git a/tests/snapshots.rs b/tests/snapshots.rs index 472505678..e54f389c3 100644 --- a/tests/snapshots.rs +++ b/tests/snapshots.rs @@ -1,3 +1,11 @@ +//TODO: move this to a binary target once Rust supports +// binary-specific dependencies. + +use std::{fs, path::PathBuf}; + +const DIR_IN: &str = "tests/in"; +const DIR_OUT: &str = "tests/out"; + bitflags::bitflags! { struct Targets: u32 { const IR = 0x1; @@ -27,17 +35,10 @@ struct Parameters { msl_custom: bool, } -#[allow(dead_code)] -fn with_snapshot_settings ()>(snapshot_assertion: F) { - let mut settings = insta::Settings::new(); - settings.set_snapshot_path("out"); - settings.set_prepend_module_to_snapshot(false); - settings.bind(|| snapshot_assertion()); -} - #[allow(dead_code, unused_variables)] fn check_targets(module: &naga::Module, name: &str, targets: Targets) { - let params = match std::fs::read_to_string(format!("tests/in/{}{}", name, ".param.ron")) { + let root = env!("CARGO_MANIFEST_DIR"); + let params = match fs::read_to_string(format!("{}/{}/{}.param.ron", root, DIR_IN, name)) { Ok(string) => ron::de::from_str(&string).expect("Couldn't find param file"), Err(_) => Parameters::default(), }; @@ -45,41 +46,39 @@ fn check_targets(module: &naga::Module, name: &str, targets: Targets) { .validate(module) .unwrap(); + let dest = PathBuf::from(root).join(DIR_OUT).join(name); + #[cfg(feature = "serialize")] { if targets.contains(Targets::IR) { let config = ron::ser::PrettyConfig::default().with_new_line("\n".to_string()); - let output = ron::ser::to_string_pretty(module, config).unwrap(); - with_snapshot_settings(|| { - insta::assert_snapshot!(format!("{}.ron", name), output); - }); + let string = ron::ser::to_string_pretty(module, config).unwrap(); + fs::write(dest.with_extension("ron"), string).unwrap(); } if targets.contains(Targets::ANALYSIS) { let config = ron::ser::PrettyConfig::default().with_new_line("\n".to_string()); - let output = ron::ser::to_string_pretty(&info, config).unwrap(); - with_snapshot_settings(|| { - insta::assert_snapshot!(format!("{}.info.ron", name), output); - }); + let string = ron::ser::to_string_pretty(&info, config).unwrap(); + fs::write(dest.with_extension("info.ron"), string).unwrap(); } } #[cfg(feature = "spv-out")] { if targets.contains(Targets::SPIRV) { - check_output_spv(module, &info, name, ¶ms); + check_output_spv(module, &info, &dest, ¶ms); } } #[cfg(feature = "msl-out")] { if targets.contains(Targets::METAL) { - check_output_msl(module, &info, name, ¶ms); + check_output_msl(module, &info, &dest, ¶ms); } } #[cfg(feature = "glsl-out")] { if targets.contains(Targets::GLSL) { for ep in module.entry_points.iter() { - check_output_glsl(module, &info, name, ep.stage, &ep.name); + check_output_glsl(module, &info, &dest, ep.stage, &ep.name); } } } @@ -87,15 +86,13 @@ fn check_targets(module: &naga::Module, name: &str, targets: Targets) { { if targets.contains(Targets::DOT) { let string = naga::back::dot::write(module, Some(&info)).unwrap(); - with_snapshot_settings(|| { - insta::assert_snapshot!(format!("{}.dot", name), string); - }); + fs::write(dest.with_extension("dot"), string).unwrap(); } } #[cfg(feature = "hlsl-out")] { if targets.contains(Targets::HLSL) { - check_output_hlsl(module, name); + check_output_hlsl(module, &dest); } } } @@ -104,7 +101,7 @@ fn check_targets(module: &naga::Module, name: &str, targets: Targets) { fn check_output_spv( module: &naga::Module, info: &naga::valid::ModuleInfo, - name: &str, + destination: &PathBuf, params: &Parameters, ) { use naga::back::spv; @@ -128,16 +125,15 @@ fn check_output_spv( let dis = rspirv::dr::load_words(spv) .expect("Produced invalid SPIR-V") .disassemble(); - with_snapshot_settings(|| { - insta::assert_snapshot!(format!("{}.spvasm", name), dis); - }); + + fs::write(destination.with_extension("spvasm"), dis).unwrap(); } #[cfg(feature = "msl-out")] fn check_output_msl( module: &naga::Module, info: &naga::valid::ModuleInfo, - name: &str, + destination: &PathBuf, params: &Parameters, ) { use naga::back::msl; @@ -148,7 +144,7 @@ fn check_output_msl( let options = ¶ms.msl; #[cfg(not(feature = "deserialize"))] let options = if params.msl_custom { - println!("Skipping {}", name); + println!("Skipping {}", destination); return; } else { &default_options @@ -158,18 +154,16 @@ fn check_output_msl( allow_point_size: true, }; - let (msl, _) = msl::write_string(module, info, options, &pipeline_options).unwrap(); + let (string, _) = msl::write_string(module, info, options, &pipeline_options).unwrap(); - with_snapshot_settings(|| { - insta::assert_snapshot!(format!("{}.msl", name), msl); - }); + fs::write(destination.with_extension("msl"), string).unwrap(); } #[cfg(feature = "glsl-out")] fn check_output_glsl( module: &naga::Module, info: &naga::valid::ModuleInfo, - name: &str, + destination: &PathBuf, stage: naga::ShaderStage, ep_name: &str, ) { @@ -187,25 +181,24 @@ fn check_output_glsl( let string = String::from_utf8(buffer).unwrap(); - with_snapshot_settings(|| { - insta::assert_snapshot!(format!("{}-{:?}.glsl", name, stage), string); - }); + let ext = format!("{:?}.glsl", stage); + fs::write(destination.with_extension(&ext), string).unwrap(); } #[cfg(feature = "hlsl-out")] -fn check_output_hlsl(module: &naga::Module, name: &str) { +fn check_output_hlsl(module: &naga::Module, destination: &PathBuf) { use naga::back::hlsl; - let hlsl = hlsl::write_string(module).unwrap(); - with_snapshot_settings(|| { - insta::assert_snapshot!(format!("{}.hlsl", name), hlsl); - }); + let string = hlsl::write_string(module).unwrap(); + + fs::write(destination.with_extension("hlsl"), string).unwrap(); } #[cfg(feature = "wgsl-in")] fn convert_wgsl(name: &str, targets: Targets) { + let root = env!("CARGO_MANIFEST_DIR"); let module = naga::front::wgsl::parse_str( - &std::fs::read_to_string(format!("tests/in/{}{}", name, ".wgsl")) + &fs::read_to_string(format!("{}/{}/{}.wgsl", root, DIR_IN, name)) .expect("Couldn't find wgsl file"), ) .unwrap(); @@ -272,8 +265,9 @@ fn convert_wgsl_texture_array() { #[cfg(feature = "spv-in")] fn convert_spv(name: &str, adjust_coordinate_space: bool, targets: Targets) { + let root = env!("CARGO_MANIFEST_DIR"); let module = naga::front::spv::parse_u8_slice( - &std::fs::read(format!("tests/in/{}{}", name, ".spv")).expect("Couldn't find spv file"), + &fs::read(format!("{}/{}/{}.spv", root, DIR_IN, name)).expect("Couldn't find spv file"), &naga::front::spv::Options { adjust_coordinate_space, flow_graph_dump_prefix: None, @@ -304,8 +298,9 @@ fn convert_glsl( entry_points: naga::FastHashMap, _targets: Targets, ) { + let root = env!("CARGO_MANIFEST_DIR"); let _module = naga::front::glsl::parse_str( - &std::fs::read_to_string(format!("tests/in/{}{}", name, ".glsl")) + &fs::read_to_string(format!("{}/{}/{}.glsl", root, DIR_IN, name)) .expect("Couldn't find glsl file"), &naga::front::glsl::Options { entry_points,