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
=== modified file 'data/templates/ubuntu-application/edit.py'
--- data/templates/ubuntu-application/edit.py 2011-04-27 15:02:41 +0000
+++ data/templates/ubuntu-application/edit.py 2012-06-29 18:23:20 +0000
@@ -65,11 +65,11 @@
65# add helpfile sources65# add helpfile sources
66filelist.extend(glob.glob('help/C/*.page'))66filelist.extend(glob.glob('help/C/*.page'))
6767
68editor = quicklyutils.get_quickly_editors()68editor = quicklyutils.get_quickly_editors().split()
69if templatetools.in_verbose_mode():69if templatetools.in_verbose_mode():
70 instance = subprocess.Popen([editor] + filelist)70 instance = subprocess.Popen(editor + filelist)
71else:71else:
72 nullfile=file("/dev/null")72 nullfile=file("/dev/null")
73 instance = subprocess.Popen([editor] + filelist, stderr=nullfile)73 instance = subprocess.Popen(editor + filelist, stderr=nullfile)
74if editor != 'gedit':74if editor[0] != 'gedit':
75 instance.wait()75 instance.wait()
7676
=== added file 'data/templates/ubuntu-application/test/edit.sh'
--- data/templates/ubuntu-application/test/edit.sh 1970-01-01 00:00:00 +0000
+++ data/templates/ubuntu-application/test/edit.sh 2012-06-29 18:23:20 +0000
@@ -0,0 +1,25 @@
1#!/bin/sh
2
3cd /tmp
4
5rm -rf test-project*
6
7quickly create ubuntu-application test-project
8# Creating bzr repository and committing
9# Congrats, your new project is setup! cd /tmp/test-project/ to start hacking.
10# Creating project directory test-project
11
12cd test-project
13
14bzr status
15
16EDITOR="ls -1" quickly edit 2>&1
17# help/C/index.page
18# help/C/preferences.page
19# help/C/topic1.page
20# ./test_project/AboutTestProjectDialog.py
21# ./test_project/__init__.py
22# ./test_project/PreferencesTestProjectDialog.py
23# ./test_project/TestProjectWindow.py
24# ./tests/test_example.py
25# ./tests/test_lint.py

Subscribers

People subscribed via source and target branches