From 6b7b3d6401219d3fb491026062cced167042fe1b Mon Sep 17 00:00:00 2001 From: Glavin Wiechert Date: Thu, 11 Jun 2015 22:07:56 -0300 Subject: [PATCH] Fix failing PHP-CS-Fixer Beautifier specs, disable some on Windows --- spec/atom-beautify-spec.coffee | 80 +++++++++++++----------- spec/beautifier-php-cs-fixer-spec.coffee | 28 ++++++--- spec/beautify-languages-spec.coffee | 9 +-- 3 files changed, 66 insertions(+), 51 deletions(-) diff --git a/spec/atom-beautify-spec.coffee b/spec/atom-beautify-spec.coffee index 3720b66..b48db92 100644 --- a/spec/atom-beautify-spec.coffee +++ b/spec/atom-beautify-spec.coffee @@ -7,6 +7,11 @@ Beautifier = require "../src/beautifiers/beautifier" # To run a specific `it` or `describe` block add an `f` to the front (e.g. `fit` # or `fdescribe`). Remove the `f` to unfocus the block. +# Check if Windows +isWindows = process.platform is 'win32' or + process.env.OSTYPE is 'cygwin' or + process.env.OSTYPE is 'msys' + describe "Atom-Beautify", -> beforeEach -> @@ -139,41 +144,42 @@ describe "Atom-Beautify", -> p.then(cb, cb) return p - it "should error with Mac/Linux-specific help description \ - when beautifier's program not found", -> - expect(beautifier).not.toBe(null) - expect(beautifier instanceof Beautifier).toBe(true) + unless isWindows + it "should error with Mac/Linux-specific help description \ + when beautifier's program not found", -> + expect(beautifier).not.toBe(null) + expect(beautifier instanceof Beautifier).toBe(true) - waitsForPromise shouldReject: true, -> - help = { - link: "http://test.com" - program: "test-program" - pathOption: "Lang - Test Program Path" - } - # Force to be Mac/Linux (not Windows) - beautifier.isWindows = false - terminal = "Terminal" - whichCmd = "which" - # Process - p = beautifier.run("program", [], help: help) - expect(p).not.toBe(null) - expect(p instanceof beautifier.Promise).toBe(true) - cb = (v) -> - # console.log(v) - expect(v).not.toBe(null) - expect(v instanceof Error).toBe(true) - expect(v.code).toBe("CommandNotFound") - expect(v.description).not.toBe(null) - expect(v.description.indexOf(help.link)).not.toBe(-1) - expect(v.description.indexOf(help.program)).not.toBe(-1) - expect(v.description - .indexOf(terminal)).not.toBe(-1, \ - "Error should have a description including \ - '#{terminal}' in message.") - expect(v.description - .indexOf(whichCmd)).not.toBe(-1, \ - "Error should have a description including \ - '#{whichCmd}' in message.") - return v - p.then(cb, cb) - return p + waitsForPromise shouldReject: true, -> + help = { + link: "http://test.com" + program: "test-program" + pathOption: "Lang - Test Program Path" + } + # Force to be Mac/Linux (not Windows) + beautifier.isWindows = false + terminal = "Terminal" + whichCmd = "which" + # Process + p = beautifier.run("program", [], help: help) + expect(p).not.toBe(null) + expect(p instanceof beautifier.Promise).toBe(true) + cb = (v) -> + # console.log(v) + expect(v).not.toBe(null) + expect(v instanceof Error).toBe(true) + expect(v.code).toBe("CommandNotFound") + expect(v.description).not.toBe(null) + expect(v.description.indexOf(help.link)).not.toBe(-1) + expect(v.description.indexOf(help.program)).not.toBe(-1) + expect(v.description + .indexOf(terminal)).not.toBe(-1, \ + "Error should have a description including \ + '#{terminal}' in message.") + expect(v.description + .indexOf(whichCmd)).not.toBe(-1, \ + "Error should have a description including \ + '#{whichCmd}' in message.") + return v + p.then(cb, cb) + return p diff --git a/spec/beautifier-php-cs-fixer-spec.coffee b/spec/beautifier-php-cs-fixer-spec.coffee index 42c58f0..a9b420d 100644 --- a/spec/beautifier-php-cs-fixer-spec.coffee +++ b/spec/beautifier-php-cs-fixer-spec.coffee @@ -7,6 +7,11 @@ path = require 'path' # To run a specific `it` or `describe` block add an `f` to the front (e.g. `fit` # or `fdescribe`). Remove the `f` to unfocus the block. +# Check if Windows +isWindows = process.platform is 'win32' or + process.env.OSTYPE is 'cygwin' or + process.env.OSTYPE is 'msys' + describe "PHP-CS-Fixer Beautifier", -> beforeEach -> @@ -43,11 +48,13 @@ describe "PHP-CS-Fixer Beautifier", -> fixers: "" levels: "" } - # Mock PATH - beautifier.getShellEnvironment = -> Promise.resolve({ - PATH: '' - }) - # + # Mock spawn + beautifier.spawn = (exe, args, options) -> + # console.log('spawn', exe, args, options) + er = new Error('ENOENT') + er.code = 'ENOENT' + return beautifier.Promise.reject(er) + # Beautify p = beautifier.beautify(text, language, options) expect(p).not.toBe(null) expect(p instanceof beautifier.Promise).toBe(true) @@ -119,13 +126,14 @@ describe "PHP-CS-Fixer Beautifier", -> failWhichProgram('php') failWhichProgram('php-cs-fixer') - describe "Mac/Linux", -> + unless isWindows + describe "Mac/Linux", -> - beforeEach -> - # console.log('mac/linx') - beautifier.isWindows = false + beforeEach -> + # console.log('mac/linx') + beautifier.isWindows = false - do OSSpecificSpecs + do OSSpecificSpecs describe "Windows", -> diff --git a/spec/beautify-languages-spec.coffee b/spec/beautify-languages-spec.coffee index 88bcfb6..ec5b721 100644 --- a/spec/beautify-languages-spec.coffee +++ b/spec/beautify-languages-spec.coffee @@ -10,6 +10,11 @@ JsDiff = require('diff') # To run a specific `it` or `describe` block add an `f` to the front (e.g. `fit` # or `fdescribe`). Remove the `f` to unfocus the block. +# Check if Windows +isWindows = process.platform is 'win32' or + process.env.OSTYPE is 'cygwin' or + process.env.OSTYPE is 'msys' + describe "BeautifyLanguages", -> optionsDir = path.resolve(__dirname, "../examples") @@ -47,10 +52,6 @@ describe "BeautifyLanguages", -> # Force activate package pack = atom.packages.getLoadedPackage("atom-beautify") pack.activateNow() - # Check if Windows - isWindows = process.platform is 'win32' or - process.env.OSTYPE is 'cygwin' or - process.env.OSTYPE is 'msys' # Need more debugging on Windows if isWindows # Change logger level