Skip to content

Commit

Permalink
Improve test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
randstr committed Oct 1, 2016
1 parent 45a7439 commit a808ea0
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 4 deletions.
36 changes: 34 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -80,5 +80,37 @@ target_link_libraries(editorconfig_core
configure_file(editorconfig.lua.in editorconfig.lua)

enable_testing()
set(EDITORCONFIG_CMD ${LUA_CMD} ${CMAKE_BINARY_DIR}/editorconfig.lua)
add_subdirectory(tests)
set(EDITORCONFIG_CMD_OPEN ${LUA_CMD} ${CMAKE_BINARY_DIR}/editorconfig.lua --open)
set(EDITORCONFIG_CMD_PARSE ${LUA_CMD} ${CMAKE_BINARY_DIR}/editorconfig.lua --parse)

#
# Functions from tests/CMakeLists.txt
#
## The most common test function
function(new_ec_test name ec_file src_file regex)
add_test(${name}-open ${EDITORCONFIG_CMD_OPEN} -f ${ec_file}
"${CMAKE_CURRENT_SOURCE_DIR}/${src_file}")
add_test(${name}-parse ${EDITORCONFIG_CMD_PARSE} -f ${ec_file}
"${CMAKE_CURRENT_SOURCE_DIR}/${src_file}")
set_tests_properties(${name}-open ${name}-parse PROPERTIES PASS_REGULAR_EXPRESSION "${regex}")
endfunction()
## The tests that requires version specified
function(new_ec_test_version name ec_file src_file regex version)
add_test(${name}-open ${EDITORCONFIG_CMD_OPEN} -b ${version} -f ${ec_file}
"${CMAKE_CURRENT_SOURCE_DIR}/${src_file}")
add_test(${name}-parse ${EDITORCONFIG_CMD_PARSE} -b ${version} -f ${ec_file}
"${CMAKE_CURRENT_SOURCE_DIR}/${src_file}")
set_tests_properties(${name}-open ${name}-parse PROPERTIES PASS_REGULAR_EXPRESSION "${regex}")
endfunction()
## The tests that requires the full path EditorConfig files
function(new_ec_test_full_ec_file_path name ec_file src_file regex)
add_test(${name}-open ${EDITORCONFIG_CMD_OPEN} -f ${ec_file} "${src_file}")
add_test(${name}-parse ${EDITORCONFIG_CMD_PARSE} -f ${ec_file} "${src_file}")
set_tests_properties(${name}-open ${name}-parse PROPERTIES PASS_REGULAR_EXPRESSION "${regex}")
endfunction()

add_subdirectory(tests/glob)
add_subdirectory(tests/properties)
add_subdirectory(tests/parser)
add_subdirectory(tests/filetree)
#add_subdirectory(tests/cli)
11 changes: 9 additions & 2 deletions editorconfig.lua.in
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,15 @@ local function run_editorconfig(path, show_header)
if show_header then
utils.printf("[%s]\n", path)
end
for k, v in ec.open(path, flags.f, flags.b) do
utils.printf("%s=%s\n", k, v)
if flags.open then
for k, v in ec.open(path, flags.f, flags.b) do
utils.printf("%s=%s\n", k, v)
end
else
local props, names = ec.parse(path, flags.f, flags.b)
for _, k in ipairs(names) do
utils.printf("%s=%s\n", k, props[k])
end
end
end

Expand Down

0 comments on commit a808ea0

Please sign in to comment.