All tests that use import-project should cleanup after themselves

Change-Id: I23779346018242e177bb1c0c3d03e66235915abb
Signed-off-by: Pascal Rapicault <pascal@rapicorp.com>
diff --git a/org.eclipse.egerrit.ui.rcptt.tests/compare/OpenFileInWorkspace.test b/org.eclipse.egerrit.ui.rcptt.tests/compare/OpenFileInWorkspace.test
index db8acf6..8f8a256 100644
--- a/org.eclipse.egerrit.ui.rcptt.tests/compare/OpenFileInWorkspace.test
+++ b/org.eclipse.egerrit.ui.rcptt.tests/compare/OpenFileInWorkspace.test
@@ -6,43 +6,47 @@
 External-Reference: 
 Id: _SidcMPPBEeaTHaB7IPJ7BA
 Runtime-Version: 2.1.0.201605312320
-Save-Time: 3/20/17 1:57 PM
+Save-Time: 3/22/17 11:26 AM
 Testcase-Type: ecl
 
 ------=_.content-0a7243a0-75d3-3d5f-9791-539de0e5b7ac
 Content-Type: text/ecl
 Entry-Name: .content
 
-//Make sure all the git repos are removed
+// Make sure all the git repos are removed
 delete-git-repos
 
-//Create a first review, import the project in the workspace, and open the compare editor
-let [val review [create-review -server $serverURL -filename "Project/src/file.txt" -fileContent "a\nb\nc\n"]] {
-	import-project $review -projectName Project
-	openCompareEditor $review
+try {
+	// Create a first review, import the project in the workspace, and open the compare editor
+	let [val review [create-review -server $serverURL -filename "Project/src/file.txt" -fileContent "a\nb\nc\n"]] {
+		import-project $review -projectName Project
+		openCompareEditor $review
+	}
+
+	// Now assert that using the context menu will open the workspace file
+	get-editor "Compare.*" | get-left-editor | get-menu "Open Workspace File" | click
+	get-eclipse-window | get-object | save-screenshot [substitute-variables "${workspace_loc}/../target/results/after" +
+		"FileOpened.png"]
+
+	wait -ms 3000
+	get-editor "file.txt"
+	get-editor "file.txt" | close
+
+	get-editor "Compare.*" | get-right-editor | get-menu "Open Workspace File" | click
+	wait -ms 3000
+	get-editor "file.txt"
+	get-editor "file.txt" | close
+
+	// Now we rename the workspace file and make sure that the user sees a dialog when the file can't be found
+	get-view "Package Explorer" | get-tree | select "Project.*/src/file.txt" | get-menu "Refactor/Rename..." | click
+	with [get-window "Rename Resource"] {
+		get-editbox -after [get-label "New name:"] | set-text "bar.txt"
+		get-button OK | click
+	}
+	get-editor "Compare.*" | get-left-editor | get-menu "Open Workspace File" | click
+	wait -ms 3000
+	get-window "File(s) not found" | get-button OK | click
+} -finally {
+	delete-git-repos
 }
-
-//Now assert that using the context menu will open the workspace file
-get-editor "Compare.*" | get-left-editor | get-menu "Open Workspace File" | click
-get-eclipse-window | get-object | save-screenshot 
-	[substitute-variables "${workspace_loc}/../target/results/afterFileOpened.png"]  
-  
-wait -ms 3000
-get-editor "file.txt"
-get-editor "file.txt" | close
-
-get-editor "Compare.*" | get-right-editor | get-menu "Open Workspace File" | click
-wait -ms 3000
-get-editor "file.txt"
-get-editor "file.txt" | close
-
-//Now we rename the workspace file and make sure that the user sees a dialog when the file can't be found
-get-view "Package Explorer" | get-tree | select "Project.*/src/file.txt"  | get-menu "Refactor/Rename..." | click
-with [get-window "Rename Resource"] {
-    get-editbox -after [get-label "New name:"] | set-text "bar.txt"
-    get-button OK | click
-}
-get-editor "Compare.*" | get-left-editor | get-menu "Open Workspace File" | click
-wait -ms 3000
-get-window "File(s) not found" | get-button OK | click
 ------=_.content-0a7243a0-75d3-3d5f-9791-539de0e5b7ac--
diff --git a/org.eclipse.egerrit.ui.rcptt.tests/reviewEditor/Checkout.test b/org.eclipse.egerrit.ui.rcptt.tests/reviewEditor/Checkout.test
index b1294f0..b4f1603 100644
--- a/org.eclipse.egerrit.ui.rcptt.tests/reviewEditor/Checkout.test
+++ b/org.eclipse.egerrit.ui.rcptt.tests/reviewEditor/Checkout.test
@@ -6,34 +6,37 @@
 External-Reference: 
 Id: _ai5P8O7_EeaycuGxgXuVog
 Runtime-Version: 2.1.0.201605312320
-Save-Time: 2/10/17 4:14 PM
+Save-Time: 3/22/17 11:26 AM
 Testcase-Type: ecl
 
 ------=_.content-0a7243a0-75d3-3d5f-9791-539de0e5b7ac
 Content-Type: text/ecl
 Entry-Name: .content
 
-//Make sure all the git repos are removed
+// Make sure all the git repos are removed
 delete-git-repos
 
-//Create a first review, import the project in the workspace, sanity check the content of the file
-let [val review [create-review -server $serverURL -filename "Project/src/file.txt" -fileContent "a\nb\nc\n"]] {
-	import-project $review -projectName Project
+try {
+	// Create a first review, import the project in the workspace, sanity check the content of the file
+	let [val review [create-review -server $serverURL -filename "Project/src/file.txt" -fileContent "a\nb\nc\n"]] {
+		import-project $review -projectName Project
+	}
+	assert-that-editor "file.txt" -contains "a\nb\nc"
+
+	// Create a second review, checkout it out, assert that we have the right file
+	let [val review [create-review -server $serverURL -filename "Project/src/file.txt" -fileContent "1\n2\n3"]] {
+		runQueryAndOpenEditor $review
+	}
+
+	with [get-editor] {
+		checkout-revision "1.*"
+	}
+	get-window "Fetch a change from Gerrit" | get-button Finish | click
+	get-window "EGerrit Tip" | get-button OK | click
+
+	// Open an editor on file.txt
+	assert-that-editor "file.txt" -contains "1\n2\n3"
+} -finally {
+	delete-git-repos
 }
-assert-that-editor "file.txt" -contains "a\nb\nc"
-
-//Create a second review, checkout it out, assert that we have the right file
-let [val review [create-review -server $serverURL -filename "Project/src/file.txt" -fileContent "1\n2\n3"]] {
-	runQueryAndOpenEditor $review
-}
-
-with [get-editor] {
-	checkout-revision "1.*"
-}
-get-window "Fetch a change from Gerrit" | get-button Finish | click
-get-window "EGerrit Tip" | get-button OK | click
-
-//Open an editor on file.txt
-assert-that-editor "file.txt" -contains "1\n2\n3"
-
 ------=_.content-0a7243a0-75d3-3d5f-9791-539de0e5b7ac--
diff --git a/org.eclipse.egerrit.ui.rcptt.tests/reviewEditor/CheckoutAlreadyExisting.test b/org.eclipse.egerrit.ui.rcptt.tests/reviewEditor/CheckoutAlreadyExisting.test
index 8200911..214a116 100644
--- a/org.eclipse.egerrit.ui.rcptt.tests/reviewEditor/CheckoutAlreadyExisting.test
+++ b/org.eclipse.egerrit.ui.rcptt.tests/reviewEditor/CheckoutAlreadyExisting.test
@@ -6,7 +6,7 @@
 External-Reference: 
 Id: _NRuHAO--EeaJxZ8h6GZdcw
 Runtime-Version: 2.1.0.201605312320
-Save-Time: 2/10/17 4:12 PM
+Save-Time: 3/22/17 11:26 AM
 Testcase-Type: ecl
 
 ------=_.content-0a7243a0-75d3-3d5f-9791-539de0e5b7ac
@@ -16,29 +16,32 @@
 // Make sure all the git repos are removed
 delete-git-repos
 
-// Create a review with two revisions.
-// Check out project
-let [val review [amend-review [create-review -server $serverURL -filename "Project/src/file.txt" -fileContent "a\nb\n" +
-	"c\n"]]] {
-	import-project $review -projectName Project
-	runQueryAndOpenEditor $review
+try {
+	// Create a review with two revisions.
+	// Check out project
+	let [val review [amend-review [create-review -server $serverURL -filename "Project/src/file.txt"
+		-fileContent "a\nb\nc\n"]]] {
+		import-project $review -projectName Project
+		runQueryAndOpenEditor $review
+	}
+
+	// Checkout the revision 1
+	with [get-editor] {
+		checkout-revision -ps "1.*"
+	}
+
+	// Assert that the dialog to perform the checkout is opened
+	get-window "Fetch a change from Gerrit" | get-button Finish | click
+	get-window "EGerrit Tip" | get-button OK | click
+
+	// Checkout the revision 1, this is expected to be a no-op since this is what we got when the project was imported
+	with [get-editor] {
+		checkout-revision -ps "2.*"
+	}
+	// Here we would fail if the dialog was not "Fetch" dialog was shown
+
+	get-window "EGerrit Tip" | get-button OK | click
+} -finally {
+	delete-git-repos
 }
-
-// Checkout the revision 1
-with [get-editor] {
-	checkout-revision -ps "1.*"
-}
-
-// Assert that the dialog to perform the checkout is opened
-get-window "Fetch a change from Gerrit" | get-button Finish | click
-get-window "EGerrit Tip" | get-button OK | click
-
-
-// Checkout the revision 1, this is expected to be a no-op since this is what we got when the project was imported
-with [get-editor] {
-	checkout-revision -ps "2.*"
-}
-// Here we would fail if the dialog was not "Fetch" dialog was shown
-
-get-window "EGerrit Tip" | get-button OK | click
 ------=_.content-0a7243a0-75d3-3d5f-9791-539de0e5b7ac--
diff --git a/org.eclipse.egerrit.ui.rcptt.tests/reviewEditor/CheckoutMultipleTimes.test b/org.eclipse.egerrit.ui.rcptt.tests/reviewEditor/CheckoutMultipleTimes.test
index b236b78..d8dfb44 100644
--- a/org.eclipse.egerrit.ui.rcptt.tests/reviewEditor/CheckoutMultipleTimes.test
+++ b/org.eclipse.egerrit.ui.rcptt.tests/reviewEditor/CheckoutMultipleTimes.test
@@ -6,7 +6,7 @@
 External-Reference: 
 Id: _w6S9QO-jEeaxIN8wWiZJ3Q
 Runtime-Version: 2.1.0.201605312320
-Save-Time: 2/10/17 8:48 PM
+Save-Time: 3/22/17 11:26 AM
 Testcase-Type: ecl
 
 ------=_.content-0a7243a0-75d3-3d5f-9791-539de0e5b7ac
@@ -16,17 +16,20 @@
 // Make sure all the git repos are removed
 delete-git-repos
 
-// Checking out a review that has just been created is a no-op
-let [val review [create-review -server $serverURL -filename "Project/src/file.txt" -fileContent "a\nb\nc\n"]] {
-	import-project $review -projectName Project
-	runQueryAndOpenEditor $review
+try {
+	// Checking out a review that has just been created is a no-op
+	let [val review [create-review -server $serverURL -filename "Project/src/file.txt" -fileContent "a\nb\nc\n"]] {
+		import-project $review -projectName Project
+		runQueryAndOpenEditor $review
 
-	assert-that-editor "file.txt" -contains "a\nb\nc"
-	
-	with [get-editor] {
-		checkout-revision "1.*" -acceptPrompts true
+		assert-that-editor "file.txt" -contains "a\nb\nc"
+
+		with [get-editor] {
+			checkout-revision "1.*" -acceptPrompts true
+		}
 	}
+	assert-that-editor "file.txt" -contains "a\nb\nc"
+} -finally {
+	delete-git-repos
 }
-assert-that-editor "file.txt" -contains "a\nb\nc"
-
 ------=_.content-0a7243a0-75d3-3d5f-9791-539de0e5b7ac--
diff --git a/org.eclipse.egerrit.ui.rcptt.tests/reviewEditor/CheckoutWithPrompting.test b/org.eclipse.egerrit.ui.rcptt.tests/reviewEditor/CheckoutWithPrompting.test
index b42152d..ef46aec 100644
--- a/org.eclipse.egerrit.ui.rcptt.tests/reviewEditor/CheckoutWithPrompting.test
+++ b/org.eclipse.egerrit.ui.rcptt.tests/reviewEditor/CheckoutWithPrompting.test
@@ -6,7 +6,7 @@
 External-Reference: 
 Id: _RMuQEO_WEeaJxZ8h6GZdcw
 Runtime-Version: 2.1.0.201605312320
-Save-Time: 2/10/17 7:43 PM
+Save-Time: 3/22/17 11:26 AM
 Testcase-Type: ecl
 
 ------=_.content-0a7243a0-75d3-3d5f-9791-539de0e5b7ac
@@ -16,51 +16,53 @@
 // Make sure all the git repos are removed
 delete-git-repos
 
-// Create a review with two revisions.
-// Check out project
-let [val review [amend-review [create-review -server $serverURL -filename "Project/src/file.txt" -fileContent "a\nb\n" +
-	"c\n"]]] {
-	import-project $review -projectName Project
-	runQueryAndOpenEditor $review
-}
-with [get-editor] {
-	checkout-revision "2.*" -acceptPrompts true
-}
-with [get-editor] {
-	checkout-revision "1.*" -acceptPrompts true
-}
+try {
+	// Create a review with two revisions.
+	// Check out project
+	let [val review [amend-review [create-review -server $serverURL -filename "Project/src/file.txt"
+		-fileContent "a\nb\nc\n"]]] {
+		import-project $review -projectName Project
+		runQueryAndOpenEditor $review
+	}
+	with [get-editor] {
+		checkout-revision "2.*" -acceptPrompts true
+	}
+	with [get-editor] {
+		checkout-revision "1.*" -acceptPrompts true
+	}
 
+	// Create a commit in the branch for revision 2
+	open-file "file.txt"
+	with [get-editor "file.txt" | get-text-viewer] {
+		set-caret-pos 1 1
+		key-type Del
+		type-text x
+		key-type "M1+s"
+	}
 
-//Create a commit in the branch for revision 2
-open-file "file.txt"
-with [get-editor "file.txt" | get-text-viewer] {
-    set-caret-pos 1 1
-    key-type Del
-    type-text x
-    key-type "M1+s"
-}
+	with [get-editor "file.txt"] {
+		get-editbox | get-menu "Team/Add to Index" | click
+		get-editbox | get-menu "Team/Commit..." | click
+	}
+	with [get-view "Git Staging" | get-section "Commit Message"] {
+		get-button "Amend (Edit Previous Commit)" | click
+		get-button Commit | click
+	}
+	get-editor "file.txt" | close
 
-with [get-editor "file.txt"] {
-    get-editbox | get-menu "Team/Add to Index" | click
-    get-editbox | get-menu "Team/Commit..." | click
-}
-with [get-view "Git Staging" | get-section "Commit Message"] {
-    get-button "Amend (Edit Previous Commit)" | click
-    get-button Commit | click
-}
-get-editor "file.txt" | close
-
-//Finally try to checkout the revision 1 again, and check the state of the dialog that opened
-with [get-editor]  {
-    checkout-revision "2.*" -acceptPrompts true
-}
-with [get-window "Review previously checked-out"] {
-    with [get-table] {
-        get-item master | get-property "columns[1]" | equals "This is commit you are looking for" | verify-true
-        get-item "change.*" | get-property "columns[1]" 
-            | equals "The branch was created from some patchset of this review but contains code you modified or rebased" 
-            | verify-true
-    }
-    get-button Switch | get-property enablement | equals true | verify-true
+	// Finally try to checkout the revision 1 again, and check the state of the dialog that opened
+	with [get-editor] {
+		checkout-revision "2.*" -acceptPrompts true
+	}
+	with [get-window "Review previously checked-out"] {
+		with [get-table] {
+			get-item master | get-property "columns[1]" | equals "This is commit you are looking for" | verify-true
+			get-item "change.*" | get-property "columns[1]" | equals "The branch was created from some patchset of th" +
+				"is review but contains code you modified or rebased" | verify-true
+		}
+		get-button Switch | get-property enablement | equals true | verify-true
+	}
+} -finally {
+	delete-git-repos
 }
 ------=_.content-0a7243a0-75d3-3d5f-9791-539de0e5b7ac--