forked from JPMoresmau/eclipsefp
/
HaskellProjectCreationOperation_PDETest.java
112 lines (90 loc) · 4.11 KB
/
HaskellProjectCreationOperation_PDETest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
// Copyright (c) 2003-2005 by Leif Frenzel - see http://leiffrenzel.de
package net.sf.eclipsefp.haskell.core.project;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.lang.reflect.InvocationTargetException;
import net.sf.eclipsefp.haskell.core.internal.project.ProjectCreationOperation;
import net.sf.eclipsefp.haskell.core.internal.project.ProjectCreationOperationPDETestCase;
import net.sf.eclipsefp.haskell.core.internal.project.ProjectModelFilesOp;
import net.sf.eclipsefp.haskell.core.preferences.ICorePreferenceNames;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
public class HaskellProjectCreationOperation_PDETest extends
ProjectCreationOperationPDETestCase {
@Override
protected ProjectCreationOperation createOperation() {
getCorePrefs().putBoolean( ICorePreferenceNames.FOLDERS_IN_NEW_PROJECT, true );
HaskellProjectCreationOperation result
= new HaskellProjectCreationOperation( );
result.setExtraOperation( new ProjectModelFilesOp() );
return result;
}
public void testAddsHaskellNature() throws InvocationTargetException,
InterruptedException, CoreException {
runOperation();
IProject prj = getWorkspaceRoot().getProject( PROJECT_NAME );
assertNotNull( prj.getNature( HaskellNature.NATURE_ID ) );
}
public void testCreatesDirectoriesFromPreferences()
throws InvocationTargetException, InterruptedException {
getCorePrefs().put( ICorePreferenceNames.FOLDERS_SRC, "customSrc" );
getCorePrefs().put( ICorePreferenceNames.FOLDERS_OUT, "customOut" );
runOperation();
IProject prj = getWorkspaceRoot().getProject( PROJECT_NAME );
assertValid( prj.getFolder( "customSrc" ) );
assertValid( prj.getFolder( "customOut" ) );
}
public void testCreatesDescriptorFile() throws InvocationTargetException,
InterruptedException {
runOperation();
IProject prj = getWorkspaceRoot().getProject( PROJECT_NAME );
IFile f = prj.getFile( HaskellProjectManager.HASKELL_PROJECT_DESCRIPTOR );
assertValid( f );
assertValid( prj.getFile( prj.getName() + ".cabal" ) );
assertValid( prj.getFile( "Setup.hs" ) );
}
public void testSetsUpProjectFoldersFromPreferences() throws Exception {
getCorePrefs().put( ICorePreferenceNames.FOLDERS_SRC, "mySrc" );
getCorePrefs().put( ICorePreferenceNames.FOLDERS_OUT, "myOut" );
getCorePrefs().put( ICorePreferenceNames.TARGET_BINARY, "myBinary" );
getCorePrefs().put( ICorePreferenceNames.SELECTED_COMPILER, "null" );
runOperation();
IProject prj = getWorkspaceRoot().getProject( PROJECT_NAME );
IFile f = prj.getFile( HaskellProjectManager.HASKELL_PROJECT_DESCRIPTOR );
final String expectedContents = HaskellProjectManager
.createDescriptorContent( "mySrc", "myOut", "myBinary", "null" );
assertEquals( expectedContents, readContents( f ) );
}
public void testDoNotCreateFoldersWhenPreferenceDisabled() throws Exception {
getCorePrefs().putBoolean( ICorePreferenceNames.FOLDERS_IN_NEW_PROJECT, false );
runOperation();
IProject prj = getWorkspaceRoot().getProject( PROJECT_NAME );
// should only contain the project descriptors (.project and .hsproject)
// and the generated Setup.hs and cabal file
assertEquals( 4, prj.members().length );
IFile f = prj.getFile( HaskellProjectManager.HASKELL_PROJECT_DESCRIPTOR );
assertValid( f );
assertEquals( "", readContents( f ) );
}
// helping methods
//////////////////
private String readContents( final IFile file ) throws Exception {
StringBuffer buf = new StringBuffer( 1024 );
InputStream input = file.getContents();
BufferedReader reader = new BufferedReader( new InputStreamReader( input ) );
String line;
while( null != ( line = reader.readLine() ) ) {
buf.append( line );
buf.append( '\n' );
}
input.close();
return buf.toString();
}
private void assertValid( final IResource res ) {
assertNotNull( res );
assertTrue( "Resource does not exist", res.exists() );
}
}