From 4e2aedb1f65aa4b6b03ee5b1d1db59aafe6d8055 Mon Sep 17 00:00:00 2001 From: Steve Messick Date: Wed, 24 Aug 2016 14:48:16 -0700 Subject: [PATCH] Basic unit test framework --- src/io/flutter/run/FlutterRunner.java | 1 + .../flutter/sdk/FlutterSdkGlobalLibUtil.java | 12 ++-------- .../FlutterCodeInsightFixtureTestCase.java | 23 ++++++++++++++++--- .../io/flutter/sdk/FlutterSdkUtilTest.java | 23 +++++++++++++++++++ testSrc/io/flutter/util/FlutterTestUtils.java | 18 ++++++--------- 5 files changed, 53 insertions(+), 24 deletions(-) diff --git a/src/io/flutter/run/FlutterRunner.java b/src/io/flutter/run/FlutterRunner.java index d14541d4c6..9dd7e0a990 100644 --- a/src/io/flutter/run/FlutterRunner.java +++ b/src/io/flutter/run/FlutterRunner.java @@ -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); } diff --git a/src/io/flutter/sdk/FlutterSdkGlobalLibUtil.java b/src/io/flutter/sdk/FlutterSdkGlobalLibUtil.java index 3517fb980d..20583530ec 100644 --- a/src/io/flutter/sdk/FlutterSdkGlobalLibUtil.java +++ b/src/io/flutter/sdk/FlutterSdkGlobalLibUtil.java @@ -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 modules) { - // TODO Implement disableDartSdk() + public static void disableFlutterSdk(List modules) { + // TODO Implement disableFlutterSdk() } public static void enableFlutterSdk(@NotNull final Module module) { diff --git a/testSrc/io/flutter/FlutterCodeInsightFixtureTestCase.java b/testSrc/io/flutter/FlutterCodeInsightFixtureTestCase.java index 07ce11ff52..f6d32ce94f 100644 --- a/testSrc/io/flutter/FlutterCodeInsightFixtureTestCase.java +++ b/testSrc/io/flutter/FlutterCodeInsightFixtureTestCase.java @@ -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(); } } diff --git a/testSrc/io/flutter/sdk/FlutterSdkUtilTest.java b/testSrc/io/flutter/sdk/FlutterSdkUtilTest.java index 144c060a2c..b0111d7e48 100644 --- a/testSrc/io/flutter/sdk/FlutterSdkUtilTest.java +++ b/testSrc/io/flutter/sdk/FlutterSdkUtilTest.java @@ -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)); + } } diff --git a/testSrc/io/flutter/util/FlutterTestUtils.java b/testSrc/io/flutter/util/FlutterTestUtils.java index 63ce35a51a..c44a05121f 100644 --- a/testSrc/io/flutter/util/FlutterTestUtils.java +++ b/testSrc/io/flutter/util/FlutterTestUtils.java @@ -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"); @@ -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(); @@ -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"); }