Skip to content

Commit

Permalink
feat: struct refactor
Browse files Browse the repository at this point in the history
chore: cahnge project sturct
fix: nested class tests
feat: add detailed log for parametrized tests
  • Loading branch information
atm1020 committed Jan 5, 2025
1 parent e4dade2 commit 48a6e2c
Show file tree
Hide file tree
Showing 28 changed files with 1,508 additions and 784 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Test

on:
push:
branches:
- "main"
pull_request:

jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
nvim-versions: ["stable", "nightly"]

name: test
steps:
- name: checkout
uses: actions/checkout@v3

- uses: rhysd/action-setup-vim@v1
with:
neovim: true
version: ${{ matrix.nvim-versions }}

- name: run tests
run: make test
13 changes: 7 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
SRC_DIR=lua
TESTS_DIR=tests
TESTS_DIR=./tests
PREPARE_CONFIG=${TESTS_DIR}/prepare-config.lua
TEST_CONFIG=${TESTS_DIR}/minimal_init.lua

.PHONY: test lint format all
.PHONY: test lint format

checks: format lint
checks: format lint test

test:
nvim --headless -c "PlenaryBustedDirectory {minimal_init = '${TEST_CONFIG}'}"
lint:
luacheck ${SRC_DIR}

format:
~/.cargo/bin//stylua ${SRC_DIR} --config-path=.stylua.toml

test:
@nvim --headless --noplugin -u ${TEST_CONFIG} \
-c "PlenaryBustedDirectory ${TESTS_DIR} {minimal_init = '${TEST_CONFIG}'}"
21 changes: 21 additions & 0 deletions lua/neotest-jdtls/junit/common.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
local M = {}

function M.get_short_error_message(result)
if result.actual and result.expected then
return string.format(
'Expected: [%s] but was [%s]',
result.expected[1],
result.actual[1]
)
end
local trace_result = ''
for idx, trace in ipairs(result.trace) do
trace_result = trace_result .. trace
if idx > 3 then
break
end
end
return trace_result
end

return M
87 changes: 87 additions & 0 deletions lua/neotest-jdtls/junit/dynamic_test_result.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
local class = require('neotest-jdtls.utils.class')
local get_short_error_message =
require('neotest-jdtls.junit.common').get_short_error_message
local lib = require('neotest.lib')
local async = require('neotest.async')
local TestStatus = require('neotest-jdtls.types.enums').TestStatus

---@class DynamicTestResult
---@field invocations string[]
---@field nodes java_test.TestResults[]
local DynamicTestResult = class()
function DynamicTestResult:_init()
self.is_dynamic_test = true
self.invocations = {}
self.nodes = {}
self.status = nil
self.errors = {}
self.output = {}
self.all = {}
end

function DynamicTestResult:append_invocation(invocation, node)
assert(invocation)
assert(node)

self.all[invocation] = node
table.insert(self.invocations, invocation)
table.insert(self.nodes, node)
end

function DynamicTestResult:get_neotest_result()
local all = 0
for invocation, node in pairs(self.all) do
all = all + 1
self:append(invocation, node)
end
local results_path = async.fn.tempname()

table.insert(
self.output,
1,
string.format(
'Total invocations: %s\nSuccess: %s\nFailed: %s\n',
all,
all - #self.errors,
#self.errors
)
)
lib.files.write(results_path, table.concat(self.output, '\n'))
return {
status = self.status,
output = results_path,
errors = self.errors,
}
end

function DynamicTestResult:append(invocation, node)
table.insert(
self.output,
string.format(
'\n----------------%s----------------',
node.result.status or TestStatus.Passed
)
)
table.insert(
self.output,
string.format('Invocation %s: %s', invocation, node.display_name)
)
table.insert(self.output, '----------------Output----------------')

if node.result.status == TestStatus.Failed then
local short_message = get_short_error_message(node.result)
self.status = TestStatus.Failed
table.insert(self.errors, { message = short_message })
table.insert(self.output, table.concat(node.result.trace, '\n'))
else
if self.status == nil then
self.status = TestStatus.Passed
end
table.insert(
self.output,
'The console output is available in the DAP console.\n'
)
end
end

return DynamicTestResult
51 changes: 0 additions & 51 deletions lua/neotest-jdtls/junit/reports/junit.lua

This file was deleted.

Loading

0 comments on commit 48a6e2c

Please sign in to comment.