From 3fab9adab68c2b27a2a5dd17ca4524a59070f1ca Mon Sep 17 00:00:00 2001 From: Johannes Altmanninger Date: Sat, 9 Dec 2023 19:14:42 +0100 Subject: [PATCH] Port test_illegal_command_exit_code --- fish-rust/src/tests/parser.rs | 31 +++++++++++++++++++++++++++ src/fish_tests.cpp | 40 ----------------------------------- 2 files changed, 31 insertions(+), 40 deletions(-) diff --git a/fish-rust/src/tests/parser.rs b/fish-rust/src/tests/parser.rs index 4ce4dad8e..0433a560a 100644 --- a/fish-rust/src/tests/parser.rs +++ b/fish-rust/src/tests/parser.rs @@ -1,4 +1,5 @@ use crate::ast::{Ast, List, Node}; +use crate::builtins::shared::{STATUS_CMD_OK, STATUS_UNMATCHED_WILDCARD}; use crate::expand::ExpandFlags; use crate::io::{IoBufferfill, IoChain}; use crate::parse_constants::{ParseTreeFlags, ParserTestErrorBits}; @@ -6,6 +7,7 @@ use crate::parser::Parser; use crate::reader::reader_reset_interrupted; use crate::signal::{signal_clear_cancel, signal_reset_handlers, signal_set_handlers}; +use crate::tests::prelude::*; use crate::threads::{iothread_drain_all, iothread_perform}; use crate::wchar::prelude::*; use libc::SIGINT; @@ -309,6 +311,35 @@ fn detect_argument_errors(src: &str) -> Result<(), ParserTestErrorBits> { ); }); +add_test!("test_eval_illegal_exit_code", || { + macro_rules! validate { + ($cmd:expr, $result:expr) => { + let parser = Parser::principal_parser(); + parser.eval($cmd, &IoChain::new()); + let exit_status = parser.get_last_status(); + assert_eq!(exit_status, parser.get_last_status()); + }; + } + + // We need to be in an empty directory so that none of the wildcards match a file that might be + // in the fish source tree. In particular we need to ensure that "?" doesn't match a file + // named by a single character. See issue #3852. + pushd("test/temp"); + validate!(L!("echo -n"), STATUS_CMD_OK.unwrap()); + validate!(L!("pwd"), STATUS_CMD_OK.unwrap()); + validate!( + L!("UNMATCHABLE_WILDCARD*"), + STATUS_UNMATCHED_WILDCARD.unwrap() + ); + validate!( + L!("UNMATCHABLE_WILDCARD**"), + STATUS_UNMATCHED_WILDCARD.unwrap() + ); + validate!(L!("?"), STATUS_UNMATCHED_WILDCARD.unwrap()); + validate!(L!("abc?def"), STATUS_UNMATCHED_WILDCARD.unwrap()); + popd(); +}); + add_test!("test_eval_empty_function_name", || { let parser = Parser::principal_parser().shared(); parser.eval( diff --git a/src/fish_tests.cpp b/src/fish_tests.cpp index 30d287085..5f817e0c1 100644 --- a/src/fish_tests.cpp +++ b/src/fish_tests.cpp @@ -1597,45 +1597,6 @@ static void test_env_snapshot() { popd(); } -// todo!("port this") -static void test_illegal_command_exit_code() { - say(L"Testing illegal command exit code"); - - // We need to be in an empty directory so that none of the wildcards match a file that might be - // in the fish source tree. In particular we need to ensure that "?" doesn't match a file - // named by a single character. See issue #3852. - if (!pushd("test/temp")) return; - - struct command_result_tuple_t { - const wchar_t *txt; - int result; - }; - - const command_result_tuple_t tests[] = { - {L"echo -n", STATUS_CMD_OK}, - {L"pwd", STATUS_CMD_OK}, - {L"UNMATCHABLE_WILDCARD*", STATUS_UNMATCHED_WILDCARD}, - {L"UNMATCHABLE_WILDCARD**", STATUS_UNMATCHED_WILDCARD}, - {L"?", STATUS_UNMATCHED_WILDCARD}, - {L"abc?def", STATUS_UNMATCHED_WILDCARD}, - }; - - auto empty_ios = new_io_chain(); - const parser_t &parser = parser_principal_parser()->deref(); - - for (const auto &test : tests) { - parser.eval(test.txt, *empty_ios); - - int exit_status = parser.get_last_status(); - if (exit_status != test.result) { - err(L"command '%ls': expected exit code %d, got %d", test.txt, test.result, - exit_status); - } - } - - popd(); -} - // todo!("no need to port, delete this") void test_maybe() { say(L"Testing maybe_t"); @@ -1863,7 +1824,6 @@ static const test_t s_tests[]{ {TEST_GROUP("colors"), test_colors}, {TEST_GROUP("input"), test_input}, {TEST_GROUP("completion_insertions"), test_completion_insertions}, - {TEST_GROUP("illegal_command_exit_code"), test_illegal_command_exit_code}, {TEST_GROUP("maybe"), test_maybe}, {TEST_GROUP("normalize"), test_normalize_path}, {TEST_GROUP("dirname"), test_dirname_basename},