From e2062d612d487aefd23c651879d479a429f3ecea Mon Sep 17 00:00:00 2001 From: Mohsin Kaleem Date: Sun, 12 Mar 2023 10:45:14 +0000 Subject: [PATCH] Update tests to fix failures from formatter definition changes --- test/formatters/apheleia-ft.el | 45 +++++-------------- .../samplecode/prettier-css/out.css | 8 ++-- .../samplecode/prettier-graphql/out.graphql | 8 ++-- .../samplecode/prettier-html/out.html | 6 +-- .../samplecode/prettier-javascript/out.js | 14 +++--- .../samplecode/prettier-json/out.json | 34 +++++++------- .../samplecode/prettier-scss/out.scss | 6 +-- .../samplecode/prettier-typescript/out.ts | 6 +-- test/formatters/samplecode/shfmt/out.bash | 2 +- 9 files changed, 53 insertions(+), 76 deletions(-) diff --git a/test/formatters/apheleia-ft.el b/test/formatters/apheleia-ft.el index 5a61ffb..46dfd27 100755 --- a/test/formatters/apheleia-ft.el +++ b/test/formatters/apheleia-ft.el @@ -226,8 +226,12 @@ environment variable, defaulting to all formatters." (let ((load-suffixes '(".el"))) (locate-library "apheleia")))))) exec-path))) + ;; Some formatters use the current file-name or buffer-name to interpret the + ;; type of file that is being formatted. Some may not be able to determine + ;; this from the contents of the file so we set this to force it. + (rename-buffer in-file) (setq stdout-buffer (get-buffer-create - (format "*apheleia-ft-stdout-%S" formatter))) + (format "*apheleia-ft-stdout-%S%s" formatter extension))) (with-current-buffer stdout-buffer (erase-buffer)) (if (functionp command) @@ -243,41 +247,14 @@ environment variable, defaulting to all formatters." (copy-to-buffer stdout-buffer (point-min) (point-max)))) (progn + (let ((result (apheleia--format-command command nil nil))) + (setq command (nthcdr 3 result) + in-temp-real-file (nth 0 result) + out-temp-file (nth 1 result))) + (with-current-buffer stdout-buffer (erase-buffer)) - (mapc - (lambda (arg) - (when (memq arg '(file filepath input output inplace)) - (cl-pushnew arg syms))) - command) - (when (or (memq 'file syms) (memq 'filepath syms)) - (setq in-temp-real-file (apheleia-ft--write-temp-file - in-text extension))) - (when (or (memq 'input syms) (memq 'inplace syms)) - (setq in-temp-file (apheleia-ft--write-temp-file - in-text extension)) - (when (memq 'inplace syms) - (setq out-temp-file in-temp-file))) - (when (memq 'output syms) - (setq out-temp-file (apheleia-ft--write-temp-file - "" extension))) - (setq command (delq 'npx command)) - (setq command - (mapcar - (lambda (arg) - (pcase arg - ((or `file `filepath) - in-temp-real-file) - ((or `input `inplace) - in-temp-file) - (`output - out-temp-file) - ((guard (stringp arg)) - arg) - (_ (eval arg)))) - command)) - (setq stdout-buffer (get-buffer-create - (format "*apheleia-ft-stdout-%S" formatter))) + (setq exit-status (apply #'call-process diff --git a/test/formatters/samplecode/prettier-css/out.css b/test/formatters/samplecode/prettier-css/out.css index 9158996..87717b9 100644 --- a/test/formatters/samplecode/prettier-css/out.css +++ b/test/formatters/samplecode/prettier-css/out.css @@ -1,6 +1,6 @@ body { - padding-left: 11em; - font-family: Georgia, "Times New Roman", Times, serif; - color: purple; - background-color: #d8da3d; + padding-left: 11em; + font-family: Georgia, "Times New Roman", Times, serif; + color: purple; + background-color: #d8da3d; } diff --git a/test/formatters/samplecode/prettier-graphql/out.graphql b/test/formatters/samplecode/prettier-graphql/out.graphql index f406f63..89828da 100644 --- a/test/formatters/samplecode/prettier-graphql/out.graphql +++ b/test/formatters/samplecode/prettier-graphql/out.graphql @@ -1,6 +1,6 @@ { - human(id: "1000") { - name - height(unit: FOOT) - } + human(id: "1000") { + name + height(unit: FOOT) + } } diff --git a/test/formatters/samplecode/prettier-html/out.html b/test/formatters/samplecode/prettier-html/out.html index 7702be8..08b8607 100644 --- a/test/formatters/samplecode/prettier-html/out.html +++ b/test/formatters/samplecode/prettier-html/out.html @@ -1,5 +1,5 @@

- Minify HTML and any - CSS or - JS included in your markup + Minify HTML and any + CSS or + JS included in your markup

diff --git a/test/formatters/samplecode/prettier-javascript/out.js b/test/formatters/samplecode/prettier-javascript/out.js index ec9cfe4..1486b51 100644 --- a/test/formatters/samplecode/prettier-javascript/out.js +++ b/test/formatters/samplecode/prettier-javascript/out.js @@ -1,10 +1,10 @@ function HelloWorld({ - greeting = "hello", - greeted = '"World"', - silent = false, - onMouseOver, + greeting = "hello", + greeted = '"World"', + silent = false, + onMouseOver, }) { - if (!greeting) { - return null; - } + if (!greeting) { + return null; + } } diff --git a/test/formatters/samplecode/prettier-json/out.json b/test/formatters/samplecode/prettier-json/out.json index 59bb3b4..86787f9 100644 --- a/test/formatters/samplecode/prettier-json/out.json +++ b/test/formatters/samplecode/prettier-json/out.json @@ -1,19 +1,19 @@ { - "arrowParens": "always", - "bracketSpacing": true, - "embeddedLanguageFormatting": "auto", - "htmlWhitespaceSensitivity": "css", - "insertPragma": false, - "jsxBracketSameLine": false, - "jsxSingleQuote": false, - "printWidth": 80, - "proseWrap": "preserve", - "quoteProps": "as-needed", - "requirePragma": false, - "semi": true, - "singleQuote": false, - "tabWidth": 2, - "trailingComma": "es5", - "useTabs": false, - "vueIndentScriptAndStyle": false + "arrowParens": "always", + "bracketSpacing": true, + "embeddedLanguageFormatting": "auto", + "htmlWhitespaceSensitivity": "css", + "insertPragma": false, + "jsxBracketSameLine": false, + "jsxSingleQuote": false, + "printWidth": 80, + "proseWrap": "preserve", + "quoteProps": "as-needed", + "requirePragma": false, + "semi": true, + "singleQuote": false, + "tabWidth": 2, + "trailingComma": "es5", + "useTabs": false, + "vueIndentScriptAndStyle": false } diff --git a/test/formatters/samplecode/prettier-scss/out.scss b/test/formatters/samplecode/prettier-scss/out.scss index 9ae1829..b5dfe19 100644 --- a/test/formatters/samplecode/prettier-scss/out.scss +++ b/test/formatters/samplecode/prettier-scss/out.scss @@ -3,7 +3,7 @@ $bgcolor: lightblue; $textcolor: darkblue; $fontsize: 18px; /* Use the variables */ body { - background-color: $bgcolor; - color: $textcolor; - font-size: $fontsize; + background-color: $bgcolor; + color: $textcolor; + font-size: $fontsize; } diff --git a/test/formatters/samplecode/prettier-typescript/out.ts b/test/formatters/samplecode/prettier-typescript/out.ts index 143b5a7..b97c21b 100644 --- a/test/formatters/samplecode/prettier-typescript/out.ts +++ b/test/formatters/samplecode/prettier-typescript/out.ts @@ -1,6 +1,6 @@ interface GreetingSettings { - greeting: string; - duration?: number; - color?: string; + greeting: string; + duration?: number; + color?: string; } declare function greet(setting: GreetingSettings): void; diff --git a/test/formatters/samplecode/shfmt/out.bash b/test/formatters/samplecode/shfmt/out.bash index 879aa94..a5903da 100644 --- a/test/formatters/samplecode/shfmt/out.bash +++ b/test/formatters/samplecode/shfmt/out.bash @@ -1,3 +1,3 @@ function f() { - thing + thing }