Skip to content

Commit

Permalink
Merge pull request #62 from flutter/testing
Browse files Browse the repository at this point in the history
Basic unit test framework
  • Loading branch information
stevemessick authored Aug 24, 2016
2 parents 361cd43 + 4e2aedb commit a9cfa4b
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 24 deletions.
1 change: 1 addition & 0 deletions src/io/flutter/run/FlutterRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public boolean canRun(final @NotNull String executorId, final @NotNull RunProfil
(DefaultRunExecutor.EXECUTOR_ID.equals(executorId) || DefaultDebugExecutor.EXECUTOR_ID.equals(executorId)));
}

@Override
protected DartUrlResolver getDartUrlResolver(@NotNull final Project project, @NotNull final VirtualFile contextFileOrDir) {
return new FlutterUrlResolver(project, contextFileOrDir);
}
Expand Down
12 changes: 2 additions & 10 deletions src/io/flutter/sdk/FlutterSdkGlobalLibUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,16 +84,8 @@ private static void setupFlutterSdkRoots(@NotNull final Library library, @NotNul
}
}

public static void ensureDartSdkConfigured(@NotNull final String sdkHomePath) {
// TODO Implement or remove.
}

public static void enableDartSdk(Module module) {
// TODO Implement enableDartSdk()
}

public static void disableDartSdk(List<Module> modules) {
// TODO Implement disableDartSdk()
public static void disableFlutterSdk(List<Module> modules) {
// TODO Implement disableFlutterSdk()
}

public static void enableFlutterSdk(@NotNull final Module module) {
Expand Down
23 changes: 20 additions & 3 deletions testSrc/io/flutter/FlutterCodeInsightFixtureTestCase.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,30 @@
*/
package io.flutter;

import com.jetbrains.lang.dart.DartCodeInsightFixtureTestCase;
import com.intellij.testFramework.fixtures.LightPlatformCodeInsightFixtureTestCase;
import com.jetbrains.lang.dart.util.DartTestUtils;
import io.flutter.sdk.FlutterSdk;
import io.flutter.util.FlutterTestUtils;

abstract public class FlutterCodeInsightFixtureTestCase extends DartCodeInsightFixtureTestCase {
abstract public class FlutterCodeInsightFixtureTestCase extends LightPlatformCodeInsightFixtureTestCase {
protected void setUp() throws Exception {
super.setUp();
FlutterTestUtils.configureFlutterSdk(myModule, getTestRootDisposable(), true);
FlutterSdk sdk = FlutterSdk.getFlutterSdk(myModule.getProject());
assert(sdk != null);
String path = sdk.getHomePath();
String dartSdkPath = path + "/bin/cache/dart-sdk";
String systemDartSdk = System.getProperty("dart.sdk");
try {
System.setProperty("dart.sdk", dartSdkPath);
DartTestUtils.configureDartSdk(myModule, getTestRootDisposable(), true);
} finally {
System.setProperty("dart.sdk", systemDartSdk);
}
}

@Override
protected String getTestDataPath() {
return FlutterTestUtils.BASE_TEST_DATA_PATH + getBasePath();
return FlutterTestUtils.BASE_TEST_DATA_PATH + "/" + getBasePath();
}
}
23 changes: 23 additions & 0 deletions testSrc/io/flutter/sdk/FlutterSdkUtilTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,30 @@
*/
package io.flutter.sdk;

import com.intellij.execution.ExecutionException;
import com.jetbrains.lang.dart.sdk.DartSdk;
import io.flutter.FlutterCodeInsightFixtureTestCase;

public class FlutterSdkUtilTest extends FlutterCodeInsightFixtureTestCase {

public void testSetup() throws ExecutionException {
// All of FlutterTestUtils is exercised before getting here.
assertNull("Test jig setup failed", null);

// Verify Flutter SDK is installed correctly.
FlutterSdk flutterSdk = FlutterSdk.getFlutterSdk(myFixture.getProject());
assertNotNull(flutterSdk);
String path = System.getProperty("flutter.sdk");
assertEquals("Incorrect Flutter SDK path", flutterSdk.getHomePath(), path);

// Verify Dart SDK is the one distributed with Flutter.
DartSdk dartSdk = DartSdk.getDartSdk(myFixture.getProject());
assertNotNull(dartSdk);
assertTrue("Dart SDK not found in Flutter SDK installation", dartSdk.getHomePath().startsWith(flutterSdk.getHomePath()));

// Check SDK utilities.
String toolPath = FlutterSdkUtil.pathToFlutterTool(flutterSdk.getHomePath());
assertEquals("Incorrect path to flutter command", toolPath, path + "/bin/flutter");
assertTrue(FlutterSdkUtil.isFlutterSdkHome(path));
}
}
18 changes: 7 additions & 11 deletions testSrc/io/flutter/util/FlutterTestUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class FlutterTestUtils {
public static final String BASE_TEST_DATA_PATH = findTestDataPath();
public static final String SDK_HOME_PATH = BASE_TEST_DATA_PATH + "/sdk";

public static void configureDartSdk(@NotNull final Module module, @NotNull final Disposable disposable, final boolean realSdk) {
public static void configureFlutterSdk(@NotNull final Module module, @NotNull final Disposable disposable, final boolean realSdk) {
final String sdkHome;
if (realSdk) {
sdkHome = System.getProperty("flutter.sdk");
Expand All @@ -43,23 +43,19 @@ public static void configureDartSdk(@NotNull final Module module, @NotNull final
"the corresponding JUnit run configuration (Run | Edit Configurations)");
}
VfsRootAccess.allowRootAccess(disposable, sdkHome);
// Flutter execution threads
ThreadTracker.longRunningThreadCreated(ApplicationManager.getApplication(),
"ByteRequestSink.LinesWriterThread",
"ByteResponseStream.LinesReaderThread");
}
else {
sdkHome = SDK_HOME_PATH;
}

ApplicationManager.getApplication().runWriteAction(() -> {
FlutterSdkGlobalLibUtil.ensureDartSdkConfigured(sdkHome);
FlutterSdkGlobalLibUtil.enableDartSdk(module);
FlutterSdkGlobalLibUtil.ensureFlutterSdkConfigured(sdkHome);
FlutterSdkGlobalLibUtil.enableFlutterSdk(module);
});

Disposer.register(disposable, () -> ApplicationManager.getApplication().runWriteAction(() -> {
if (!module.isDisposed()) {
FlutterSdkGlobalLibUtil.disableDartSdk(Collections.singletonList(module));
FlutterSdkGlobalLibUtil.disableFlutterSdk(Collections.singletonList(module));
}

ApplicationLibraryTable libraryTable = ApplicationLibraryTable.getApplicationTable();
Expand All @@ -78,19 +74,19 @@ private static String findTestDataPath() {

final File f = new File("testData");
if (f.isDirectory()) {
// started from 'Dart-plugin' project
// started from flutter plugin project
return FileUtil.toSystemIndependentName(f.getAbsolutePath());
}

final String parentPath = PathUtil.getParentPath(PathManager.getHomePath());

if (new File(parentPath + "/intellij-plugins").isDirectory()) {
// started from IntelliJ IDEA Community Edition + Dart Plugin project
// started from IntelliJ IDEA Community Edition + flutter plugin project
return FileUtil.toSystemIndependentName(parentPath + "/intellij-plugins/flutter-intellij/testData");
}

if (new File(parentPath + "/contrib").isDirectory()) {
// started from IntelliJ IDEA Community + Dart Plugin project
// started from IntelliJ IDEA Community + flutter plugin project
return FileUtil.toSystemIndependentName(parentPath + "/contrib/flutter-intellij/testData");
}

Expand Down

0 comments on commit a9cfa4b

Please sign in to comment.