From 3e933ee81b5b137aec363d09dba0fce50c894f06 Mon Sep 17 00:00:00 2001 From: Paul Betts Date: Mon, 23 Sep 2013 11:50:05 -0700 Subject: [PATCH 1/5] Nuke these from the repo, they break cloning on Win32 --- spec/fixtures/evil-files/file with spaces.txt | 1 - "spec/fixtures/evil-files/goddam\nnewlines" | 1 - "spec/fixtures/evil-files/quote\".txt" | 1 - spec/fixtures/evil-files/utfă.md | 1 - 4 files changed, 4 deletions(-) delete mode 100644 spec/fixtures/evil-files/file with spaces.txt delete mode 100644 "spec/fixtures/evil-files/goddam\nnewlines" delete mode 100644 "spec/fixtures/evil-files/quote\".txt" delete mode 100644 spec/fixtures/evil-files/utfă.md diff --git a/spec/fixtures/evil-files/file with spaces.txt b/spec/fixtures/evil-files/file with spaces.txt deleted file mode 100644 index 140c7bf61..000000000 --- a/spec/fixtures/evil-files/file with spaces.txt +++ /dev/null @@ -1 +0,0 @@ -I am evil because there are spaces in my name diff --git "a/spec/fixtures/evil-files/goddam\nnewlines" "b/spec/fixtures/evil-files/goddam\nnewlines" deleted file mode 100644 index 00c5620b8..000000000 --- "a/spec/fixtures/evil-files/goddam\nnewlines" +++ /dev/null @@ -1 +0,0 @@ -I am evil because there's a newline in my name diff --git "a/spec/fixtures/evil-files/quote\".txt" "b/spec/fixtures/evil-files/quote\".txt" deleted file mode 100644 index 5e51d8e20..000000000 --- "a/spec/fixtures/evil-files/quote\".txt" +++ /dev/null @@ -1 +0,0 @@ -I am evil because there's a " in my filename. Why you do that!? \ No newline at end of file diff --git a/spec/fixtures/evil-files/utfă.md b/spec/fixtures/evil-files/utfă.md deleted file mode 100644 index 782a5bf5a..000000000 --- a/spec/fixtures/evil-files/utfă.md +++ /dev/null @@ -1 +0,0 @@ -I am evil because there's a UTF-8 character in my name From 459e4d55236b93c6077f4bff5a1a8545d826756b Mon Sep 17 00:00:00 2001 From: Paul Betts Date: Wed, 25 Sep 2013 17:20:59 -0700 Subject: [PATCH 2/5] Rewrite evil files test to generate files on the fly --- spec/project-spec.coffee | 60 +++++++++++++++++++++++++++++++++------- 1 file changed, 50 insertions(+), 10 deletions(-) diff --git a/spec/project-spec.coffee b/spec/project-spec.coffee index 5b37a9766..2cf12eded 100644 --- a/spec/project-spec.coffee +++ b/spec/project-spec.coffee @@ -5,6 +5,8 @@ Project = require '../src/project' path = require 'path' BufferedProcess = require '../src/buffered-process' +isWindows = !!process.platform.match /^win/ + describe "Project", -> beforeEach -> project.setPath(project.resolve('dir')) @@ -268,22 +270,60 @@ describe "Project", -> range: [[2, 6], [2, 11]] it "works on evil filenames", -> - project.setPath(path.join(__dirname, 'fixtures', 'evil-files')) + temp = process.env['TEMP'] || process.env['TMPDIR'] + target = path.join(temp, 'evil-files') + + if fs.exists(target) + (fs.readdirSync(target) || []).forEach (f) -> + fs.unlinkSync(path.join(target, f)) + fs.rmdirSync target + + fs.mkdirSync target + + inputs = [] + if (isWindows) + inputs = [ + "a_file_with_utf8.txt", + "file with spaces.txt", + "utfa\u0306.md" + ] + else + inputs = [ + "a_file_with_utf8.txt", + "file with spaces.txt", + "goddam\nnewlines", + "quote\".txt", + "utfa\u0306.md" + ] + + inputs.forEach (filename) -> + fd = fs.writeFileSync(path.join(target, filename), 'evil files!', { flag: 'w' }) + console.log(target) + + project.setPath temp + console.log("path: " + project.getPath()) + paths = [] matches = [] waitsForPromise -> project.scan /evil/, (result) -> - paths.push(result.filePath) - matches = matches.concat(result.matches) + paths.push(result.path) + matches.push(result.match) runs -> - expect(paths.length).toBe 5 - matches.forEach (match) -> expect(match.matchText).toEqual 'evil' - expect(paths[0]).toMatch /a_file_with_utf8.txt$/ - expect(paths[1]).toMatch /file with spaces.txt$/ - expect(paths[2]).toMatch /goddam\nnewlines$/m - expect(paths[3]).toMatch /quote".txt$/m - expect(path.basename(paths[4])).toBe "utfa\u0306.md" + console.log(matches) + console.log(paths) + try + expect(paths.length).toBe inputs.length + matches.forEach (match) -> + expect(match).toEqual 'evil' + + inputs.forEach (file) -> + expect(_.some(paths, (p) -> p.endsWith(file))) + finally + inputs.forEach (input) -> + fs.unlinkSync (path.join(target, input)) + fs.rmdirSync target it "ignores case if the regex includes the `i` flag", -> results = [] From 903a1b9bf06c20dc8f5415f3bc31426673c618d6 Mon Sep 17 00:00:00 2001 From: Paul Betts Date: Wed, 25 Sep 2013 17:32:00 -0700 Subject: [PATCH 3/5] Use tmp.mkdir --- spec/project-spec.coffee | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/project-spec.coffee b/spec/project-spec.coffee index 2cf12eded..8320bcdf3 100644 --- a/spec/project-spec.coffee +++ b/spec/project-spec.coffee @@ -270,7 +270,7 @@ describe "Project", -> range: [[2, 6], [2, 11]] it "works on evil filenames", -> - temp = process.env['TEMP'] || process.env['TMPDIR'] + temp = temp.mkdirSync("atom") target = path.join(temp, 'evil-files') if fs.exists(target) @@ -278,7 +278,7 @@ describe "Project", -> fs.unlinkSync(path.join(target, f)) fs.rmdirSync target - fs.mkdirSync target + fs.mkdirSync(target) inputs = [] if (isWindows) From 8b73224fe34e4fa2637a2f8f222b305145f53be8 Mon Sep 17 00:00:00 2001 From: Paul Betts Date: Wed, 25 Sep 2013 18:03:00 -0700 Subject: [PATCH 4/5] Rewrite underscore code --- spec/project-spec.coffee | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/spec/project-spec.coffee b/spec/project-spec.coffee index 8320bcdf3..5760da65e 100644 --- a/spec/project-spec.coffee +++ b/spec/project-spec.coffee @@ -315,11 +315,14 @@ describe "Project", -> console.log(paths) try expect(paths.length).toBe inputs.length - matches.forEach (match) -> - expect(match).toEqual 'evil' inputs.forEach (file) -> - expect(_.some(paths, (p) -> p.endsWith(file))) + itWorked = false + paths.forEach (p) -> + itWorked = itWorked || p.endsWith(file) + + expect(itWorked) + finally inputs.forEach (input) -> fs.unlinkSync (path.join(target, input)) From 4d415d3ca9590844e383c429e188642c5efbfd8b Mon Sep 17 00:00:00 2001 From: Matt Colyer Date: Fri, 11 Oct 2013 14:09:17 -0700 Subject: [PATCH 5/5] Generate evil file fixtures depending on platform --- .gitignore | 1 + spec/fixtures/evil-files/a_file_with_utf8.txt | 1 - spec/project-spec.coffee | 69 +++++-------------- spec/spec-helper-platform.coffee | 38 ++++++++++ spec/spec-helper.coffee | 3 + 5 files changed, 59 insertions(+), 53 deletions(-) delete mode 100644 spec/fixtures/evil-files/a_file_with_utf8.txt create mode 100644 spec/spec-helper-platform.coffee diff --git a/.gitignore b/.gitignore index 93d848dfb..981541515 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ npm-debug.log /tags /atom-shell/ docs/output +spec/fixtures/evil-files/ diff --git a/spec/fixtures/evil-files/a_file_with_utf8.txt b/spec/fixtures/evil-files/a_file_with_utf8.txt deleted file mode 100644 index a811bd702..000000000 --- a/spec/fixtures/evil-files/a_file_with_utf8.txt +++ /dev/null @@ -1 +0,0 @@ -I am evil because there's a UTF-8 character right here: ă diff --git a/spec/project-spec.coffee b/spec/project-spec.coffee index 1e67d6829..652b36400 100644 --- a/spec/project-spec.coffee +++ b/spec/project-spec.coffee @@ -3,10 +3,9 @@ fstream = require 'fstream' Project = require '../src/project' {_, fs} = require 'atom' path = require 'path' +platform = require './spec-helper-platform' BufferedProcess = require '../src/buffered-process' -isWindows = !!process.platform.match /^win/ - describe "Project", -> beforeEach -> project.setPath(project.resolve('dir')) @@ -387,63 +386,29 @@ describe "Project", -> range: [[2, 6], [2, 11]] it "works on evil filenames", -> - temp = temp.mkdirSync("atom") - target = path.join(temp, 'evil-files') - - if fs.exists(target) - (fs.readdirSync(target) || []).forEach (f) -> - fs.unlinkSync(path.join(target, f)) - fs.rmdirSync target - - fs.mkdirSync(target) - - inputs = [] - if (isWindows) - inputs = [ - "a_file_with_utf8.txt", - "file with spaces.txt", - "utfa\u0306.md" - ] - else - inputs = [ - "a_file_with_utf8.txt", - "file with spaces.txt", - "goddam\nnewlines", - "quote\".txt", - "utfa\u0306.md" - ] - - inputs.forEach (filename) -> - fd = fs.writeFileSync(path.join(target, filename), 'evil files!', { flag: 'w' }) - console.log(target) - - project.setPath temp - console.log("path: " + project.getPath()) - + project.setPath(path.join(__dirname, 'fixtures', 'evil-files')) paths = [] matches = [] waitsForPromise -> project.scan /evil/, (result) -> - paths.push(result.path) - matches.push(result.match) + paths.push(result.filePath) + matches = matches.concat(result.matches) runs -> - console.log(matches) - console.log(paths) - try - expect(paths.length).toBe inputs.length + _.each(matches, (m) -> expect(m.matchText).toEqual 'evil') - inputs.forEach (file) -> - itWorked = false - paths.forEach (p) -> - itWorked = itWorked || p.endsWith(file) - - expect(itWorked) - - finally - inputs.forEach (input) -> - fs.unlinkSync (path.join(target, input)) - fs.rmdirSync target + if platform.isWindows() + expect(paths.length).toBe 3 + expect(paths[0]).toMatch /a_file_with_utf8.txt$/ + expect(paths[1]).toMatch /file with spaces.txt$/ + expect(path.basename(paths[2])).toBe "utfa\u0306.md" + else + expect(paths.length).toBe 5 + expect(paths[0]).toMatch /a_file_with_utf8.txt$/ + expect(paths[1]).toMatch /file with spaces.txt$/ + expect(paths[2]).toMatch /goddam\nnewlines$/m + expect(paths[3]).toMatch /quote".txt$/m + expect(path.basename(paths[4])).toBe "utfa\u0306.md" it "ignores case if the regex includes the `i` flag", -> results = [] diff --git a/spec/spec-helper-platform.coffee b/spec/spec-helper-platform.coffee new file mode 100644 index 000000000..db0198e12 --- /dev/null +++ b/spec/spec-helper-platform.coffee @@ -0,0 +1,38 @@ +path = require 'path' +fsUtils = require '../src/fs-utils' + +{_} = require 'atom' + +## Platform specific helpers +module.exports = + # Public: Returns true if being run from within Windows + isWindows: -> + !!process.platform.match /^win/ + + # Public: Some files can not exist on Windows filesystems, so we have to + # selectively generate our fixtures. + # + # Returns nothing. + generateEvilFiles: -> + evilFilesPath = path.join(__dirname, 'fixtures', 'evil-files') + fsUtils.remove(evilFilesPath) if fsUtils.exists(evilFilesPath) + fsUtils.mkdirSync(evilFilesPath) + + if (@isWindows()) + filenames = [ + "a_file_with_utf8.txt", + "file with spaces.txt", + "utfa\u0306.md" + ] + else + filenames = [ + "a_file_with_utf8.txt", + "file with spaces.txt", + "goddam\nnewlines", + "quote\".txt", + "utfa\u0306.md" + ] + + for filename in filenames + fd = fsUtils.writeFileSync(path.join(evilFilesPath, filename), 'evil file!', flag: 'w') + diff --git a/spec/spec-helper.coffee b/spec/spec-helper.coffee index 72778f421..18c1b8b9d 100644 --- a/spec/spec-helper.coffee +++ b/spec/spec-helper.coffee @@ -12,8 +12,11 @@ Project = require '../src/project' Editor = require '../src/editor' TokenizedBuffer = require '../src/tokenized-buffer' pathwatcher = require 'pathwatcher' +platform = require './spec-helper-platform' clipboard = require 'clipboard' +platform.generateEvilFiles() + atom.themes.loadBaseStylesheets() atom.themes.requireStylesheet '../static/jasmine'