polybar/tests/CMakeLists.txt

79 lines
2.3 KiB
CMake
Raw Normal View History

# Download and unpack googletest at configure time {{{
configure_file(
CMakeLists.txt.in
${CMAKE_BINARY_DIR}/googletest-download/CMakeLists.txt
)
execute_process( COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" .
RESULT_VARIABLE result
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/googletest-download)
if(result)
message(FATAL_ERROR "CMake step for googletest failed: ${result}")
endif()
execute_process(COMMAND ${CMAKE_COMMAND} --build .
RESULT_VARIABLE result
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/googletest-download )
if(result)
message(FATAL_ERROR "Build step for googletest failed: ${result}")
endif()
# Add googletest directly to our build. This defines
# the gtest, gtest_main, gmock and gmock_main targets.
add_subdirectory(${CMAKE_BINARY_DIR}/googletest-src
${CMAKE_BINARY_DIR}/googletest-build
EXCLUDE_FROM_ALL)
# }}}
# Compile all unit tests with 'make all_unit_tests'
add_custom_target(all_unit_tests
COMMENT "Building all unit test")
function(add_unit_test source_file)
string(REPLACE "/" "_" testname ${source_file})
set(name "unit_test.${testname}")
add_executable(${name} unit_tests/${source_file}.cpp)
get_include_dirs(includes_dir)
target_include_directories(${name} PRIVATE ${includes_dir} ${CMAKE_CURRENT_LIST_DIR})
# Link against gmock (this automatically links against gtest)
target_link_libraries(${name} poly gmock_main)
add_test(NAME ${name} COMMAND ${name})
add_dependencies(all_unit_tests ${name})
2016-10-24 23:47:00 +00:00
endfunction()
2016-06-15 03:32:35 +00:00
2020-05-31 14:28:31 +00:00
add_unit_test(utils/actions)
add_unit_test(utils/action_router)
add_unit_test(utils/color)
2019-03-07 06:42:10 +00:00
add_unit_test(utils/command)
2021-09-21 19:23:05 +00:00
add_unit_test(utils/env)
add_unit_test(utils/math)
add_unit_test(utils/scope)
add_unit_test(utils/string)
add_unit_test(utils/file)
add_unit_test(utils/process)
Add units support (POINT, PIXEL, SPACE) (#2578) * add units support (POINT, PIXEL, SPACE) for polybar - add a size_with_unit struct - add a geometry_format_values struct - move dpi initialisation from renderer.cpp to bar.cpp - add a string to size_with_unit converter - add point support (with pt) - add pixel support (with px) * Fix unit test compilation * clang-format * Better names The old names didn't really capture the purpose of the structs and function. space_type -> spacing_type space_size -> spacing_val size_type -> extent_type geometry -> extent_val geometry_format_values -> percentage_with_offset * Remove parse_size_with_unit No longer needed. The convert<spacing_val> function in config.cpp already does all the work for us and always setting the type to pixel was wrong. In addition, line-size should not be of type spacing_val but extent_val. * Cleanup I tried to address most of my comments on the old PR * Fix renderer width calculation We can't just blindly add the x difference to the width because for example the width should increase if x < width and the increase keeps x < width. Similarly, we can't just add the offset to the width. * Rename geom_format_to_pixels to percentage_with_offset_to_pixel * Cleanup * Apply suggested changes from Patrick on GitHub Co-authored-by: Patrick Ziegler <p.ziegler96@gmail.com> * Update src/components/bar.cpp Co-authored-by: Patrick Ziegler <p.ziegler96@gmail.com> * Update src/components/config.cpp Co-authored-by: Patrick Ziegler <p.ziegler96@gmail.com> * Update src/components/builder.cpp Co-authored-by: Patrick Ziegler <p.ziegler96@gmail.com> * Update src/components/builder.cpp Co-authored-by: Patrick Ziegler <p.ziegler96@gmail.com> * config: Use stod for parsing percentage * Use stof instead of strtof * units: Fix test edge cases * Remove unnecessary clang-format toggle * Use percentage_with_offset for margin-{top,bottom} * Support negative extent values * Rename unit to units and create a cpp file * Move percentage_with_offset_to_pixel unit test to units * Add unit tests for units_utils * Clarify when and how negative spacing/extent is allowed Negative spacing is never allowed and produces a config error. Extents allow negative values in theory, but only a few use-cases accept it. Only the extent value used for the `%{O}` tag and the offset value in percentage_with_offset can be negative. Everything else is capped below at 0. The final pixel value of percentage_with_offset also caps below at 0. * Fix parsing errors not being caught in config * Print a proper error message for uncaught exceptions * Cleanup module::get_output All changes preserve the existing semantics * Stop using remove_trailing_space in module::get_output Instead, we first check if the current tag is built, and only if it is, the spacing is prepended. * Remove unused imports * Restore old behavior If there are two tags and the second one isn't built (module::build returns false), the space in between them is removed. For example in the mpd module: format-online = <toggle> <label-song> foo If mpd is not running, the mpd module will return false when trying to build the `<label-song>` tag. If we don't remove the space between `<toggle>` and `<label-song>`, we end up with two spaces between `<toggle>` and `foo`. This change is to match the old behavior where at least one trailing space character was removed from the builder. * Add changelog entry * Remove unused setting * Use percentage with offset for tray-offset Co-authored-by: Jérôme BOULMIER <jerome.boulmier@outlook.fr> Co-authored-by: Joe Groocock <github@frebib.net>
2022-02-20 20:08:57 +00:00
add_unit_test(utils/units)
add_unit_test(components/builder)
add_unit_test(components/command_line)
config_parser: Introduce stricter syntax conventions (#1377) This is the next step to merge #1237 in stages. Currently there are barely any restrictions on how the config can be written. This causes things like config files with DOS line endings to not be parsed properly (#1366) because polybar splits by `\n` and when parsing section headers, it can't deal with the `\r` at the end of the line and thus doesn't recognize any section headers. With this PR we introduce some rules as to what characters are allowed in section names and keys. Note: When talking about spaces I refer to any character for which `isspace()` returns `true`. The rules are as follows: * A section name or a key name cannot contain any spaces as well as any of there characters:`"'=;#[](){}:.$\%` * Spaces at the beginning and end of lines are always ignored when parsing * Comment lines start with `;` or `#` and last for the whole line. The whole line will be ignored by the parser. You cannot start a comment at the end of a line. * Section headers have the following form `[HEADER_NAME]` * Key-value lines look like this: `KEY_NAME{SPACES}={SPACES}VALUE_STRING` where `{SPACES}` represents any number of spaces. `VALUE_STRING` can contain any characters. If it is *surrounded* with double quotes (`"`), those quotes will be removed, this can be used to add spaces to the beginning or end of the value * Empty lines are lines with only spaces in them * If the line has any other form, it is a syntax error This will introduce the following breaking changes because of how underdefined the config syntax was before: * `key = ""` will get treated as an empty string instead of the literal * string `""` * Any section or key name with forbidden characters will now be syntax errors. * Certain strings will be forbidden as section names: `self`, `root`, * `BAR`. Because they have a special meaning inside references and so a * section `[root]` can never be referenced. This replaces the current parser implementation with a new more robust one that will later be expanded to also check for dependency cycles and allow for values that contain references mixed with other strings. This PR also now expands the config paths given over the command line so that `--config=~/.config/polybar/config` resolves properly. Closes #1032 Closes #1694 * config_parser: Add skeleton with tests First step in the config_parser develoment. Only tests functions that are easily testable without many outside dependencies. Integration tests will follow. * config_parser: Implement parse_header * config_parser: Implement get_line_type * feat(string): Add trim functions with predicate Not only trimming based on single character matching but based on a freely specifiable predicate. Will be used to trim all spaces (based on isspace) * config_parser: Implement parse_key * config_parser: Implement parse_line for valid lines * config_parser: Throw exception on invalid lines * config_parser: Remove line_no and file_index from parse_line Cleaner to let the caller catch and fill in the line number and file path * string: Clear up misleading description of trim Before, trim would remove all characters that *didn't* match the predicate and thus the predicate isspace wouldn't work correctly. But because we used the inverse (isnospace_pred) it all worked out, but if the function was used with any other function, it wouldn't have given the desired output * config_parser: Implement parse_file * config_parser: Switch operation to config_parser This changes the way the config is invoked. Now main.cpp creates a config_parser object which then returns the singleton config object from the parse method. Subsequent calls to config::make will return the already created config object as before The config_parser does not yet have all the functionality of the old parser: `inherit` directives are not yet resolved. Other than that all the old functionality is implemented (creating sectionmap and applying include-file) Any sort of dependency detection (except for include-file) are still missing * config: Move xrm initialization to constructor config_parser handles the detection of xrdb references and passes that info to the config object. This finally allows us to delete the config::parse_file function because everything in it has been implemented (except for xrdb detection and file error handling) * refactor(config_parser): Cleanup * config_parser: Set config data after initialization Looks much cleaner this way * config_parser: Expand include-file paths * config_parser: Init xrm if the config uses %{xrdb references * config_parser: Use same type of maps as in old impl Polybar has some weird, not yet fixed, inheriting behaviour and it changes depending on the order in which the config stores its data. Using the same type of maps ensures that the behaviour stays the same. * refactor(config_parser): Clearer invalid name error message * config_parser: Don't allow reserved section names Sections with the names 'self', 'BAR', 'root' could never be referenced because those strings have a special meaning inside references * config_parser: Handle inherit directives This uses the old copy_inherited function, so this still suffers from crashes if there are cyclic dependencies. This also fixes the behaviour where any key that starts with 'inherit' would be treated as an inherit directive * config_parser: Clearer dependency cycle error message * refactor(config_parser): Handle file errors when parsing This removes the need to check if the file exists separately * fix(config): expand config file path Now paths using ~ and environment variables can be used as the config path * fix(config): Properly recognize xrdb references * config_parser: Make messages more informative * doc(config): Improve commenting Comments now describe what the config_parser actually does instead of what it will do. We also now follow the rule that single line comments inside functions should use `//` comments * refactor: Move else on same line as curly braces * fix(config_parser): Don't duplicate paths in `files` * refactor(config_parser): Use else if for clarity * fix(config): Undefined behavior in syntax_error Before the custom what() method produced undefined behavior because the returned string became invalid once the function returned. * refactor(config): descriptive name for useless lines is_valid could easily be confused as meaning syntactically invalid without it being clarified in a comment * refactor(config): Use separate strings instead of key_value Takes just as much space and is much better to read * fix(config_parser): TestCase -> TestSuite and fix macro call Ref: #1644 * config_parser: use const string& in method args * config_parser: Improve comments * config_parser: Incorporate review comments
2019-08-06 17:41:31 +00:00
add_unit_test(components/config_parser)
add_unit_test(drawtypes/label)
add_unit_test(drawtypes/ramp)
add_unit_test(drawtypes/iconset)
add_unit_test(drawtypes/layouticonset)
Use sockets for IPC (#2539) Deprecates not using `polybar-msg` for IPC. Fixes #2532 Closes #2465 Fixes #2504 * Create FIFO specific NamedPipeHandle subclass to PipeHandle * Prototype SocketHandle * Move mainloop up to main.cpp * Pass eventloop to ipc class * Deprecate sending ipc over the named pipe Unfortunately, we can only show the warning in the polybar log and not give the user any feedback because the pipe is one-way * Move eventloop into its own namespace * Prototype ipc socket handling * Remove handles from ipc_client Should be independent from eventloop logic * Remove ipc clients when finished * Add tests for ipc_client decoding * Add callback for complete ipc messages * Remove template param from mixins * Move signal handler to new callback system * Move poll handle to new callback system * Move FSEventHandle to new callback system * Move TimerHandle and AsyncHandle to new callback system * Move PipeHandle to new callback system * Implement socket functionality in new callback system * Correctly reset ipc named pipe handle * Let client close handles in error callback * Wrap client pipe and ipc::client in connection class * Better decoder log messages * Socket path logic * Fix CI warnings * Remove UVHandleGeneric * Fix error when socket folder already exists * Proof of concept message writeback * Restructure ipc files * polybar-msg: Use sockets * polybar-msg: Better syntax for actions * Fix memory leak with fifo After EOF, the pipe wasn't closed and EOF was called all the time, each time allocating a new pipe. * Make polybar-msg compile on its own * Rudimentary writeback for polybar-msg * Fix payload reference going out of scope. * Add IPC documentation * Cleanup polybar-msg code * Specify the v0 ipc message format * Close ipc connection after message * Fix ipc tests * Properly close ipc connections * Fix polybar-msg not working with action string * Write polybar-msg manpage * polybar-msg: Stop using exit() * ipc: Print log message with PID * Add tests for ipc util * polybar-msg: Print PID with success message * ipc: Propagate message errors * Rename ipc::client to ipc::decoder * Rename ipc.cpp to polybar-msg.cpp * ipc: Write encoder function and fix decoder bugs * ipc: Use message format for responses * ipc: Handle wrong message types * ipc: Write back error message if ipc message cannot be processed This only happens for commands and empty actions. Non-empty actions are not immediately executed, but deferred until the next loop iteration. * Remove TODO about deleting runtime directory The socket file is not deleted after socket.close() is called, only after libuv executes the close callback. So we can't just call rmdir because it will probably always fail. * CLeanup WriteRequest * Update manpage authors * Cleanup
2022-01-22 19:35:37 +00:00
add_unit_test(ipc/decoder)
add_unit_test(ipc/encoder)
add_unit_test(ipc/util)
add_unit_test(tags/parser)
2021-01-14 09:25:37 +00:00
add_unit_test(tags/dispatch)
2021-01-16 12:13:13 +00:00
add_unit_test(tags/action_context)
# Run make check to build and run all unit tests
add_custom_target(check
COMMAND GTEST_COLOR=1 ctest --output-on-failure
DEPENDS all_unit_tests
)