summary refs log blame commit diff stats
path: root/doc/cd-after-exit.txt
blob: 5e54fee05c9bdba8c32dada956b074eff532ba42 (plain) (tree)
1
2
3
4
5
6
7
8
9






                                                                            

                                                           





























                                                                            
 












































































                                                                              



                                                                          















                                                                           













                                                                          
 
            
The "cd-after-exit" Feature

== Abstract

This document explains the troublesome implementation of the "cd-after-exit"
feature.

This is written for developers who wonder how it's working.


== Specification

When the feature is enabled, ranger will attempt to change the directory of
the parent shell (from which ranger is run) to the last visited directory
when ranger is exited.

This task is, by its nature, shell dependent.  As a bash or zsh user,
I focused on the implementation for those two shells and left the
addition of support for csh, ksh, and other shells to those who actually use
those shells.


== What's the problem?

Shells have several limitations, the implementation could not be done easily
because:

1. It is not possible to use something like system('cd xyz') at the end.
This command would run in a new shell and wouldn't change the directory
of the parent shell at all.

2. Using exec('cd xyz') is not possible either, since 'cd' is a command
which is directly integrated in to the shell and can not be run this way.


== Redirection of streams

The only way I found is using cd `program` from inside the shell to change
the directory to whatever `program` prints to the stdout:

    bash$ cd `echo ..`

Since the user interface still has to be printed, we simply redirect it to
the stderr.  It is not sufficient however to change sys.stdout to sys.stderr,
since curses seems not to be aware of sys.stdout and continues to print out
the interface to the actual stdout.

So what I did was swap the stdout and stderr of the whole ranger process on
the shell command line by using:

    bash$ cd `ranger 3>&1 1>&2 2>&3 3>&-`

Since errors are now printed to the stdout, we have do this in ranger:
    sys.stderr = sys.__stdout__

And at the end, write the current directory to the stdout, which is now
reachable via sys.__stderr__ due to the redirections:
    sys.__stderr__.write(last_visited_directory)

To inform the ranger process about these changes, we add a --cd-after-exit
switch which:
    bash$ cd `ranger --cd-after-exit 3>&1 1>&2 2>&3 3>&-`


== Argument passing

This works well enough, but there are two remaining problems:

1. How to pass arguments to ranger?

2. How to memorize that line? Although you can just copy+paste it
into your bashrc and create an alias, the complexity of the line
could lead to errors.

Both problems are solved by putting the command in a file:

run.sh:
    cd "`ranger --cd-after-exit \"$@\" 3>&1 1>&2 2>&3 3>&-`"

The $@ is responsible for argument passing.  By using the source command,
the file will be evaluated without creating a distinct new shell.

    bash$ source run.sh arg1 ... argN

To add flexibility, replace the name "ranger" in the command to the first
argument.  Now it requires you to pass the name of the ranger command to
the script as the first argument:

run.sh:
    RANGER="$1"
    shift
    cd "`$RANGER --cd-after-exit \"$@\" 3>&1 1>&2 2>&3 3>&-`"


== Put it in a nutshell

I didn't want to have 2 files for the main program and wanted just one
file at /usr/bin/ranger.  So I used this trick to merge both files into one:

    #!/usr/bin/python
    """":
    <shell code>
    """
    <python code>

If you run this file with python, or simply by typing ranger, the program will
run normally.  If you, however, run this file by sourcing it into the shell,
like you did with run.sh, the cd-after-exit mode will be activated.

Now the way of running ranger with the cd-after-exit feature is:

    bash$ source /path/to/ranger.py /path/to/ranger.py

or, if properly installed:

    bash$ source ranger ranger

A convenient way of using this feature is adding this line to your bashrc:

    alias rn='source ranger ranger'


== Open issues

Unfortunately there is some redundancy: you have to type the path to ranger
twice.  I know of no way to fix this, because it is not possible to get the
filename of the file currently being sourced.

Example:

    bash$ echo 'source sourced.sh' > main.sh
    bash$ echo 'echo $0 $@' > sourced.sh
    bash$ bash main.sh
    main.sh

If you find a way to make this print out 'sourced.sh', let me know. :)

Another thing: If Ctrl+C is pressed anywhere in the program, the execution
of the sourced shell script is stopped and the feature stops working.

This was handled by using a script like that:

    ranger_exec="$1"
    shift
    trap "" INT
    exec 3< <($ranger_exec --cd-after-exit $@ 3>&1 1>&2 2>&3 3>&-)
    while read ranger_output; do false; done <&3
    cd "$ranger_output"
    #...and some clean ups

but that won't work in zsh for some reason, so I took it out again.

Dec 25, 2009
c?id=b4e9905db971b67450bf4da63fd9ccff5de0aa69'>b4e9905d ^
b4e9905d ^



b4e9905d ^

5319a03a ^
b4e9905d ^
81190251 ^
b4e9905d ^

81190251 ^
b4e9905d ^
b4e9905d ^



b4e9905d ^

5319a03a ^
b4e9905d ^
81190251 ^
b4e9905d ^

81190251 ^
b4e9905d ^
b4e9905d ^



b4e9905d ^

5319a03a ^
b4e9905d ^
81190251 ^
b4e9905d ^

81190251 ^
b4e9905d ^
b4e9905d ^



b4e9905d ^

5319a03a ^
b4e9905d ^



81190251 ^
b4e9905d ^
b4e9905d ^



b4e9905d ^

5319a03a ^
b4e9905d ^



81190251 ^
b4e9905d ^
b4e9905d ^



b4e9905d ^

5319a03a ^
b4e9905d ^



81190251 ^
b4e9905d ^
b4e9905d ^



b4e9905d ^

5319a03a ^
b4e9905d ^


21f0bd04 ^
81190251 ^
21f0bd04 ^
21f0bd04 ^



21f0bd04 ^

5319a03a ^
21f0bd04 ^
81190251 ^
21f0bd04 ^
91d4097d ^
81190251 ^
91d4097d ^
91d4097d ^



91d4097d ^

5319a03a ^
91d4097d ^
81190251 ^
91d4097d ^
bd221f6f ^
81190251 ^
bd221f6f ^
bd221f6f ^



bd221f6f ^

5319a03a ^
bd221f6f ^
81190251 ^
bd221f6f ^

81190251 ^
bd221f6f ^
bd221f6f ^



bd221f6f ^

5319a03a ^
bd221f6f ^
81190251 ^
bd221f6f ^
b4e9905d ^
81190251 ^
0ee6c7a6 ^
0ee6c7a6 ^



0ee6c7a6 ^

5319a03a ^



0ee6c7a6 ^
5319a03a ^
0ee6c7a6 ^
5319a03a ^
0ee6c7a6 ^
5319a03a ^




0ee6c7a6 ^
81190251 ^
0ee6c7a6 ^
0ee6c7a6 ^



0ee6c7a6 ^
7842b0d1 ^
5319a03a ^



5c65599e ^
5319a03a ^
7842b0d1 ^
5319a03a ^
0ee6c7a6 ^
5319a03a ^




0ee6c7a6 ^
81190251 ^
0ee6c7a6 ^
0ee6c7a6 ^



0ee6c7a6 ^

5319a03a ^



0ee6c7a6 ^
5319a03a ^
0ee6c7a6 ^
5319a03a ^
0ee6c7a6 ^
5319a03a ^




7842b0d1 ^
81190251 ^
7842b0d1 ^
540d658e ^
cae2979a ^


cae2979a ^
6af10696 ^
6640a089 ^
cae2979a ^
5319a03a ^
cae2979a ^
5319a03a ^

cae2979a ^
d56f6dc3 ^
5ec2d3cf ^
5319a03a ^

5ec2d3cf ^
81190251 ^
5ec2d3cf ^
5ec2d3cf ^



5ec2d3cf ^
6af10696 ^
6640a089 ^
5ec2d3cf ^
5319a03a ^



5ec2d3cf ^
5319a03a ^
5ec2d3cf ^
5319a03a ^

cae2979a ^
81190251 ^
cae2979a ^
cae2979a ^
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405




                   
                   
                 

                      
 
                  
                       
 
                             
                            
 

                              
                                                                    
 
                                                      
 

                                                                                    
                                                           
                        

 
                                                               



                                                      
                                                            



                                                   
                                                           
 
                                                  

 
                                                           


                                                  
 










































































                                                                                 
                                                                                                              
















                                                                            

                                                               

                                                          
                                                                   
 
                                                        

                         
                                                           
                        



                                                                    

                                                                             
                                                                   
 
                                                        

                         
                                                           
                        



                                                             

                                                        
                                                                   
 
                                                        

                         
                                                           
                        



                                                                    

                                                                          
                                                                   
 
                                                        

                         
                                                           
                        



                                                        

                                                             
                                                                   



                                                                   
                                                           
                        



                                                             

                                                              
                                                                   



                                                                    
                                                           
                        



                                                            

                                                                 
                                                                   



                                                                       
                                                           
                        



                                                                     

                                                                 
                                                                   


                                                                 
 
                                                           
                        



                                                                     

                                                                                          
                                                                   
 
                                                        
                         
 
                                                           
                        



                                                                   

                                                                                
                                                                   
 
                                                        
                         
 
                                                           
                        



                                                                      

                                                                   
                                                                   
 
                                                        

                         
                                                           
                        



                                                                       

                                                                                      
                                                                   
 
                                                        
                         
 
                                                           
                        



                                                        

                                                                     



                                                                   
 
                                                     
 
                                                      
 




                                                                       
 
                                                           
                        



                                                      
                                                                
 



                                                                   
 
                                                     
 
                                                      
 




                                                                       
 
                                                           
                        



                                                                 

                                                                                     



                                                                   
 
                                                     
 
                                                      
 




                                                                       
 
                                                           
                        
 


                                                                         
                                           
                                                                                         
                                                                                                                  
 
                                                                   
 

                                               
 
                                                                                     
 

                                                                
 
                                                           
                        



                                                    
                                           
                                                                                       
                                                                                                              
 



                                                                   
 
                                                                            
 

                                                                                  
 
                                                           
                        
 
#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
#include <cmocka.h>
#include <stdlib.h>
#include <string.h>
#include <glib.h>

#include "xmpp/xmpp.h"

#include "ui/ui.h"
#include "ui/stub_ui.h"

#include "command/commands.h"
#include "config/accounts.h"

#define CMD_CONNECT "/connect"

static void test_with_connection_status(jabber_conn_status_t status)
{
    will_return(jabber_get_connection_status, status);

    expect_cons_show("You are either connected already, or a login is in process.");

    gboolean result = cmd_connect(NULL, CMD_CONNECT, NULL);
    assert_true(result);
}

void cmd_connect_shows_message_when_disconnecting(void **state)
{
    test_with_connection_status(JABBER_DISCONNECTING);
}

void cmd_connect_shows_message_when_connecting(void **state)
{
    test_with_connection_status(JABBER_CONNECTING);
}

void cmd_connect_shows_message_when_connected(void **state)
{
    test_with_connection_status(JABBER_CONNECTED);
}

void cmd_connect_shows_message_when_undefined(void **state)
{
    test_with_connection_status(JABBER_UNDEFINED);
}

void cmd_connect_when_no_account(void **state)
{
    gchar *args[] = { "user@server.org", NULL };

    will_return(jabber_get_connection_status, JABBER_DISCONNECTED);

    expect_string(accounts_get_account, name, "user@server.org");
    will_return(accounts_get_account, NULL);

    will_return(ui_ask_password, strdup("password"));

    expect_cons_show("Connecting as user@server.org");

    expect_string(jabber_connect_with_details, jid, "user@server.org");
    expect_string(jabber_connect_with_details, passwd, "password");
    expect_value(jabber_connect_with_details, altdomain, NULL);
    expect_value(jabber_connect_with_details, port, 0);
    will_return(jabber_connect_with_details, JABBER_CONNECTING);

    gboolean result = cmd_connect(NULL, CMD_CONNECT, args);
    assert_true(result);
}

void cmd_connect_fail_message(void **state)
{
    gchar *args[] = { "user@server.org", NULL };

    will_return(jabber_get_connection_status, JABBER_DISCONNECTED);

    expect_any(accounts_get_account, name);
    will_return(accounts_get_account, NULL);

    will_return(ui_ask_password, strdup("password"));

    expect_cons_show("Connecting as user@server.org");

    expect_any(jabber_connect_with_details, jid);
    expect_any(jabber_connect_with_details, passwd);
    expect_any(jabber_connect_with_details, altdomain);
    expect_any(jabber_connect_with_details, port);
    will_return(jabber_connect_with_details, JABBER_DISCONNECTED);

    expect_cons_show_error("Connection attempt for user@server.org failed.");

    gboolean result = cmd_connect(NULL, CMD_CONNECT, args);
    assert_true(result);
}

void cmd_connect_lowercases_argument(void **state)
{
    gchar *args[] = { "USER@server.ORG", NULL };

    will_return(jabber_get_connection_status, JABBER_DISCONNECTED);

    expect_string(accounts_get_account, name, "user@server.org");
    will_return(accounts_get_account, NULL);

    will_return(ui_ask_password, strdup("password"));

    expect_cons_show("Connecting as user@server.org");

    expect_any(jabber_connect_with_details, jid);
    expect_any(jabber_connect_with_details, passwd);
    expect_any(jabber_connect_with_details, altdomain);
    expect_any(jabber_connect_with_details, port);
    will_return(jabber_connect_with_details, JABBER_CONNECTING);

    gboolean result = cmd_connect(NULL, CMD_CONNECT, args);
    assert_true(result);
}

void cmd_connect_asks_password_when_not_in_account(void **state)
{
    gchar *args[] = { "jabber_org", NULL };
    ProfAccount *account = account_new("jabber_org", "me@jabber.org", NULL, NULL,
        TRUE, NULL, 0, NULL, NULL, NULL, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);

    will_return(jabber_get_connection_status, JABBER_DISCONNECTED);

    expect_any(accounts_get_account, name);
    will_return(accounts_get_account, account);

    will_return(ui_ask_password, strdup("password"));

    expect_cons_show("Connecting with account jabber_org as me@jabber.org");

    expect_any(jabber_connect_with_account, account);
    will_return(jabber_connect_with_account, JABBER_CONNECTING);

    gboolean result = cmd_connect(NULL, CMD_CONNECT, args);
    assert_true(result);
}

void cmd_connect_shows_usage_when_no_server_value(void **state)
{
    gchar *args[] = { "user@server.org", "server", NULL };

    will_return(jabber_get_connection_status, JABBER_DISCONNECTED);

    expect_string(cons_bad_cmd_usage, cmd, CMD_CONNECT);
    expect_cons_show("");

    gboolean result = cmd_connect(NULL, CMD_CONNECT, args);
    assert_true(result);
}

void cmd_connect_shows_usage_when_server_no_port_value(void **state)
{
    gchar *args[] = { "user@server.org", "server", "aserver", "port", NULL };

    will_return(jabber_get_connection_status, JABBER_DISCONNECTED);

    expect_string(cons_bad_cmd_usage, cmd, CMD_CONNECT);
    expect_cons_show("");

    gboolean result = cmd_connect(NULL, CMD_CONNECT, args);
    assert_true(result);
}

void cmd_connect_shows_usage_when_no_port_value(void **state)
{
    gchar *args[] = { "user@server.org", "port", NULL };

    will_return(jabber_get_connection_status, JABBER_DISCONNECTED);

    expect_string(cons_bad_cmd_usage, cmd, CMD_CONNECT);
    expect_cons_show("");

    gboolean result = cmd_connect(NULL, CMD_CONNECT, args);
    assert_true(result);
}

void cmd_connect_shows_usage_when_port_no_server_value(void **state)
{
    gchar *args[] = { "user@server.org", "port", "5678", "server", NULL };

    will_return(jabber_get_connection_status, JABBER_DISCONNECTED);

    expect_string(cons_bad_cmd_usage, cmd, CMD_CONNECT);
    expect_cons_show("");

    gboolean result = cmd_connect(NULL, CMD_CONNECT, args);
    assert_true(result);
}

void cmd_connect_shows_message_when_port_0(void **state)
{
    gchar *args[] = { "user@server.org", "port", "0", NULL };

    will_return(jabber_get_connection_status, JABBER_DISCONNECTED);

    expect_cons_show("Value 0 out of range. Must be in 1..65535.");
    expect_cons_show("");

    gboolean result = cmd_connect(NULL, CMD_CONNECT, args);
    assert_true(result);
}

void cmd_connect_shows_message_when_port_minus1(void **state)
{
    gchar *args[] = { "user@server.org", "port", "-1", NULL };

    will_return(jabber_get_connection_status, JABBER_DISCONNECTED);

    expect_cons_show("Value -1 out of range. Must be in 1..65535.");
    expect_cons_show("");

    gboolean result = cmd_connect(NULL, CMD_CONNECT, args);
    assert_true(result);
}

void cmd_connect_shows_message_when_port_65536(void **state)
{
    gchar *args[] = { "user@server.org", "port", "65536", NULL };

    will_return(jabber_get_connection_status, JABBER_DISCONNECTED);

    expect_cons_show("Value 65536 out of range. Must be in 1..65535.");
    expect_cons_show("");

    gboolean result = cmd_connect(NULL, CMD_CONNECT, args);
    assert_true(result);
}

void cmd_connect_shows_message_when_port_contains_chars(void **state)
{
    gchar *args[] = { "user@server.org", "port", "52f66", NULL };

    will_return(jabber_get_connection_status, JABBER_DISCONNECTED);

    expect_cons_show("Could not convert \"52f66\" to a number.");
    expect_cons_show("");

    gboolean result = cmd_connect(NULL, CMD_CONNECT, args);
    assert_true(result);
}

void cmd_connect_shows_usage_when_server_provided_twice(void **state)
{
    gchar *args[] = { "user@server.org", "server", "server1", "server", "server2", NULL };

    will_return(jabber_get_connection_status, JABBER_DISCONNECTED);

    expect_string(cons_bad_cmd_usage, cmd, CMD_CONNECT);
    expect_cons_show("");

    gboolean result = cmd_connect(NULL, CMD_CONNECT, args);
    assert_true(result);
}

void cmd_connect_shows_usage_when_port_provided_twice(void **state)
{
    gchar *args[] = { "user@server.org", "port", "1111", "port", "1111", NULL };

    will_return(jabber_get_connection_status, JABBER_DISCONNECTED);

    expect_string(cons_bad_cmd_usage, cmd, CMD_CONNECT);
    expect_cons_show("");

    gboolean result = cmd_connect(NULL, CMD_CONNECT, args);
    assert_true(result);
}

void cmd_connect_shows_usage_when_invalid_first_property(void **state)
{
    gchar *args[] = { "user@server.org", "wrong", "server", NULL };

    will_return(jabber_get_connection_status, JABBER_DISCONNECTED);

    expect_string(cons_bad_cmd_usage, cmd, CMD_CONNECT);
    expect_cons_show("");

    gboolean result = cmd_connect(NULL, CMD_CONNECT, args);
    assert_true(result);
}

void cmd_connect_shows_usage_when_invalid_second_property(void **state)
{
    gchar *args[] = { "user@server.org", "server", "aserver", "wrong", "1234", NULL };

    will_return(jabber_get_connection_status, JABBER_DISCONNECTED);

    expect_string(cons_bad_cmd_usage, cmd, CMD_CONNECT);
    expect_cons_show("");

    gboolean result = cmd_connect(NULL, CMD_CONNECT, args);
    assert_true(result);
}

void cmd_connect_with_server_when_provided(void **state)
{
    gchar *args[] = { "user@server.org", "server", "aserver", NULL };

    will_return(jabber_get_connection_status, JABBER_DISCONNECTED);

    expect_string(accounts_get_account, name, "user@server.org");
    will_return(accounts_get_account, NULL);

    will_return(ui_ask_password, strdup("password"));

    expect_cons_show("Connecting as user@server.org");

    expect_string(jabber_connect_with_details, jid, "user@server.org");
    expect_string(jabber_connect_with_details, passwd, "password");
    expect_string(jabber_connect_with_details, altdomain, "aserver");
    expect_value(jabber_connect_with_details, port, 0);
    will_return(jabber_connect_with_details, JABBER_CONNECTING);

    gboolean result = cmd_connect(NULL, CMD_CONNECT, args);
    assert_true(result);
}

void cmd_connect_with_port_when_provided(void **state)
{
    gchar *args[] = { "user@server.org", "port", "5432", NULL };

    will_return(jabber_get_connection_status, JABBER_DISCONNECTED);

    expect_string(accounts_get_account, name, "user@server.org");
    will_return(accounts_get_account, NULL);

    will_return(ui_ask_password, strdup("password"));

    expect_cons_show("Connecting as user@server.org");

    expect_string(jabber_connect_with_details, jid, "user@server.org");
    expect_string(jabber_connect_with_details, passwd, "password");
    expect_value(jabber_connect_with_details, altdomain, NULL);
    expect_value(jabber_connect_with_details, port, 5432);
    will_return(jabber_connect_with_details, JABBER_CONNECTING);

    gboolean result = cmd_connect(NULL, CMD_CONNECT, args);
    assert_true(result);
}

void cmd_connect_with_server_and_port_when_provided(void **state)
{
    gchar *args[] = { "user@server.org", "port", "5432", "server", "aserver", NULL };

    will_return(jabber_get_connection_status, JABBER_DISCONNECTED);

    expect_string(accounts_get_account, name, "user@server.org");
    will_return(accounts_get_account, NULL);

    will_return(ui_ask_password, strdup("password"));

    expect_cons_show("Connecting as user@server.org");

    expect_string(jabber_connect_with_details, jid, "user@server.org");
    expect_string(jabber_connect_with_details, passwd, "password");
    expect_string(jabber_connect_with_details, altdomain, "aserver");
    expect_value(jabber_connect_with_details, port, 5432);
    will_return(jabber_connect_with_details, JABBER_CONNECTING);

    gboolean result = cmd_connect(NULL, CMD_CONNECT, args);
    assert_true(result);
}

void cmd_connect_shows_message_when_connecting_with_account(void **state)
{
    gchar *args[] = { "jabber_org", NULL };
    ProfAccount *account = account_new("jabber_org", "user@jabber.org", "password", NULL,
        TRUE, NULL, 0, "laptop", NULL, NULL, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);

    will_return(jabber_get_connection_status, JABBER_DISCONNECTED);

    expect_any(accounts_get_account, name);
    will_return(accounts_get_account, account);

    expect_cons_show("Connecting with account jabber_org as user@jabber.org/laptop");

    expect_any(jabber_connect_with_account, account);
    will_return(jabber_connect_with_account, JABBER_CONNECTING);

    gboolean result = cmd_connect(NULL, CMD_CONNECT, args);
    assert_true(result);
}

void cmd_connect_connects_with_account(void **state)
{
    gchar *args[] = { "jabber_org", NULL };
    ProfAccount *account = account_new("jabber_org", "me@jabber.org", "password", NULL,
        TRUE, NULL, 0, NULL, NULL, NULL, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);

    will_return(jabber_get_connection_status, JABBER_DISCONNECTED);

    expect_any(accounts_get_account, name);
    will_return(accounts_get_account, account);

    expect_cons_show("Connecting with account jabber_org as me@jabber.org");

    expect_memory(jabber_connect_with_account, account, account, sizeof(account));
    will_return(jabber_connect_with_account, JABBER_CONNECTING);

    gboolean result = cmd_connect(NULL, CMD_CONNECT, args);
    assert_true(result);
}