diff --git a/CMakeLists.txt b/CMakeLists.txt index 443a6640b..d7250acd3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/cmake/Tests.cmake b/cmake/Tests.cmake index cab0158e9..7b398744e 100644 --- a/cmake/Tests.cmake +++ b/cmake/Tests.cmake @@ -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. diff --git a/src/fish_test_helper.cpp b/src/fish_test_helper.cpp new file mode 100644 index 000000000..50f3bca7a --- /dev/null +++ b/src/fish_test_helper.cpp @@ -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 +#include +#include +#include + +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; +}