From d26289a5c938eded72292a18aa2cd240e93adb5a Mon Sep 17 00:00:00 2001 From: Kenichi Kamiya Date: Sun, 9 Feb 2025 16:34:35 +0900 Subject: [PATCH] Refine E2E tests --- .github/workflows/nix.yml | 32 ++++++++------ Taskfile.yml | 44 +++++++++++++++----- dprint-dogfooding.json | 6 --- dprint.json | 2 +- examples/raw.typ | 19 --------- flake.nix | 1 + tests/all/dprint.json | 7 ++++ tests/all/expected.typ | 40 ++++++++++++++++++ tests/all/raw.typ | 53 ++++++++++++++++++++++++ tests/default/dprint.json | 1 + {examples => tests/default}/expected.typ | 15 +++++++ tests/default/raw.typ | 53 ++++++++++++++++++++++++ tests/with_global_config/dprint.json | 4 ++ tests/with_global_config/expected.typ | 37 +++++++++++++++++ tests/with_global_config/raw.typ | 53 ++++++++++++++++++++++++ 15 files changed, 318 insertions(+), 49 deletions(-) delete mode 100644 dprint-dogfooding.json delete mode 100644 examples/raw.typ create mode 100644 tests/all/dprint.json create mode 100644 tests/all/expected.typ create mode 100644 tests/all/raw.typ create mode 100644 tests/default/dprint.json rename {examples => tests/default}/expected.typ (58%) create mode 100644 tests/default/raw.typ create mode 100644 tests/with_global_config/dprint.json create mode 100644 tests/with_global_config/expected.typ create mode 100644 tests/with_global_config/raw.typ diff --git a/.github/workflows/nix.yml b/.github/workflows/nix.yml index 678c788..7c21ec0 100644 --- a/.github/workflows/nix.yml +++ b/.github/workflows/nix.yml @@ -64,27 +64,35 @@ jobs: runs-on: ubuntu-24.04 timeout-minutes: 15 needs: [build] + # Don't use `nix develop` in this steps to avoid other devshell tools and make faster to run steps: - uses: actions/checkout@v4 - - uses: dprint/check@2f1cf31537886c3bfb05591c031f7744e48ba8a1 # v2.2 + - name: Install dprint + env: + DPRINT_CLI_VERSION: '${{ matrix.dprint-version }}' + run: | + curl -fsSL https://dprint.dev/install.sh | sh -s "$DPRINT_CLI_VERSION" > /dev/null 2>&1 + echo "/home/runner/.dprint/bin" >> "$GITHUB_PATH" + - name: Install Task + uses: arduino/setup-task@v2 with: - dprint-version: '${{ matrix.dprint-version }}' - - name: Run with WASM plugin + version: '3.39.2' # selfup {"extract":"\\d\\.\\d+\\.\\d+","replacer":["task", "--version"], "nth": 3} + - name: Download pre-built plugin env: GH_TOKEN: ${{ github.token }} run: | gh run download '${{ github.run_id }}' tree + - name: Make sure dependencies + run: | dprint --version - dprint output-file-paths --config=dprint-dogfooding.json "--plugins=${PWD}/plugins/dprint_plugin_typstyle.wasm" - - run: dprint check --config=dprint-dogfooding.json "--plugins=${PWD}/plugins/dprint_plugin_typstyle.wasm" - id: dprint-check - continue-on-error: true - - run: false - if: steps.dprint-check.outcome == 'success' - - run: | - dprint fmt --config=dprint-dogfooding.json "--plugins=${PWD}/plugins/dprint_plugin_typstyle.wasm" - diff ./examples/raw.typ ./examples/expected.typ + task --version + diff --version + - name: Test + env: + PLUGIN_DIR: '${{ github.workspace }}/plugins/dprint_plugin_typstyle.wasm' + run: + task test release: if: startsWith(github.ref, 'refs/tags/') runs-on: ubuntu-24.04 diff --git a/Taskfile.yml b/Taskfile.yml index 2fe842a..3b306e3 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -2,20 +2,47 @@ version: '3' +env: + PLUGIN_DIR: '{{.USER_WORKING_DIR}}/target/wasm32-unknown-unknown/release' + tasks: default: deps: - - task: check - - task: build - build: + - check + - build + build: # Prefer cargo cache rather than go-task cache feature - cargo build --release --target=wasm32-unknown-unknown check: deps: - - task: test - - task: lint + - test + - lint test: + deps: + - test-e2e-default + - test-e2e-all + - test-e2e-with_global_config + # cmds: + # - cargo test # There is no test. If adding here, required to update GitHub Actions workflow + test-e2e-*: + deps: + - build + vars: + TESTNAME: '{{index .MATCH 0}}' + cmds: + - cd 'tests/{{.TESTNAME}}' && dprint check --plugins="$PLUGIN_DIR/dprint_plugin_typstyle.wasm" expected.typ + - cd 'tests/{{.TESTNAME}}' && diff <(cat raw.typ | dprint fmt --stdin raw.typ --plugins="$PLUGIN_DIR/dprint_plugin_typstyle.wasm") expected.typ + bump-fixtures-*: + deps: + - build + vars: + TESTNAME: '{{index .MATCH 0}}' cmds: - - cargo test + - cd 'tests/{{.TESTNAME}}' && cat raw.typ | dprint fmt --stdin raw.typ --plugins="$PLUGIN_DIR/dprint_plugin_typstyle.wasm" > expected.typ + bump-fixtures: + deps: + - bump-fixtures-default + - bump-fixtures-all + - bump-fixtures-with_global_config fmt: cmds: - cargo fmt @@ -29,11 +56,6 @@ tasks: # nix fmt doesn't have check: https://github.com/NixOS/nix/issues/6918 - git ls-files '*.nix' | xargs nixfmt --check - git ls-files | xargs selfup list -check - dogfooding: # Intentionally failing - deps: - - task: build - cmds: - - dprint check --config=dprint-dogfooding.json --plugins=./target/wasm32-unknown-unknown/release/dprint_plugin_typstyle.wasm selfup: cmds: - git ls-files | xargs selfup run diff --git a/dprint-dogfooding.json b/dprint-dogfooding.json deleted file mode 100644 index ae3e0c2..0000000 --- a/dprint-dogfooding.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "typst": { - "column": 78 - }, - "excludes": [".git", ".direnv", "target"] -} diff --git a/dprint.json b/dprint.json index 208c9b1..1902253 100644 --- a/dprint.json +++ b/dprint.json @@ -10,7 +10,7 @@ }, "toml": { }, - "excludes": [".git", ".direnv", "target", "examples/expected*"], + "excludes": [".git", ".direnv", "target", "tests"], "plugins": [ "https://plugins.dprint.dev/json-0.19.4.wasm", "https://plugins.dprint.dev/markdown-0.17.8.wasm", diff --git a/examples/raw.typ b/examples/raw.typ deleted file mode 100644 index 2ffcc5d..0000000 --- a/examples/raw.typ +++ /dev/null @@ -1,19 +0,0 @@ -#set text( - font: "New Computer Modern", - size: 10pt -) -#set page( - paper: "a6", - margin: (x: 1.8cm, y: 1.5cm), -) -#set par( - justify: true, - leading: 0.52em, -) - -= Introduction -In this report, we will explore the -various factors that influence fluid -dynamics in glaciers and how they -contribute to the formation and -behaviour of these natural structures. diff --git a/flake.nix b/flake.nix index c3863b0..12bccab 100644 --- a/flake.nix +++ b/flake.nix @@ -33,6 +33,7 @@ (with pkgs; [ bashInteractive findutils # xargs + diffutils # for E2E test nixfmt-rfc-style nil go-task diff --git a/tests/all/dprint.json b/tests/all/dprint.json new file mode 100644 index 0000000..8f86060 --- /dev/null +++ b/tests/all/dprint.json @@ -0,0 +1,7 @@ +{ + "typst": { + "tab_spaces": 3, + "column": 20, + "blank_lines_upper_bound": 5, + }, +} diff --git a/tests/all/expected.typ b/tests/all/expected.typ new file mode 100644 index 0000000..d67bced --- /dev/null +++ b/tests/all/expected.typ @@ -0,0 +1,40 @@ +#set text( + font: "New Computer Modern", + + + size: 10pt, +) +#set page( + paper: "a6", + margin: ( + x: 1.8cm, + y: 1.5cm, + ), +) +#set par( + justify: true, + + + + + + leading: 0.52em, +) + +This line has spaces. + +This line is much much much much much much much much much much much much much much much much much much much much much much much much much much long. + +#set rect( + width: 100%, + height: 100%, + inset: 4pt, + stroke: auto, +) + += Introduction +In this report, we will explore the +various factors that influence fluid +dynamics in glaciers and how they +contribute to the formation and +behaviour of these natural structures. diff --git a/tests/all/raw.typ b/tests/all/raw.typ new file mode 100644 index 0000000..f0584ca --- /dev/null +++ b/tests/all/raw.typ @@ -0,0 +1,53 @@ +#set text( + font: "New Computer Modern" + , + + + size: 10pt +) +#set page( + paper: "a6", + margin: (x: 1.8cm, y: 1.5cm), +) +#set par( +justify: true, + + + + + + + + + + + + + + + + + + + + + + + + leading: 0.52em, +) + +This line has spaces. + +This line is much much much much much much much much much much much much much much much much much much much much much much much much much much long. + +#set rect( + width: 100%, height: 100%, inset: 4pt, stroke: auto +) + += Introduction +In this report, we will explore the +various factors that influence fluid +dynamics in glaciers and how they +contribute to the formation and +behaviour of these natural structures. diff --git a/tests/default/dprint.json b/tests/default/dprint.json new file mode 100644 index 0000000..0967ef4 --- /dev/null +++ b/tests/default/dprint.json @@ -0,0 +1 @@ +{} diff --git a/examples/expected.typ b/tests/default/expected.typ similarity index 58% rename from examples/expected.typ rename to tests/default/expected.typ index 5d81773..acef511 100644 --- a/examples/expected.typ +++ b/tests/default/expected.typ @@ -1,5 +1,7 @@ #set text( font: "New Computer Modern", + + size: 10pt, ) #set page( @@ -8,9 +10,22 @@ ) #set par( justify: true, + + leading: 0.52em, ) +This line has spaces. + +This line is much much much much much much much much much much much much much much much much much much much much much much much much much much long. + +#set rect( + width: 100%, + height: 100%, + inset: 4pt, + stroke: auto, +) + = Introduction In this report, we will explore the various factors that influence fluid diff --git a/tests/default/raw.typ b/tests/default/raw.typ new file mode 100644 index 0000000..f0584ca --- /dev/null +++ b/tests/default/raw.typ @@ -0,0 +1,53 @@ +#set text( + font: "New Computer Modern" + , + + + size: 10pt +) +#set page( + paper: "a6", + margin: (x: 1.8cm, y: 1.5cm), +) +#set par( +justify: true, + + + + + + + + + + + + + + + + + + + + + + + + leading: 0.52em, +) + +This line has spaces. + +This line is much much much much much much much much much much much much much much much much much much much much much much much much much much long. + +#set rect( + width: 100%, height: 100%, inset: 4pt, stroke: auto +) + += Introduction +In this report, we will explore the +various factors that influence fluid +dynamics in glaciers and how they +contribute to the formation and +behaviour of these natural structures. diff --git a/tests/with_global_config/dprint.json b/tests/with_global_config/dprint.json new file mode 100644 index 0000000..e772853 --- /dev/null +++ b/tests/with_global_config/dprint.json @@ -0,0 +1,4 @@ +{ + "lineWidth": 20, + "indentWidth": 3 +} diff --git a/tests/with_global_config/expected.typ b/tests/with_global_config/expected.typ new file mode 100644 index 0000000..5bf9e99 --- /dev/null +++ b/tests/with_global_config/expected.typ @@ -0,0 +1,37 @@ +#set text( + font: "New Computer Modern", + + + size: 10pt, +) +#set page( + paper: "a6", + margin: ( + x: 1.8cm, + y: 1.5cm, + ), +) +#set par( + justify: true, + + + leading: 0.52em, +) + +This line has spaces. + +This line is much much much much much much much much much much much much much much much much much much much much much much much much much much long. + +#set rect( + width: 100%, + height: 100%, + inset: 4pt, + stroke: auto, +) + += Introduction +In this report, we will explore the +various factors that influence fluid +dynamics in glaciers and how they +contribute to the formation and +behaviour of these natural structures. diff --git a/tests/with_global_config/raw.typ b/tests/with_global_config/raw.typ new file mode 100644 index 0000000..f0584ca --- /dev/null +++ b/tests/with_global_config/raw.typ @@ -0,0 +1,53 @@ +#set text( + font: "New Computer Modern" + , + + + size: 10pt +) +#set page( + paper: "a6", + margin: (x: 1.8cm, y: 1.5cm), +) +#set par( +justify: true, + + + + + + + + + + + + + + + + + + + + + + + + leading: 0.52em, +) + +This line has spaces. + +This line is much much much much much much much much much much much much much much much much much much much much much much much much much much long. + +#set rect( + width: 100%, height: 100%, inset: 4pt, stroke: auto +) + += Introduction +In this report, we will explore the +various factors that influence fluid +dynamics in glaciers and how they +contribute to the formation and +behaviour of these natural structures.