Add fish_test_helper executable

In tests we would like to arrange for an executable to invoke certain
system calls, e.g. to claim or relinquish control of the terminal. This is
annoying to do portably via e.g. perl. fish_test_helper is a little
program where we can add custom commands to make it act in certain ways.
This commit is contained in:
ridiculousfish 2019-04-06 22:22:11 -07:00
parent 4d66c7896f
commit 23d88e0e03
3 changed files with 39 additions and 1 deletions

View file

@ -162,6 +162,9 @@ ADD_EXECUTABLE(fish_key_reader
src/fish_key_reader.cpp src/print_help.cpp)
FISH_LINK_DEPS(fish_key_reader)
# A helper for running tests.
ADD_EXECUTABLE(fish_test_helper src/fish_test_helper.cpp)
# Set up tests.
INCLUDE(cmake/Tests.cmake)

View file

@ -44,14 +44,17 @@ ADD_DEPENDENCIES(test test_low_level tests_dir)
# Make the directory in which to run tests.
# Also symlink fish to where the tests expect it to be.
# Lastly put fish_test_helper there too.
ADD_CUSTOM_TARGET(tests_buildroot_target
COMMAND ${CMAKE_COMMAND} -E make_directory ${TEST_INSTALL_DIR}
COMMAND DESTDIR=${TEST_INSTALL_DIR} ${CMAKE_COMMAND}
--build ${CMAKE_CURRENT_BINARY_DIR} --target install
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_BINARY_DIR}/fish_test_helper
${TEST_INSTALL_DIR}/${CMAKE_INSTALL_PREFIX}/bin
COMMAND ${CMAKE_COMMAND} -E create_symlink
${TEST_INSTALL_DIR}/${CMAKE_INSTALL_PREFIX}
${TEST_ROOT_DIR}
DEPENDS fish)
DEPENDS fish fish_test_helper)
IF(NOT FISH_IN_TREE_BUILD)
# We need to symlink share/functions for the tests.

32
src/fish_test_helper.cpp Normal file
View file

@ -0,0 +1,32 @@
// fish_test_helper is a little program with no fish dependencies that acts like certain other
// programs, allowing fish to test its behavior.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
static void become_foreground_then_print_stderr() {
if (tcsetpgrp(STDOUT_FILENO, getpgrp()) < 0) {
perror("tcsetgrp");
exit(EXIT_FAILURE);
}
usleep(1000000 / 4); //.25 secs
fprintf(stderr, "become_foreground_then_print_stderr done\n");
}
int main(int argc, char *argv[]) {
if (argc <= 1) {
fprintf(stderr, "No commands given.");
return 0;
}
for (int i = 1; i < argc; i++) {
if (!strcmp(argv[i], "become_foreground_then_print_stderr")) {
become_foreground_then_print_stderr();
} else {
fprintf(stderr, "%s: Unknown command: %s\n", argv[0], argv[i]);
return EXIT_FAILURE;
}
}
return 0;
}