Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Added test for Re #1000607

(cherry picked from commit 9b8ed82)

Conflicts:

	org.scala-ide.sdt.core.tests/src/scala/tools/eclipse/sbtbuilder/ScalaJavaDepTest.scala
  • Loading branch information...
commit 02336198a3cc32f70699847b4c4f48210a432115 1 parent a903ca6
Luc Bourlier authored December 05, 2011
82  org.scala-ide.sdt.core.tests/src/scala/tools/eclipse/sbtbuilder/ScalaJavaDepTest.scala
@@ -8,7 +8,7 @@ import org.eclipse.core.resources.IncrementalProjectBuilder
8 8
 import org.eclipse.jdt.core.IJavaModelMarker
9 9
 import org.eclipse.core.resources.IResource
10 10
 
11  
-import org.junit.Assert
  11
+import org.junit.Assert._
12 12
 import org.eclipse.core.resources.IMarker
13 13
 
14 14
 import scala.tools.eclipse.testsetup.SDTTestUtils
@@ -29,61 +29,86 @@ class ScalaJavaDepTest {
29 29
   
30 30
   @Test def testSimpleScalaDep() {
31 31
     println("building " + project)
32  
-    project.clean(new NullProgressMonitor())
33  
-    rebuild(project, false)
  32
+    cleanProject
  33
+
  34
+    def getProblemMarkers= getProblemMarkersFor("test/J.java", "test/S.scala")
34 35
 
35 36
     val problems0 = getProblemMarkers
36  
-    Assert.assertTrue("Build errors found: " + userFriendlyMarkers(problems0), problems0.isEmpty)
  37
+    assertTrue("Build errors found: " + userFriendlyMarkers(problems0), problems0.isEmpty)
37 38
     
38 39
     val JJavaCU = compilationUnit("test/J.java")
39 40
     val originalJJava = SDTTestUtils.slurpAndClose(project.underlying.getFile("src/test/J.java").getContents)
40 41
     SDTTestUtils.changeContentOfFile(project.underlying, JJavaCU.getResource().getAdapter(classOf[IFile]).asInstanceOf[IFile], changedJJava)
41 42
     rebuild(project)
42  
-    val problems1 = getProblemMarkers()
43  
-    Assert.assertTrue("One build error expected, got: " + userFriendlyMarkers(problems1), problems1.length == 1) // do more precise matching later
  43
+    val problems1 = getProblemMarkers
  44
+    assertTrue("One build error expected, got: " + userFriendlyMarkers(problems1), problems1.length == 1) // do more precise matching later
44 45
     
45 46
     val JJavaCU2 = compilationUnit("test/J.java")
46 47
     SDTTestUtils.changeContentOfFile(project.underlying, JJavaCU2.getResource().getAdapter(classOf[IFile]).asInstanceOf[IFile], originalJJava)
47 48
     rebuild(project)
48  
-    val problems2 = getProblemMarkers()
49  
-    Assert.assertTrue("Build errors found: " + userFriendlyMarkers(problems2), problems2.isEmpty)
  49
+    val problems2 = getProblemMarkers
  50
+    assertTrue("Build errors found: " + userFriendlyMarkers(problems2), problems2.isEmpty)
50 51
   }
51 52
 
52 53
   @Ignore
53 54
   @Test def testSimpleJavaDep() {
54 55
     println("building " + project)
55  
-    project.clean(new NullProgressMonitor())
56  
-    rebuild(project, false)
  56
+    cleanProject
  57
+
  58
+    def getProblemMarkers= getProblemMarkersFor("test/J.java", "test/S.scala")
57 59
 
58  
-    val problems0 = getProblemMarkers()
59  
-    Assert.assertTrue("Build errors found: " + userFriendlyMarkers(problems0), problems0.isEmpty)
  60
+    val problems0 = getProblemMarkers
  61
+    assertTrue("Build errors found: " + userFriendlyMarkers(problems0), problems0.isEmpty)
60 62
     
61 63
     val SScalaCU = compilationUnit("test/S.scala")
62 64
     val originalSScala = SDTTestUtils.slurpAndClose(project.underlying.getFile("src/test/S.scala").getContents)
63 65
     SDTTestUtils.changeContentOfFile(project.underlying, SScalaCU.getResource().getAdapter(classOf[IFile]).asInstanceOf[IFile], changedSScala)
64 66
     rebuild(project)
65  
-    val problems1 = getProblemMarkers()
66  
-    Assert.assertTrue("One build error expected: " + userFriendlyMarkers(problems1), problems1.length == 1) // do more precise matching later
  67
+    val problems1 = getProblemMarkers
  68
+    assertTrue("One build error expected: " + userFriendlyMarkers(problems1), problems1.length == 1) // do more precise matching later
67 69
     
68 70
     val SScalaCU2 = compilationUnit("test/S.scala")
69 71
     SDTTestUtils.changeContentOfFile(project.underlying, SScalaCU2.getResource().getAdapter(classOf[IFile]).asInstanceOf[IFile], originalSScala)
70 72
     rebuild(project)
71  
-    val problems2 = getProblemMarkers()
72  
-    Assert.assertTrue("Build errors found: " + userFriendlyMarkers(problems2), problems2.isEmpty)
73  
-  }
  73
+    val problems2 = getProblemMarkers
  74
+    assertTrue("Build errors found: " + userFriendlyMarkers(problems2), problems2.isEmpty)
  75
+  }  
74 76
   
75  
-  def rebuild(prj: ScalaProject, incremental: Boolean = true): List[IMarker] = {
  77
+  def rebuild(prj: ScalaProject) {
76 78
     println("building " + prj)
77  
-    val buildType = if (incremental) IncrementalProjectBuilder.INCREMENTAL_BUILD else IncrementalProjectBuilder.FULL_BUILD
78  
-    prj.underlying.build(buildType, new NullProgressMonitor)
79  
-    getProblemMarkers()
  79
+    prj.underlying.build(IncrementalProjectBuilder.INCREMENTAL_BUILD, new NullProgressMonitor)
80 80
   }
81 81
 
82  
-  def getProblemMarkers(): List[IMarker] = {
83  
-    val units = compilationUnits("test/J.java", "test/S.scala").toList
  82
+  @Test def ticket_1000607() {
  83
+    def getProblemMarkers= getProblemMarkersFor("ticket_1000607/A.scala", "ticket_1000607/C.java")
  84
+
  85
+    // do a clean build and check the expected error
  86
+    cleanProject
  87
+    var problems= getProblemMarkers
  88
+    assertEquals("One error expected: " + userFriendlyMarkers(problems), 1, problems.size)
  89
+    
  90
+    // "fix" the scala code
  91
+    val aClass= compilationUnit("ticket_1000607/A.scala")
  92
+    SDTTestUtils.changeContentOfFile(project.underlying, aClass.getResource().asInstanceOf[IFile], changed_ticket_1000607_A)
  93
+    
  94
+    // trigger incremental compile
  95
+    project.underlying.build(IncrementalProjectBuilder.INCREMENTAL_BUILD, new NullProgressMonitor)
  96
+    
  97
+    // and check that the error disappeared
  98
+    problems= getProblemMarkers
  99
+    assertTrue("Unexpected error: " + userFriendlyMarkers(problems), problems.isEmpty)
  100
+  }
  101
+  
  102
+  def getProblemMarkersFor(paths: String*): List[IMarker] = {
  103
+    val units = compilationUnits(paths: _*).toList
84 104
     units.flatMap(SDTTestUtils.findProblemMarkers)
85 105
   }
86 106
   
  107
+  private def cleanProject: Unit = {
  108
+    project.underlying.build(IncrementalProjectBuilder.CLEAN_BUILD, new NullProgressMonitor)
  109
+    project.underlying.build(IncrementalProjectBuilder.FULL_BUILD, new NullProgressMonitor)
  110
+  }
  111
+
87 112
   def userFriendlyMarkers(markers: List[IMarker]) = markers.map(_.getAttribute(IMarker.MESSAGE))
88 113
   
89 114
   lazy val changedJJava = """
@@ -106,4 +131,15 @@ class S {
106 131
 	def foo1(s:String) { println(new J().bar(s)) } 
107 132
 }
108 133
 """
  134
+
  135
+  lazy val changed_ticket_1000607_A = """
  136
+package ticket_1000607
  137
+
  138
+trait A {
  139
+  def foo(s: String): Unit = {}
  140
+}
  141
+
  142
+abstract class B extends A
  143
+"""
  144
+  
109 145
 }
7  org.scala-ide.sdt.core.tests/test-workspace/scalajavadep/src/ticket_1000607/A.scala
... ...
@@ -0,0 +1,7 @@
  1
+package ticket_1000607
  2
+
  3
+trait A {
  4
+  def foo(s: String): Unit //= {}
  5
+}
  6
+
  7
+abstract class B extends A
5  org.scala-ide.sdt.core.tests/test-workspace/scalajavadep/src/ticket_1000607/C.java
... ...
@@ -0,0 +1,5 @@
  1
+package ticket_1000607;
  2
+
  3
+public class C extends B {
  4
+}
  5
+

0 notes on commit 0233619

Please sign in to comment.
Something went wrong with that request. Please try again.