-
Notifications
You must be signed in to change notification settings - Fork 6
add intellij integration test structure #76
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
8c3e2d7
add intellij integration test structure
afucher bfa026c
configure testdata and assert files
afucher 0c28fcd
try to execute slurp action
afucher f67bb03
set lsp server path
afucher 6e9c640
interacting with editor - wip
marlon-jsilva ca38644
executa slurp e valida arquivo
afucher 2bf2a01
fix dispatch-all-until
marlonjsilva 169b1ac
remove unnecessary lines
marlonjsilva 27f71ed
refactoring tests - wip
marlonjsilva c7a5da9
adding --debug to test.yaml
marlonjsilva e0fc2a7
bump LSP4IJ version
marlonjsilva dcfd8c6
bump LSP4IJ version
marlonjsilva ed7e2ac
improve tests
marlonjsilva f8c7106
refactor some functions
marlonjsilva d97d808
disable comment from test report
afucher f6597fb
remove debug flag from test
afucher 3064671
apply code review
afucher 317502c
change test project name to be more explicit
afucher File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
name: Tests | ||
on: | ||
pull_request: | ||
|
||
permissions: | ||
contents: read | ||
checks: write | ||
pull-requests: write | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: Setup Java | ||
uses: actions/setup-java@v4 | ||
with: | ||
distribution: 'temurin' | ||
java-version: 17 | ||
cache: 'gradle' | ||
|
||
- name: Install Clojure | ||
uses: DeLaGuardo/setup-clojure@master | ||
with: | ||
bb: '1.12.196' | ||
cli: 1.12.0.1530 | ||
|
||
- name: Run tests | ||
run: ./gradlew test | ||
|
||
- name: Publish Test Report | ||
uses: mikepenz/action-junit-report@v5 | ||
if: success() || failure() # always run even if the previous step fails | ||
with: | ||
report_paths: '**/build/test-results/test/TEST-*.xml' | ||
simplified_summary: true | ||
comment: false |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
{:paths ["src/scripts"] | ||
:tasks {tag scripts/tag | ||
build-plugin scripts/build-plugin | ||
test scripts/tests | ||
install-plugin scripts/install-plugin | ||
publish-plugin scripts/publish-plugin}} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
src/test/clojure/com/github/clojure_lsp/intellij/slurp_action_test.clj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
(ns com.github.clojure-lsp.intellij.slurp-action-test | ||
(:require | ||
[clojure.test :refer [deftest is]] | ||
[com.github.clojure-lsp.intellij.editor :as editor] | ||
[com.github.clojure-lsp.intellij.test-utils :as test-utils] | ||
[com.github.ericdallo.clj4intellij.test :as clj4intellij.test]) | ||
(:import | ||
[com.intellij.openapi.project Project] | ||
[com.intellij.testFramework.fixtures CodeInsightTestFixture])) | ||
|
||
(set! *warn-on-reflection* true) | ||
|
||
(deftest slurp-action-test | ||
"Tests the Forward Slurp editor action functionality in Clojure LSP. | ||
This test: | ||
1. Sets up a test project with a Clojure file | ||
2. Opens the file in the editor | ||
3. Sets up the LSP server | ||
4. Moves the caret to a specific position | ||
5. Executes the Forward Slurp action | ||
6. Verifies the resulting text matches the expected output | ||
|
||
The test ensures that the Forward Slurp action correctly modifies the code structure | ||
by moving the closing parenthesis forward." | ||
(let [project-name "clojure.sample-project" | ||
{:keys [fixtures project deps-file]} (test-utils/setup-test-project project-name) | ||
clj-file (.copyFileToProject ^CodeInsightTestFixture fixtures "foo.clj")] | ||
(is (= project-name (.getName ^Project project))) | ||
(is deps-file) | ||
|
||
(let [editor (test-utils/open-file-in-editor fixtures clj-file)] | ||
(test-utils/setup-lsp-server project) | ||
(editor/move-caret-to-position editor 2 8) | ||
(test-utils/run-editor-action "ClojureLSP.ForwardSlurp" project) | ||
(clj4intellij.test/dispatch-all) | ||
|
||
(.checkResultByFile ^CodeInsightTestFixture fixtures "foo_expected.clj") | ||
|
||
(test-utils/teardown-test-project project)))) |
92 changes: 92 additions & 0 deletions
92
src/test/clojure/com/github/clojure_lsp/intellij/test_utils.clj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
(ns com.github.clojure-lsp.intellij.test-utils | ||
(:require | ||
[com.github.clojure-lsp.intellij.client :as lsp-client] | ||
[com.github.clojure-lsp.intellij.server :as server] | ||
[com.github.ericdallo.clj4intellij.app-manager :as app-manager] | ||
[com.github.ericdallo.clj4intellij.test :as clj4intellij.test]) | ||
(:import | ||
[com.github.clojure_lsp.intellij.extension SettingsState] | ||
[com.intellij.ide DataManager] | ||
[com.intellij.openapi.actionSystem ActionManager] | ||
[com.intellij.openapi.components ServiceManager] | ||
[com.intellij.testFramework.fixtures CodeInsightTestFixture])) | ||
|
||
(set! *warn-on-reflection* true) | ||
|
||
(defn get-editor-text | ||
"Returns the text content of the editor's document." | ||
[^CodeInsightTestFixture fixture] | ||
(-> fixture .getEditor .getDocument .getText)) | ||
|
||
(defn open-file-in-editor | ||
"Opens a file in the editor and returns the editor instance." | ||
[^CodeInsightTestFixture fixture file] | ||
(let [project (.getProject fixture)] | ||
(app-manager/write-command-action | ||
project | ||
(fn [] (.openFileInEditor fixture file))) | ||
(.getEditor fixture))) | ||
|
||
(defn run-editor-action | ||
"Runs an editor action with the given ID for the specified project." | ||
[action-id project] | ||
(let [action (.getAction (ActionManager/getInstance) action-id) | ||
context (.getDataContext (DataManager/getInstance))] | ||
(app-manager/write-command-action | ||
project | ||
(fn [] | ||
(.actionPerformed | ||
action | ||
(com.intellij.openapi.actionSystem.AnActionEvent/createFromDataContext action-id nil context)))))) | ||
|
||
(defn wait-lsp-start | ||
"Dispatches all events until the LSP server is started or the timeout is reached." | ||
[{:keys [project millis timeout] | ||
:or {millis 1000 | ||
timeout 10000}}] | ||
(let [start-time (System/currentTimeMillis)] | ||
(loop [] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. clojure.core.async/alts! is perfect for those do or timeout task, but it's ok to keep it as it is |
||
(let [current-time (System/currentTimeMillis) | ||
elapsed-time (- current-time start-time) | ||
status (lsp-client/server-status project)] | ||
(cond | ||
(>= elapsed-time timeout) | ||
(throw (ex-info "LSP server failed to start within timeout" | ||
{:elapsed-time elapsed-time | ||
:final-status status})) | ||
|
||
(= status :started) | ||
true | ||
|
||
:else | ||
(do | ||
(clj4intellij.test/dispatch-all) | ||
(Thread/sleep millis) | ||
(recur))))))) | ||
|
||
(defn teardown-test-project | ||
"Shuts down all resources for the given project." | ||
[project] | ||
(server/shutdown! project)) | ||
|
||
(defn setup-test-project | ||
"Sets up a test project with the given name and optional deps.edn content. | ||
Returns a map with :fixture, :project, and :deps-file." | ||
([project-name] | ||
(setup-test-project project-name "{}")) | ||
([project-name deps-content] | ||
(let [fixtures (clj4intellij.test/setup project-name) | ||
deps-file (.createFile fixtures "deps.edn" deps-content) | ||
_ (.setTestDataPath fixtures "testdata") | ||
project (.getProject fixtures)] | ||
{:fixtures fixtures | ||
:project project | ||
:deps-file deps-file}))) | ||
|
||
(defn setup-lsp-server | ||
"Sets up and waits for the LSP server to be ready." | ||
[project] | ||
(let [my-settings ^SettingsState (ServiceManager/getService SettingsState)] | ||
(.loadState my-settings my-settings) | ||
(clj4intellij.test/dispatch-all) | ||
(wait-lsp-start {:project project}))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
(ns foo) | ||
|
||
(println) "Oiii" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
(ns foo) | ||
|
||
(println "Oiii") |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For some reason using the same approach from clj4intellij with promises makes the test to hang forever 😢 So, we decided to create a specific function in this project to use a timeout instead of promise to wait.