Merge lp:~berdario/quickly/editor-fix into lp:quickly

Proposed by Dario Bertini
Status: Needs review
Proposed branch: lp:~berdario/quickly/editor-fix
Merge into: lp:quickly
Diff against target: 49 lines (+29/-4)
2 files modified
data/templates/ubuntu-application/edit.py (+4/-4)
data/templates/ubuntu-application/test/edit.sh (+25/-0)
To merge this branch: bzr merge lp:~berdario/quickly/editor-fix
Reviewer Review Type Date Requested Status
Quickly Developers Pending
Review via email: mp+111751@code.launchpad.net

Description of the change

if $EDITOR contains a space (e.g. "emacs -nw") calling "quickly edit" would fail

To post a comment you must log in.
Revision history for this message
Didier Roche-Tolomelli (didrocks) wrote :

Hey Dario, thanks for this patch and help to make Quickly better.

You code looks overall good :) However, you can see that we have some automated tests with Quickly, would you mind writing some for this case? (use a dummy EDITOR = cat and cat -option variable)

lp:~berdario/quickly/editor-fix updated
675. By Dario Bertini

Added test for "quickly edit"
"env cat" is used as a dummy editor: it has a space to catch the previous bug, and will actually access the files, thus raising an error if quickly will try to open non-existing files

676. By Dario Bertini

The test will ignore stderr, so I can't rely on that to make it detect problems
as a workaround, I hardcoded the output of using "ls -1" as the editor, unfortunately it seems it still doesn't work

Revision history for this message
Dario Bertini (berdario) wrote :

I spent one hour trying to write a test that will correctly work when "quickly edit" works, and fail when it fails...

I gave up: see the commit message for r676

among the problems I found when writing the test:

-it won't use the local branch's copy of quickly
-it will fail if the script doesn't have a final newline
-sometimes it saves the output in a result.log, sometimes it doesn't
-it will fail if there's a blank line at the end of the script

Revision history for this message
Tony Byrne (tony-badwolf) wrote :

Hi Dario
 That was unfortunate. I had a look because writing tests *should* be easy, because it isn't quickly has failed you :(

quickly will use QUICKLY_EDITOR in preference to EDITOR if it is in the environment

so this works in edit.sh for me

QUICKLY_EDITOR="ls -1" quickly edit | grep "__init__"
# ./test_project/__init__.py

piping through grep means I don't have to list every file.

When you call quickly you will always get /usr/bin/quickly unless you change your path

So I use something like this in a makefile when I'm working on a branch
export PATH=path/to/my/quickly/bin:$$PATH

As for the final newline and blank line, it looks to me like a requirement of sed and I think it is just insane. I wrote some patches and tested them with python unittest, the quickly team added python tests capability to the test system to suit me.

Revision history for this message
Dario Bertini (berdario) wrote :

it still fails for me... I don't know what is going wrong:

Running test edit.sh...
********************************
--- data/templates/ubuntu-application/test/edit.sh 2012-06-30 12:49:12.060582184 +0200
+++ /home/dario/Projects/quickly/results.log 2012-06-30 12:50:12.432881551 +0200
@@ -14,4 +14,3 @@
 bzr status

 EDITOR="ls -1" quickly edit | grep "__init__"
-# ./test_project/__init__.py
********************************
FAILED

Revision history for this message
Dario Bertini (berdario) wrote :

to elaborate on this:
if I run the test with

test/one-test.sh data/templates/ubuntu-application/test/edit.sh

I get the failure, due to the ./test_project/__init__.py line not being printed

if I run it with

bash data/templates/ubuntu-application/test/edit.sh

./test_project/__init__.py is the last line of output as expected

If needed, right now I'm in #quickly on freenode

Unmerged revisions

676. By Dario Bertini

The test will ignore stderr, so I can't rely on that to make it detect problems
as a workaround, I hardcoded the output of using "ls -1" as the editor, unfortunately it seems it still doesn't work

675. By Dario Bertini

Added test for "quickly edit"
"env cat" is used as a dummy editor: it has a space to catch the previous bug, and will actually access the files, thus raising an error if quickly will try to open non-existing files

674. By Dario Bertini

Fixed bug: when $EDITOR contains spaces subprocess fails

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'data/templates/ubuntu-application/edit.py'
2--- data/templates/ubuntu-application/edit.py 2011-04-27 15:02:41 +0000
3+++ data/templates/ubuntu-application/edit.py 2012-06-29 18:23:20 +0000
4@@ -65,11 +65,11 @@
5 # add helpfile sources
6 filelist.extend(glob.glob('help/C/*.page'))
7
8-editor = quicklyutils.get_quickly_editors()
9+editor = quicklyutils.get_quickly_editors().split()
10 if templatetools.in_verbose_mode():
11- instance = subprocess.Popen([editor] + filelist)
12+ instance = subprocess.Popen(editor + filelist)
13 else:
14 nullfile=file("/dev/null")
15- instance = subprocess.Popen([editor] + filelist, stderr=nullfile)
16-if editor != 'gedit':
17+ instance = subprocess.Popen(editor + filelist, stderr=nullfile)
18+if editor[0] != 'gedit':
19 instance.wait()
20
21=== added file 'data/templates/ubuntu-application/test/edit.sh'
22--- data/templates/ubuntu-application/test/edit.sh 1970-01-01 00:00:00 +0000
23+++ data/templates/ubuntu-application/test/edit.sh 2012-06-29 18:23:20 +0000
24@@ -0,0 +1,25 @@
25+#!/bin/sh
26+
27+cd /tmp
28+
29+rm -rf test-project*
30+
31+quickly create ubuntu-application test-project
32+# Creating bzr repository and committing
33+# Congrats, your new project is setup! cd /tmp/test-project/ to start hacking.
34+# Creating project directory test-project
35+
36+cd test-project
37+
38+bzr status
39+
40+EDITOR="ls -1" quickly edit 2>&1
41+# help/C/index.page
42+# help/C/preferences.page
43+# help/C/topic1.page
44+# ./test_project/AboutTestProjectDialog.py
45+# ./test_project/__init__.py
46+# ./test_project/PreferencesTestProjectDialog.py
47+# ./test_project/TestProjectWindow.py
48+# ./tests/test_example.py
49+# ./tests/test_lint.py

Subscribers

People subscribed via source and target branches