forked from ElementsProject/lightning
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cli: remove formatting hint correclty when it's not the last element.
I noticed that the 'lightning-cli summary' output was wrong. Signed-off-by: Rusty Russell <[email protected]>
- Loading branch information
1 parent
69b02e2
commit 0f5036d
Showing
2 changed files
with
115 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
#include "config.h" | ||
#include <assert.h> | ||
#include <common/amount.h> | ||
#include <common/bigsize.h> | ||
#include <fcntl.h> | ||
#include <stdio.h> | ||
#include <sys/socket.h> | ||
#include <sys/stat.h> | ||
#include <sys/types.h> | ||
#include <unistd.h> | ||
|
||
int test_main(int argc, char *argv[]); | ||
ssize_t test_read(int fd, void *buf, size_t len); | ||
int test_socket(int domain, int type, int protocol); | ||
int test_connect(int sockfd, const struct sockaddr *addr, | ||
socklen_t addrlen); | ||
int test_getpid(void); | ||
int test_printf(const char *format, ...); | ||
int test_fputc(int c, FILE *stream); | ||
|
||
#define main test_main | ||
#define read test_read | ||
#define socket test_socket | ||
#define connect test_connect | ||
#define getpid test_getpid | ||
#define printf test_printf | ||
#define fputc test_fputc | ||
|
||
#include "../lightning-cli.c" | ||
#undef main | ||
|
||
/* AUTOGENERATED MOCKS START */ | ||
/* Generated stub for bigsize_get */ | ||
size_t bigsize_get(const u8 *p UNNEEDED, size_t max UNNEEDED, bigsize_t *val UNNEEDED) | ||
{ fprintf(stderr, "bigsize_get called!\n"); abort(); } | ||
/* Generated stub for bigsize_put */ | ||
size_t bigsize_put(u8 buf[BIGSIZE_MAX_LEN] UNNEEDED, bigsize_t v UNNEEDED) | ||
{ fprintf(stderr, "bigsize_put called!\n"); abort(); } | ||
/* Generated stub for version_and_exit */ | ||
char *version_and_exit(const void *unused UNNEEDED) | ||
{ fprintf(stderr, "version_and_exit called!\n"); abort(); } | ||
/* AUTOGENERATED MOCKS END */ | ||
|
||
int test_socket(int domain UNUSED, int type UNUSED, int protocol UNUSED) | ||
{ | ||
/* We give a real fd, as it writes to it */ | ||
return open("/dev/null", O_WRONLY); | ||
} | ||
|
||
int test_connect(int sockfd UNUSED, const struct sockaddr *addr UNUSED, | ||
socklen_t addrlen UNUSED) | ||
{ | ||
return 0; | ||
} | ||
|
||
int test_getpid(void) | ||
{ | ||
return 9999; | ||
} | ||
|
||
static char *response = "{\"id\": \"lightning-cli-9999\", \"jsonrpc\": \"2.0\", \"result\": {\"channels\": [\"\n\", \"├477308sat OUT/OURS ┼ IN/THEIRS 477308sat┤ SCID FLAG ALIAS\", \"├──────────────────────┼──────────────────────┤ 580612x1826x0 [__] BLUEIRON-v0.7.2rc1\"], \"my_address\": \"02b78caed0f45120acc48efe867aa506e8ea60f0712a23303178471da0ca2213f5@hdco6sxkbisc7s5t.onion\", \"format-hint\": \"simple\", \"avail_in\": \"0.00477308500btc (USD $54.37)\", \"num_utxos\": 0, \"num_gossipers\": 1, \"channels_flags\": \"P:private O:offline\", \"avail_out\": \"0.00477308500btc (USD $54.37)\", \"utxo_amount\": \"0.00000000btc (USD $0.00)\", \"num_channels\": 1, \"num_connected\": 1}}\n\n"; | ||
static size_t response_off; | ||
|
||
ssize_t test_read(int fd UNUSED, void *buf, size_t len) | ||
{ | ||
if (len > strlen(response + response_off)) | ||
len = strlen(response + response_off); | ||
memcpy(buf, response + response_off, len); | ||
return len; | ||
} | ||
|
||
static char *output; | ||
|
||
int test_printf(const char *fmt, ...) | ||
{ | ||
va_list ap; | ||
|
||
va_start(ap, fmt); | ||
tal_append_vfmt(&output, fmt, ap); | ||
va_end(ap); | ||
return 1; | ||
} | ||
|
||
int test_fputc(int c, FILE *stream) | ||
{ | ||
tal_append_fmt(&output, "%c", c); | ||
return (unsigned)c; | ||
} | ||
|
||
int main(int argc UNUSED, char *argv[]) | ||
{ | ||
setup_locale(); | ||
|
||
char *fake_argv[] = { argv[0], "--lightning-dir=/tmp/", "test", NULL }; | ||
|
||
output = tal_strdup(NULL, ""); | ||
assert(test_main(3, fake_argv) == 0); | ||
|
||
assert(streq(output, "channels=\n" | ||
"\n" | ||
"├477308sat OUT/OURS ┼ IN/THEIRS 477308sat┤ SCID FLAG ALIAS\n" | ||
"├──────────────────────┼──────────────────────┤ 580612x1826x0 [__] BLUEIRON-v0.7.2rc1\n" | ||
"my_address=02b78caed0f45120acc48efe867aa506e8ea60f0712a23303178471da0ca2213f5@hdco6sxkbisc7s5t.onion\n" | ||
"avail_in=0.00477308500btc (USD $54.37)\n" | ||
"num_utxos=0\n" | ||
"num_gossipers=1\n" | ||
"channels_flags=P:private O:offline\n" | ||
"avail_out=0.00477308500btc (USD $54.37)\n" | ||
"utxo_amount=0.00000000btc (USD $0.00)\n" | ||
"num_channels=1\n" | ||
"num_connected=1\n")); | ||
tal_free(output); | ||
return 0; | ||
} |