diff --git a/Makefile b/Makefile index 38484e63..6e995139 100644 --- a/Makefile +++ b/Makefile @@ -54,7 +54,7 @@ LDFLAGS-os-FreeBSD = -L/usr/local/lib LIBS-os-Haiku = -lnetwork -lbe -CPPFLAGS-os-OpenBSD = -DKAK_BIN_PATH="$(bindir)/kak" -I/usr/local/include +CPPFLAGS-os-OpenBSD = -DKAK_BIN_PATH=\"$(bindir)/kak\" -I/usr/local/include LDFLAGS-os-OpenBSD = -L/usr/local/lib mandir-os-OpenBSD = $(DESTDIR)$(PREFIX)/man/man1 @@ -136,6 +136,9 @@ doc/kak.1.gz: doc/kak.1 check: test test: src/kak + if [ $(os) = OpenBSD ]; then \ + export KAKOUNE_RUNTIME=$$PWD/share/kak; \ + fi && \ cd test && ./run TAGS: tags diff --git a/doc/pages/changelog.asciidoc b/doc/pages/changelog.asciidoc index 4b0857ff..ee5e374f 100644 --- a/doc/pages/changelog.asciidoc +++ b/doc/pages/changelog.asciidoc @@ -3,6 +3,10 @@ This changelog contains major and/or breaking changes to Kakoune between released versions. +== Kakoune 2024.05.18 + +* Fixed tests on Alpine Linux and *BSD + == Kakoune 2024.05.09 * `flag-lines -after` switch to display text after the line diff --git a/rc/tools/git.kak b/rc/tools/git.kak index ac349a97..def591d8 100644 --- a/rc/tools/git.kak +++ b/rc/tools/git.kak @@ -224,7 +224,7 @@ define-command -params 1.. \ execute-keys ^commit } catch %{ # Missing commit line, assume it is an uncommitted change. - execute-keys \A + execute-keys Gg } require-module diff try %{ diff --git a/src/file.cc b/src/file.cc index be298964..ca2d2834 100644 --- a/src/file.cc +++ b/src/file.cc @@ -634,9 +634,10 @@ String get_kak_binary_path() char buffer[2048]; #if defined(__linux__) or defined(__CYGWIN__) or defined(__gnu_hurd__) ssize_t res = readlink("/proc/self/exe", buffer, 2048); - kak_assert(res != -1); - buffer[res] = '\0'; - return buffer; + if (res != -1 && res < 2048) { + buffer[res] = '\0'; + return buffer; + } #elif defined(__FreeBSD__) or defined(__NetBSD__) #if defined(__FreeBSD__) int mib[] = {CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1}; @@ -644,37 +645,44 @@ String get_kak_binary_path() int mib[] = {CTL_KERN, KERN_PROC_ARGS, -1, KERN_PROC_PATHNAME}; #endif size_t res = sizeof(buffer); - sysctl(mib, 4, buffer, &res, NULL, 0); - return buffer; + if (sysctl(mib, 4, buffer, &res, NULL, 0) != -1) + return buffer; #elif defined(__APPLE__) uint32_t bufsize = 2048; - _NSGetExecutablePath(buffer, &bufsize); - char* canonical_path = realpath(buffer, nullptr); - String path = canonical_path; - free(canonical_path); - return path; + char* canonical_path = NULL; + if (_NSGetExecutablePath(buffer, &bufsize) != -1) + canonical_path = realpath(buffer, nullptr); + if (canonical_path) { + String path = canonical_path; + free(canonical_path); + return path; + } #elif defined(__HAIKU__) BApplication app("application/x-vnd.kakoune"); app_info info; - status_t status = app.GetAppInfo(&info); - kak_assert(status == B_OK); - BPath path(&info.ref); - return path.Path(); + if (app.GetAppInfo(&info) == B_OK) { + BPath path(&info.ref); + return path.Path(); + } #elif defined(__DragonFly__) ssize_t res = readlink("/proc/curproc/file", buffer, 2048); - kak_assert(res != -1); - buffer[res] = '\0'; - return buffer; + if (res != -1 && res < 2048) { + buffer[res] = '\0'; + return buffer; + } #elif defined(__OpenBSD__) + (void)buffer; return KAK_BIN_PATH; #elif defined(__sun__) ssize_t res = readlink("/proc/self/path/a.out", buffer, 2048); - kak_assert(res != -1); - buffer[res] = '\0'; - return buffer; + if (res != -1 && res < 2048) { + buffer[res] = '\0'; + return buffer; + } #else # error "finding executable path is not implemented on this platform" #endif + throw runtime_error("unable to get the executable path"); } } diff --git a/src/main.cc b/src/main.cc index 9eb392a6..7a91691b 100644 --- a/src/main.cc +++ b/src/main.cc @@ -45,6 +45,9 @@ struct { unsigned int version; StringView notes; } constexpr version_notes[] = { { + 20240518, + "» Fix tests failing on some platforms\n" + }, { 20240509, "» {+u}flag-lines -after{} highlighter\n" "» asynchronous {+u}shell-script-candidates{} completion\n" diff --git a/src/terminal_ui.cc b/src/terminal_ui.cc index 3ad95e40..52a25e26 100644 --- a/src/terminal_ui.cc +++ b/src/terminal_ui.cc @@ -702,7 +702,7 @@ Optional TerminalUI::get_next_key() static constexpr auto control = [](char c) { return c & 037; }; - static auto convert = [this](Codepoint c) -> Codepoint { + auto convert = [this](Codepoint c) -> Codepoint { if (c == control('m') or c == control('j')) return Key::Return; if (c == control('i')) @@ -717,7 +717,7 @@ Optional TerminalUI::get_next_key() return Key::Escape; return c; }; - static auto parse_key = [](unsigned char c) -> Key { + auto parse_key = [&convert](unsigned char c) -> Key { if (Codepoint cp = convert(c); cp > 255) return Key{cp}; // Special case: you can type NUL with Ctrl-2 or Ctrl-Shift-2 or @@ -756,7 +756,7 @@ Optional TerminalUI::get_next_key() return mod; }; - auto parse_csi = [this]() -> Optional { + auto parse_csi = [this, &convert]() -> Optional { auto next_char = [] { return get_char().value_or((unsigned char)0xff); }; int params[16][4] = {}; auto c = next_char(); diff --git a/test/commands/edit-fifo-noscroll/script b/test/commands/edit-fifo-noscroll/script index f64e1a77..3a719e6a 100644 --- a/test/commands/edit-fifo-noscroll/script +++ b/test/commands/edit-fifo-noscroll/script @@ -1,19 +1,18 @@ -ui_out -ignore 7 +ui_out -until '{ "jsonrpc": "2.0", "method": "refresh", "params": [true] }' exec 5>fifo -ui_out '{ "jsonrpc": "2.0", "method": "refresh", "params": [true] }' echo '* line1' >&5 ui_out '{ "jsonrpc": "2.0", "method": "draw", "params": [[[{ "face": { "fg": "black", "bg": "white", "underline": "default", "attributes": [] }, "contents": "*" }, { "face": { "fg": "default", "bg": "default", "underline": "default", "attributes": [] }, "contents": " line1\u000a" }]], { "fg": "default", "bg": "default", "underline": "default", "attributes": [] }, { "fg": "blue", "bg": "default", "underline": "default", "attributes": [] }] }' -ui_out -ignore 2 +ui_out -until '{ "jsonrpc": "2.0", "method": "refresh", "params": [false] }' echo '* line2' >&5 ui_out '{ "jsonrpc": "2.0", "method": "draw", "params": [[[{ "face": { "fg": "black", "bg": "white", "underline": "default", "attributes": [] }, "contents": "*" }, { "face": { "fg": "default", "bg": "default", "underline": "default", "attributes": [] }, "contents": " line1\u000a" }], [{ "face": { "fg": "default", "bg": "default", "underline": "default", "attributes": [] }, "contents": "* line2\u000a" }]], { "fg": "default", "bg": "default", "underline": "default", "attributes": [] }, { "fg": "blue", "bg": "default", "underline": "default", "attributes": [] }] }' -ui_out -ignore 2 +ui_out -until '{ "jsonrpc": "2.0", "method": "refresh", "params": [false] }' dd if=/dev/zero bs=2049 count=1 2>/dev/null | sed s/././g >&5 -ui_out -ignore 3 +ui_out -until '{ "jsonrpc": "2.0", "method": "refresh", "params": [false] }' ui_in '{ "jsonrpc": "2.0", "method": "keys", "params": [ "gjxH|wc -c | tr -d \" \"" ] }' -ui_out -ignore 6 +ui_out -until '{ "jsonrpc": "2.0", "method": "refresh", "params": [false] }' exec 5>&- -ui_out '{ "jsonrpc": "2.0", "method": "draw_status", "params": [[], [{ "face": { "fg": "default", "bg": "default", "underline": "default", "attributes": [] }, "contents": "*fifo* 3:4 " }, { "face": { "fg": "black", "bg": "yellow", "underline": "default", "attributes": [] }, "contents": "[scratch]" }, { "face": { "fg": "default", "bg": "default", "underline": "default", "attributes": [] }, "contents": " " }, { "face": { "fg": "blue", "bg": "default", "underline": "default", "attributes": [] }, "contents": "1 sel" }, { "face": { "fg": "default", "bg": "default", "underline": "default", "attributes": [] }, "contents": " - client0@[kak-tests]" }], { "fg": "cyan", "bg": "default", "underline": "default", "attributes": [] }] }' +ui_out -until '{ "jsonrpc": "2.0", "method": "draw_status", "params": [[], [{ "face": { "fg": "default", "bg": "default", "underline": "default", "attributes": [] }, "contents": "*fifo* 3:4 " }, { "face": { "fg": "black", "bg": "yellow", "underline": "default", "attributes": [] }, "contents": "[scratch]" }, { "face": { "fg": "default", "bg": "default", "underline": "default", "attributes": [] }, "contents": " " }, { "face": { "fg": "blue", "bg": "default", "underline": "default", "attributes": [] }, "contents": "1 sel" }, { "face": { "fg": "default", "bg": "default", "underline": "default", "attributes": [] }, "contents": " - client0@[kak-tests]" }], { "fg": "cyan", "bg": "default", "underline": "default", "attributes": [] }] }' diff --git a/test/run b/test/run index 95f71a9e..a65f5396 100755 --- a/test/run +++ b/test/run @@ -190,6 +190,12 @@ ui_out() { skip_count=$(( skip_count - 1 )) done ;; + -until) + shift + while read -r event <&4; do + [ "$event" = "$1" ] && break + done + ;; -until-grep) shift while diff --git a/test/tools/git/blame-in-diff/enabled b/test/tools/git/blame-in-diff/enabled index a041a9b4..b5b89081 100755 --- a/test/tools/git/blame-in-diff/enabled +++ b/test/tools/git/blame-in-diff/enabled @@ -1,2 +1,2 @@ #!/bin/sh -command -v git >/dev/null +command -v git >/dev/null && command -v perl >/dev/null diff --git a/test/tools/git/blame-in-diff/script b/test/tools/git/blame-in-diff/script index e5ca34b2..e22b3ec8 100644 --- a/test/tools/git/blame-in-diff/script +++ b/test/tools/git/blame-in-diff/script @@ -1,11 +1,10 @@ -ui_out -ignore 7 -ui_out -ignore 11 +ui_out -until '{ "jsonrpc": "2.0", "method": "refresh", "params": [false] }' # We've jumped to the new version of line 2. Move to the old version so we # can annotate the old file. ui_in '{ "jsonrpc": "2.0", "method": "keys", "params": [ "k:git blame" ] }' -ui_out -ignore 11 +while ui_out -until-grep '"draw_status"' | grep '\[fifo\]'; do :; done > /dev/null # We should have jumped to the old version of line 2, assert on kak_selection. ui_in '{ "jsonrpc": "2.0", "method": "keys", "params": [ "x" ] }' -ui_out -ignore 5 +ui_out -until '{ "jsonrpc": "2.0", "method": "refresh", "params": [false] }' diff --git a/test/tools/git/blame-jump-message/enabled b/test/tools/git/blame-jump-message/enabled index a041a9b4..b5b89081 100755 --- a/test/tools/git/blame-jump-message/enabled +++ b/test/tools/git/blame-jump-message/enabled @@ -1,2 +1,2 @@ #!/bin/sh -command -v git >/dev/null +command -v git >/dev/null && command -v perl >/dev/null diff --git a/test/tools/git/blame-jump-message/script b/test/tools/git/blame-jump-message/script index 67834a40..9f6fb6e0 100644 --- a/test/tools/git/blame-jump-message/script +++ b/test/tools/git/blame-jump-message/script @@ -1,6 +1,5 @@ -while ! ui_out -until-grep draw_status | grep -v '\[fifo\]' >/dev/null; -do - : +while true; do + ui_out -until-grep draw_status | grep -v '\[fifo\]' >/dev/null && break done actual_draw_status=$(ui_out -until-grep draw_status) @@ -11,5 +10,5 @@ EOF expected_subject_json=\"$(printf '%s' "$expected_subject" | sed 's/"/\\"/g')\" expected_draw_status='{ "jsonrpc": "2.0", "method": "draw_status", "params": [[{ "face": { "fg": "black", "bg": "yellow", "underline": "default", "attributes": [] }, "contents": '"$expected_subject_json"' }], [{ "face": { "fg": "default", "bg": "default", "underline": "default", "attributes": [] }, "contents": "*git* 13:2 " }, { "face": { "fg": "black", "bg": "yellow", "underline": "default", "attributes": [] }, "contents": "[scratch]" }, { "face": { "fg": "default", "bg": "default", "underline": "default", "attributes": [] }, "contents": " " }, { "face": { "fg": "blue", "bg": "default", "underline": "default", "attributes": [] }, "contents": "1 sel" }, { "face": { "fg": "default", "bg": "default", "underline": "default", "attributes": [] }, "contents": " - client0@[kak-tests]" }], { "fg": "cyan", "bg": "default", "underline": "default", "attributes": [] }] }' -assert_eq "$actual_draw_status" "$expected_draw_status" +assert_eq "$expected_draw_status" "$actual_draw_status" ui_out -ignore 2