From 2fdde54121e369a56757eebf8dfe0876f292a62d Mon Sep 17 00:00:00 2001 From: Eugenio Depalo Date: Thu, 15 Oct 2026 11:32:51 +0200 Subject: [PATCH 1/2] cli: Fail YAML validation for missing input ascli_validate_files_format() returns a process status, but its YAML missing-file path returned FALSE and therefore reported success. Return ASCLI_EXIT_CODE_BAD_INPUT, matching text validation. --- tests/meson.build | 13 ++++++ tests/test-cli.c | 82 ++++++++++++++++++++++++++++++++++ tools/ascli-actions-validate.c | 2 +- 3 files changed, 96 insertions(+), 1 deletion(-) create mode 100644 tests/test-cli.c diff --git a/tests/meson.build b/tests/meson.build index a85c80e4e..4608cf804 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -121,6 +121,19 @@ test ('as-test_misc', env: as_test_env ) +# Command-line interface +as_test_cli_exe = executable ('as-test_cli', + ['test-cli.c'], + dependencies: [appstream_dep, + gio_dep], + include_directories: [root_inc_dir] +) +test ('as-test_cli', + as_test_cli_exe, + args: [ascli_exe], + env: as_test_env +) + # AppStream Compose tests if get_option('compose') as_test_compose_exe = executable ('as-test_compose', diff --git a/tests/test-cli.c b/tests/test-cli.c new file mode 100644 index 000000000..e5ffe0498 --- /dev/null +++ b/tests/test-cli.c @@ -0,0 +1,82 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- + * + * Copyright (C) 2026 Eugenio De Palo + * + * Licensed under the GNU Lesser General Public License Version 2.1 + * + * This library is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 2.1 of the license, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library. If not, see . + */ + +#include +#include +#include + +#include "tools/ascli-utils.h" + +static gchar *ascli_path = NULL; + +static gint +run_validate_missing (const gchar *format) +{ + g_autoptr(GError) error = NULL; + g_autoptr(GSubprocess) subprocess = NULL; + g_autofree gchar *tmpdir = NULL; + g_autofree gchar *missing_path = NULL; + const gchar *argv[] = { + ascli_path, "validate", "--no-net", format, NULL, NULL, + }; + gint exit_status; + + tmpdir = g_dir_make_tmp ("appstream-test-cli-XXXXXX", &error); + g_assert_no_error (error); + missing_path = g_build_filename (tmpdir, "missing.metainfo.xml", NULL); + argv[4] = missing_path; + + subprocess = g_subprocess_newv (argv, + G_SUBPROCESS_FLAGS_STDOUT_SILENCE | + G_SUBPROCESS_FLAGS_STDERR_SILENCE, + &error); + g_assert_no_error (error); + g_assert_true (g_subprocess_wait (subprocess, NULL, &error)); + g_assert_no_error (error); + g_assert_true (g_subprocess_get_if_exited (subprocess)); + exit_status = g_subprocess_get_exit_status (subprocess); + g_assert_cmpint (g_rmdir (tmpdir), ==, 0); + + return exit_status; +} + +static void +test_validate_missing (void) +{ + g_assert_cmpint (run_validate_missing ("--format=text"), ==, ASCLI_EXIT_CODE_BAD_INPUT); + g_assert_cmpint (run_validate_missing ("--format=yaml"), ==, ASCLI_EXIT_CODE_BAD_INPUT); +} + +int +main (int argc, char **argv) +{ + int ret; + + setlocale (LC_ALL, ""); + g_assert_cmpint (argc, >=, 2); + ascli_path = g_strdup (argv[1]); + g_test_init (&argc, &argv, NULL); + + g_test_add_func ("/AppStream/CLI/ValidateMissing", test_validate_missing); + + ret = g_test_run (); + g_free (ascli_path); + return ret; +} diff --git a/tools/ascli-actions-validate.c b/tools/ascli-actions-validate.c index e25997972..7fabb2e01 100644 --- a/tools/ascli-actions-validate.c +++ b/tools/ascli-actions-validate.c @@ -511,7 +511,7 @@ ascli_validate_files_format (gchar **argv, if (!g_file_query_exists (file, NULL)) { g_print (_("File '%s' does not exist."), argv[i]); g_print ("\n"); - return FALSE; + return ASCLI_EXIT_CODE_BAD_INPUT; } if (!as_validator_validate_file (validator, file)) From a598ef1b5e448ec5ff572d347939e36c0b706cf2 Mon Sep 17 00:00:00 2001 From: Eugenio Depalo Date: Thu, 15 Oct 2026 19:54:46 +0200 Subject: [PATCH 2/2] cli: Remove unnecessary test --- tests/meson.build | 13 -------- tests/test-cli.c | 82 ----------------------------------------------- 2 files changed, 95 deletions(-) delete mode 100644 tests/test-cli.c diff --git a/tests/meson.build b/tests/meson.build index 4608cf804..a85c80e4e 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -121,19 +121,6 @@ test ('as-test_misc', env: as_test_env ) -# Command-line interface -as_test_cli_exe = executable ('as-test_cli', - ['test-cli.c'], - dependencies: [appstream_dep, - gio_dep], - include_directories: [root_inc_dir] -) -test ('as-test_cli', - as_test_cli_exe, - args: [ascli_exe], - env: as_test_env -) - # AppStream Compose tests if get_option('compose') as_test_compose_exe = executable ('as-test_compose', diff --git a/tests/test-cli.c b/tests/test-cli.c deleted file mode 100644 index e5ffe0498..000000000 --- a/tests/test-cli.c +++ /dev/null @@ -1,82 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- - * - * Copyright (C) 2026 Eugenio De Palo - * - * Licensed under the GNU Lesser General Public License Version 2.1 - * - * This library is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 2.1 of the license, or - * (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library. If not, see . - */ - -#include -#include -#include - -#include "tools/ascli-utils.h" - -static gchar *ascli_path = NULL; - -static gint -run_validate_missing (const gchar *format) -{ - g_autoptr(GError) error = NULL; - g_autoptr(GSubprocess) subprocess = NULL; - g_autofree gchar *tmpdir = NULL; - g_autofree gchar *missing_path = NULL; - const gchar *argv[] = { - ascli_path, "validate", "--no-net", format, NULL, NULL, - }; - gint exit_status; - - tmpdir = g_dir_make_tmp ("appstream-test-cli-XXXXXX", &error); - g_assert_no_error (error); - missing_path = g_build_filename (tmpdir, "missing.metainfo.xml", NULL); - argv[4] = missing_path; - - subprocess = g_subprocess_newv (argv, - G_SUBPROCESS_FLAGS_STDOUT_SILENCE | - G_SUBPROCESS_FLAGS_STDERR_SILENCE, - &error); - g_assert_no_error (error); - g_assert_true (g_subprocess_wait (subprocess, NULL, &error)); - g_assert_no_error (error); - g_assert_true (g_subprocess_get_if_exited (subprocess)); - exit_status = g_subprocess_get_exit_status (subprocess); - g_assert_cmpint (g_rmdir (tmpdir), ==, 0); - - return exit_status; -} - -static void -test_validate_missing (void) -{ - g_assert_cmpint (run_validate_missing ("--format=text"), ==, ASCLI_EXIT_CODE_BAD_INPUT); - g_assert_cmpint (run_validate_missing ("--format=yaml"), ==, ASCLI_EXIT_CODE_BAD_INPUT); -} - -int -main (int argc, char **argv) -{ - int ret; - - setlocale (LC_ALL, ""); - g_assert_cmpint (argc, >=, 2); - ascli_path = g_strdup (argv[1]); - g_test_init (&argc, &argv, NULL); - - g_test_add_func ("/AppStream/CLI/ValidateMissing", test_validate_missing); - - ret = g_test_run (); - g_free (ascli_path); - return ret; -}