mirror of
https://github.com/fish-shell/fish-shell.git
synced 2025-02-21 05:17:08 +08:00
Port test_illegal_command_exit_code
This commit is contained in:
parent
c74cc71e26
commit
3fab9adab6
@ -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::parse_util::{parse_util_detect_errors, parse_util_detect_errors_in_ar
|
||||
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 @@ add_test!("test_eval_recursion_detection", || {
|
||||
);
|
||||
});
|
||||
|
||||
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(
|
||||
|
@ -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},
|
||||
|
Loading…
x
Reference in New Issue
Block a user