Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ versioning for release tags.

### Fixed

- Allow `host-env get` to read a variable without treating its absent value
argument as invalid input.
- Filter unsupported OSC terminal control sequences from `host-shell` output
without corrupting UTF-8 text.
- Keep the `host-shell` login wrapper within the HostShell command trap limit.
Expand Down
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# SPDX-License-Identifier: GPL-3.0-or-later

TOOLS = host-run host-multiview host-shell host-path host-reveal host-notify host-edit host-clip host-info host-download host-env
TEST_BINS = tests/test_host_common.out tests/test_host_command_builders.out tests/test_host_edit_command.out tests/test_host_download_command.out tests/test_host_terminal_filter.out
TEST_BINS = tests/test_host_common.out tests/test_host_command_builders.out tests/test_host_edit_command.out tests/test_host_download_command.out tests/test_host_terminal_filter.out tests/test_host_env_cli.out
TEST_SCRIPTS = tests/test_package_layout.sh tests/test_ahi_driver_source.sh tests/test_runtime_source.sh
include version.mk
COMMON_HEADERS = src/host_common.h src/host_path.h src/host_capture.h src/host_base64.h src/host_clip_command.h src/host_download_command.h src/host_edit_command.h src/host_env_command.h src/host_info_command.h src/host_notify_command.h src/host_powershell.h src/host_reveal_command.h src/host_shell_command.h src/uae_pragmas.h
Expand Down Expand Up @@ -128,6 +128,9 @@ tests/test_host_download_command.out: tests/test_host_download_command.c src/hos
tests/test_host_terminal_filter.out: tests/test_host_terminal_filter.c src/host_terminal_filter.h
$(HOST_CC) $(HOST_NATIVE_FLAGS) $(HOST_CFLAGS) tests/test_host_terminal_filter.c -o $@

tests/test_host_env_cli.out: tests/test_host_env_cli.c src/host-env.c src/host_env_command.h src/host_common.h src/host_powershell.h
$(HOST_CC) $(HOST_NATIVE_FLAGS) $(HOST_CFLAGS) $(VERFLAGS) tests/test_host_env_cli.c -o $@

debug: CFLAGS += -DDEBUG -g
debug: clean all

Expand Down
4 changes: 0 additions & 4 deletions src/host-env.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,6 @@ int main(int argc, char *argv[])
if (!require_name(argv[2])) {
return HOST_RETURN_ERROR;
}
if (!host_env_valid_value(argv[3])) {
printf("Environment variable values cannot contain line breaks\n");
return HOST_RETURN_ERROR;
}
if (windows) {
if (!host_append_env_get_command_windows(command, sizeof(command), argv[2])) {
printf("Command is too long\n");
Expand Down
71 changes: 71 additions & 0 deletions tests/test_host_env_cli.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* SPDX-FileCopyrightText: 2020-2026 Dimitris Panokostas
* SPDX-License-Identifier: GPL-3.0-or-later
*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define HOST_PLATFORM_POSIX 1
#define HOST_PLATFORM_WINDOWS 3

static const char *captured_command;

static int InitUAEResource(void)
{
return 1;
}

static int GetHostPlatform(void)
{
return HOST_PLATFORM_POSIX;
}

static int host_print_command_output(const char *command)
{
captured_command = command;
return 0;
}

#define HOST_CAPTURE_H
#define main host_env_main
#include "../src/host-env.c"
#undef main

static void require(int condition, const char *message)
{
if (!condition) {
fprintf(stderr, "%s\n", message);
exit(1);
}
}

static void test_get_dispatch(void)
{
char *argv[] = { "host-env", "get", "HOST_TOOLS_TEST", NULL };

captured_command = NULL;
require(host_env_main(3, argv) == 0, "get should dispatch successfully");
require(captured_command != NULL, "get should execute a host command");
require(strstr(captured_command, "HOST_TOOLS_TEST") != NULL,
"get command should contain the requested variable name");
}

static void test_set_dispatch(void)
{
char *argv[] = { "host-env", "set", "HOST_TOOLS_TEST", "value with spaces", NULL };

captured_command = NULL;
require(host_env_main(4, argv) == 0, "set should dispatch successfully");
require(captured_command != NULL, "set should execute a host command");
require(strstr(captured_command, "value with spaces") != NULL,
"set command should contain the requested value");
}

int main(void)
{
test_get_dispatch();
test_set_dispatch();
return 0;
}