Skip to content

Commit

Permalink
Restructure the tests
Browse files Browse the repository at this point in the history
  • Loading branch information
yyoncho committed Sep 1, 2018
1 parent e7e8f8e commit fcfbb84
Show file tree
Hide file tree
Showing 10 changed files with 108 additions and 115 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
.cask
*.elc
.classpath
.project
.settings
target
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ before_install:
install:
- cask install
script:
- rm -rf ~/.emacs.d/eclipse.jdt.ls/server/
- mkdir -p ~/.emacs.d/eclipse.jdt.ls/server/
- mkdir -p ~/.emacs.d/eclipse.jdt.ls/plugins/
- wget http://download.eclipse.org/jdtls/snapshots/jdt-language-server-latest.tar.gz -O /tmp/jdt-latest.tar
Expand Down
1 change: 0 additions & 1 deletion README.org
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
[[https://melpa.org/#/dap-mode][file:https://melpa.org/packages/dap-mode-badge.svg]]
[[http://spacemacs.org][file:https://cdn.rawgit.com/syl20bnr/spacemacs/442d025779da2f62fc86c2082703697714db6514/assets/spacemacs-badge.svg]]
[[https://travis-ci.org/yyoncho/dap-mode][https://travis-ci.org/yyoncho/dap-mode.svg?branch=master]]
[[https://coveralls.io/github/yyoncho/dap-mode?branch=master][https://coveralls.io/repos/github/yyoncho/dap-mode/badge.svg?branch=master]]
* Table of Contents :TOC_4_gh:noexport:
- [[#summary][Summary]]
- [[#project-status][Project status]]
Expand Down
15 changes: 9 additions & 6 deletions dap-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,10 @@ The hook will be called with the session file and the new set of breakpoint loca
;; Leftover data from previous chunk; to be processed
(leftovers nil))

(defun dap--get-sessions (workspace)
"Get sessions for WORKSPACE."
(lsp-workspace-get-metadata "debug-sessions" workspace))

(defun dap--wait-for-port (host port &optional retry-count sleep-interval)
"Wait for PORT to be open on HOST.
Expand Down Expand Up @@ -311,10 +315,6 @@ WORKSPACE will be used to calculate root folder."
(erase-buffer)
(insert (prin1-to-string to-persist)))))

(defun dap--get-sessions (workspace)
"Get sessions for WORKSPACE."
(lsp-workspace-get-metadata "debug-sessions" workspace))

(defun dap--set-sessions (workspace debug-sessions)
"Update list of debug sessions for WORKSPACE to DEBUG-SESSIONS."
(lsp-workspace-set-metadata "debug-sessions" debug-sessions workspace)
Expand Down Expand Up @@ -1172,9 +1172,12 @@ If the current session it will be terminated."
(dap--set-sessions lsp--cur-workspace ())
(dap--switch-to-session nil))

(defun dap-delete-all-breakpoints ()
(defun dap-breakpoint-delete-all ()
"Delete all breakpoints."
(interactive))
(interactive)
(maphash (lambda (file-name _)
(dap--breakpoints-changed nil file-name))
(dap--get-breakpoints lsp--cur-workspace)))

(defun dap--after-open ()
"Handler of after open hook."
Expand Down
2 changes: 1 addition & 1 deletion dap-overlays.el
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ overlay."
#'dap-overlays--remove-result-overlay-after-command
nil 'local)
(dap-overlays--remove-result-overlay-after-command))))
(when-let* ((win (get-buffer-window buffer)))
(when-let (win (get-buffer-window buffer))
;; Left edge is visible.
(when (and (<= (window-start win) (point) (window-end win))
;; Right edge is visible. This is a little conservative
Expand Down
90 changes: 16 additions & 74 deletions features/Breakpoints.feature
Original file line number Diff line number Diff line change
@@ -1,106 +1,48 @@
Feature: Breakpoint tests

Background:
Given I have maven project "m" in "tmp"
And I call "dap-turn-on-dap-mode"
And I add project "m" folder "tmp" to the list of workspace folders
And I open a java file "tmp/m/src/main/java/temp/App.java"
And I clear the buffer
And I insert:
"""
package temp;
class App {
public static void main(String[] args) {
System.out.print(123);
foo();
bar();
}
static int foo() {
new App();
return 10;
}
static int bar() {
new App();
return 10;
}
}
"""
And I call "save-buffer"
And I start lsp-java
And I open a project file "test-project/src/main/java/temp/App.java"
And The server status must become "LSP::Started"

@Breakpoints @WIP
@Breakpoints
Scenario: Breakpoint + continue
When I place the cursor before "System"
And I call "dap-breakpoint-toggle"
And I go to beginning of buffer
And I attach handler "breakpoint" to hook "dap-stopped-hook"
And I call "dap-java-debug"
Then The hook handler "breakpoint" would be called
And the cursor should be before "System"
And the cursor should be before " System"
And I call "dap-continue"
And I should see buffer "*out*" with content "123"

@Breakpoints
Scenario: Next
When I place the cursor before "System"
And I call "dap-breakpoint-toggle"
And I go to beginning of buffer
And I attach handler "breakpoint" to hook "dap-stopped-hook"
And I call "dap-java-debug"
Then The hook handler "breakpoint" would be called
And the cursor should be before "System"
And I call "dap-next"
Then The hook handler "breakpoint" would be called
And the cursor should be before "foo"
And I should see buffer "*out*" with content "123"

@Breakpoints
Scenario: Step in
When I place the cursor before "foo()"
And I call "dap-breakpoint-toggle"
And I call "dap-breakpoint-add"
And I go to beginning of buffer
And I attach handler "breakpoint" to hook "dap-stopped-hook"
And I call "dap-java-debug"
Then The hook handler "breakpoint" would be called
And the cursor should be before "foo()"
And I call "dap-step-in"
Then The hook handler "breakpoint" would be called
When I go in active window
Then I should be in buffer "App.java"
And the cursor should be before "new App();"
And I call "dap-continue"
And I should see buffer "*out*" with content "123"

@Breakpoints
Scenario: Terminate
When I place the cursor before "System"
And I call "dap-breakpoint-toggle"
And I go to beginning of buffer
And I attach handler "breakpoint" to hook "dap-stopped-hook"
And I attach handler "terminated" to hook "dap-terminated-hook"
And I call "dap-java-debug"
Then The hook handler "breakpoint" would be called
And the cursor should be before "System"
And the cursor should be before " System"
And I call "dap-disconnect"
Then The hook handler "terminated" would be called

@Breakpoints
Scenario: Step out
When I place the cursor before "new App"
And I call "dap-breakpoint-toggle"
And I call "dap-breakpoint-add"
And I go to beginning of buffer
And I attach handler "stopped" to hook "dap-stopped-hook"
And I call "dap-java-debug"
Then The hook handler "stopped" would be called
And the cursor should be before "new App"
And the cursor should be before " new App"
And I call "dap-step-out"
Then The hook handler "stopped" would be called
And the cursor should be before "foo()"
And the cursor should be before " foo()"
And I call "dap-continue"
And I should see buffer "*out*" with content "123"

Expand All @@ -114,10 +56,10 @@ Feature: Breakpoint tests
And I attach handler "breakpoint" to hook "dap-stopped-hook"
And I call "dap-java-debug"
Then The hook handler "breakpoint" would be called
And the cursor should be before "foo()"
And the cursor should be before " foo()"
When I call "dap-continue"
Then The hook handler "breakpoint" would be called
And the cursor should be before "bar()"
And the cursor should be before " bar()"
When I call "dap-continue"
And I should see buffer "*out*" with content "123"

Expand All @@ -139,8 +81,8 @@ Feature: Breakpoint tests
And I attach handler "breakpoint" to hook "dap-stopped-hook"
And I call "dap-java-debug"
Then The hook handler "breakpoint" would be called
And the cursor should be before "foo()"
And I place the cursor before "bar()"
And the cursor should be before " foo()"
And I place the cursor before " bar()"
And I call "dap-breakpoint-toggle"
When I call "dap-continue"
And I should see buffer "*out*" with content "123"
Expand All @@ -152,12 +94,12 @@ Feature: Breakpoint tests
And I attach handler "breakpoint" to hook "dap-stopped-hook"
And I call "dap-java-debug"
Then The hook handler "breakpoint" would be called
And the cursor should be before "foo()"
And the cursor should be before " foo()"
And I place the cursor before "bar()"
And I call "dap-breakpoint-toggle"
When I call "dap-continue"
Then The hook handler "breakpoint" would be called
And the cursor should be before "bar()"
And the cursor should be before " bar()"
When I call "dap-continue"
And I should see buffer "*out*" with content "123"

Expand All @@ -166,11 +108,11 @@ Feature: Breakpoint tests
When I place the cursor before "System"
And I call "dap-breakpoint-toggle"
And I kill buffer "App.java"
And I open a java file "tmp/m/src/main/java/temp/App.java"
And I open a project file "test-project/src/main/java/temp/App.java"
And I start lsp-java
And I attach handler "breakpoint" to hook "dap-stopped-hook"
And I call "dap-java-debug"
Then The hook handler "breakpoint" would be called
And the cursor should be before "System"
And the cursor should be before " System"
And I call "dap-continue"
And I should see buffer "*out*" with content "123"
24 changes: 24 additions & 0 deletions features/fixtures/test-project/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>test-project1</groupId>
<artifactId>test-project</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>test-project</name>
<url>http://maven.apache.org</url>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
19 changes: 19 additions & 0 deletions features/fixtures/test-project/src/main/java/temp/App.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package temp;

class App {
public static void main(String[] args) {
System.out.print(123);
foo();
bar();
}

static int foo() {
new App();
return 10;
}

static int bar() {
new App();
return 10;
}
}
7 changes: 5 additions & 2 deletions features/step-definitions/dap-java-steps.el
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

;;; Code:


(require 'f)
(require 's)
(require 'dap-java)
Expand Down Expand Up @@ -75,6 +74,10 @@
(find-file file-name)
(save-buffer)))

(And "^I open a project file \"\\([^\"]+\\)\"$"
(lambda (file-name)
(find-file (f-join dap-java-maven-project-root file-name))))

(And "^I add project \"\\([^\"]+\\)\" folder \"\\([^\"]+\\)\" to the list of workspace folders$"
(lambda (project dir-name)
(add-to-list 'lsp-java--workspace-folders (f-join dap-java-test-root dir-name project))))
Expand Down Expand Up @@ -167,7 +170,7 @@

(And "^I call:$"
(lambda (fn-to-call)
(call-interactively (intern fn-to-call))))
(call-interactively (intern fn-to-call))))

(And "^I kill buffer \"\\([^\"]+\\)\"$"
(lambda (buffer-name)
Expand Down
Loading

0 comments on commit fcfbb84

Please sign in to comment.