From ea07864bc9ede51d5896c50112801a27a1210db7 Mon Sep 17 00:00:00 2001 From: Gillian <72627535+buijs-dev@users.noreply.github.com> Date: Sat, 4 May 2024 14:18:31 +0200 Subject: [PATCH] WIP release 3.0.0: - Code formatting - Add debugging for test failing in ci --- test/src/cli/context_test.dart | 52 +++++++++++++------ test/src/cli/task_add_test.dart | 6 +-- test/src/cli/task_get_flutter_test.dart | 36 ++++++------- test/src/cli/task_project_build_test.dart | 14 ++--- test/src/cli/task_project_init_test.dart | 40 ++++++-------- test/src/cli/task_service_test.dart | 7 ++- test/src/cli/task_test.dart | 10 ++-- test/src/common/config_test.dart | 30 ++++++----- test/src/common/project_kradle_test.dart | 12 +++-- test/src/common/project_test.dart | 1 - test/src/common/utilities_test.dart | 8 ++- test/src/consumer/android_test.dart | 29 +++++------ test/src/producer/android_test.dart | 28 +++++----- test/src/producer/kradle_test.dart | 7 +-- test/src/producer/platform_test.dart | 19 ++++--- test/src/producer/resource_test.dart | 18 ++++--- test/src/systemtest/e2e_test.dart | 50 +++++++++--------- test/src/systemtest/e2e_test_with_config.dart | 33 +++++++----- 18 files changed, 216 insertions(+), 184 deletions(-) diff --git a/test/src/cli/context_test.dart b/test/src/cli/context_test.dart index 654c8ce..e478b81 100644 --- a/test/src/cli/context_test.dart +++ b/test/src/cli/context_test.dart @@ -33,13 +33,18 @@ void main() { }); test("Verify parsing get flutter context", () { - final context = toContextOrNull(Directory.current, ["get", "flutter=3.10.6.macos.x64"]); + final context = + toContextOrNull(Directory.current, ["get", "flutter=3.10.6.macos.x64"]); expect(context != null, true); }); test("Verify parsing producer init context", () { - final context = toContextOrNull(Directory.current, ["init", "bom=2023.1.1.beta", "flutter=3.10.6.macos.arm64",]); + final context = toContextOrNull(Directory.current, [ + "init", + "bom=2023.1.1.beta", + "flutter=3.10.6.macos.arm64", + ]); expect(context != null, true); expect(context!.taskName, TaskName.init); @@ -49,33 +54,48 @@ void main() { }); test("When more than 2 arguments are supplied then context is null", () { - final context = toContextOrNull(Directory.current, ["init", "bom=2023.1.1.beta", "flutter=3.10.6.macos.arm64", "x=y"]); + final context = toContextOrNull(Directory.current, + ["init", "bom=2023.1.1.beta", "flutter=3.10.6.macos.arm64", "x=y"]); - expect(context == null, true, reason: "context should be null because too many arguments"); + expect(context == null, true, + reason: "context should be null because too many arguments"); }); test("When an argument is not a valid option value then context is null", () { - final context = toContextOrNull(Directory.current, ["init", "woot=2023.1.1.beta", "flutter=3.10.6.macos.arm64",]); - - expect(context == null, true, reason: "context should be null because argument is invalid"); + final context = toContextOrNull(Directory.current, [ + "init", + "woot=2023.1.1.beta", + "flutter=3.10.6.macos.arm64", + ]); + + expect(context == null, true, + reason: "context should be null because argument is invalid"); }); test("When get context has more than 1 argument, context is null", () { - final context = toContextOrNull(Directory.current, ["get", "this", "and" ]); + final context = toContextOrNull(Directory.current, ["get", "this", "and"]); - expect(context == null, true, reason: "context should be null because get can only have one argument"); + expect(context == null, true, + reason: + "context should be null because get can only have one argument"); }); - for (final value in ["3.10=6=10", "'3.10=6=10'", '"3.10=6=10"', " 3.10 "]) { + for (final value in [ + "3.10=6=10", + "'3.10=6=10'", + '"3.10=6=10"', + " 3.10 " + ]) { test("Verify parsing options", () { final options = toTaskOptionsOrNull(["flutter=$value"]); - expect(options != null, true, reason: "options should be parsed successfully"); + expect(options != null, true, + reason: "options should be parsed successfully"); final flutter = options![TaskOption.flutter]; expect(flutter, value.trim(), reason: "value should be stored"); }); } - for (final value in ["", " ","=", "= ", " = "]) { + for (final value in ["", " ", "=", "= ", " = "]) { test("Verify parsing options fails on missing value", () { expect(toTaskOptionsOrNull(["flutter$value"]), null); }); @@ -104,8 +124,11 @@ void main() { test("Verify copyWith merges options maps", () { final map1 = {TaskOption.bom: "da-bom", TaskOption.name: "name"}; - final map2 = {TaskOption.bom: "not-da-bom", TaskOption.klutterui:"union"}; - final context = Context(workingDirectory: Directory(""), taskName: TaskName.build, taskOptions: map1); + final map2 = {TaskOption.bom: "not-da-bom", TaskOption.klutterui: "union"}; + final context = Context( + workingDirectory: Directory(""), + taskName: TaskName.build, + taskOptions: map1); final copied = context.copyWith(taskOptions: map2); final copiedMap = copied.taskOptions; expect(copiedMap.length, 3); @@ -113,5 +136,4 @@ void main() { expect(copiedMap[TaskOption.name], map1[TaskOption.name]); expect(copiedMap[TaskOption.klutterui], map2[TaskOption.klutterui]); }); - } diff --git a/test/src/cli/task_add_test.dart b/test/src/cli/task_add_test.dart index 6da9c45..6b9f8c3 100644 --- a/test/src/cli/task_add_test.dart +++ b/test/src/cli/task_add_test.dart @@ -26,12 +26,12 @@ import "package:test/test.dart"; void main() { test("ConsumerAdd fails when option is not set", () async { - final result = await AddLibrary() - .execute(Context( + final result = await AddLibrary().execute(Context( taskName: TaskName.add, workingDirectory: Directory.current, taskOptions: {})); expect(result.isOk, false); - expect(result.message, "unable to run task add because: [missing value for option: lib]"); + expect(result.message, + "unable to run task add because: [missing value for option: lib]"); }); } diff --git a/test/src/cli/task_get_flutter_test.dart b/test/src/cli/task_get_flutter_test.dart index 6183b3f..df7ae77 100644 --- a/test/src/cli/task_get_flutter_test.dart +++ b/test/src/cli/task_get_flutter_test.dart @@ -25,43 +25,39 @@ import "package:klutter/src/cli/context.dart"; import "package:test/test.dart"; void main() { - - test("GetFlutterSDK downloads latest compatible if version is not set", () async { + test("GetFlutterSDK downloads latest compatible if version is not set", + () async { final task = GetFlutterSDK(); - final result = await task.execute(context({ - TaskOption.dryRun: "true" - })); + final result = await task.execute(context({TaskOption.dryRun: "true"})); expect(result.isOk, true); }); test("GetFlutterSDK fails when Flutter SDK is incorrect", () async { - final result = await GetFlutterSDK().execute(context({ - TaskOption.flutter : "0.0.0", - TaskOption.dryRun : "true" - })); + final result = await GetFlutterSDK().execute( + context({TaskOption.flutter: "0.0.0", TaskOption.dryRun: "true"})); expect(result.isOk, false); - expect(result.message, "unable to run task get because: [invalid value for option flutter: invalid flutter version (supported versions are: (3.0.5, 3.3.10, 3.7.12, 3.10.6)): 0.0.0]"); + expect(result.message, + "unable to run task get because: [invalid value for option flutter: invalid flutter version (supported versions are: (3.0.5, 3.3.10, 3.7.12, 3.10.6)): 0.0.0]"); }); - test("GetFlutterSDK uses OS from version if present in version String", () async { + test("GetFlutterSDK uses OS from version if present in version String", + () async { final task = GetFlutterSDK(); final root = Directory.systemTemp; root.resolveFile("kradle.env") ..createSync() ..writeAsStringSync("cache=${root.absolutePath}"); final result = await task.execute(context({ - TaskOption.flutter : "3.3.10.linux.x64", - TaskOption.dryRun : "true", - TaskOption.root : root.absolutePath, + TaskOption.flutter: "3.3.10.linux.x64", + TaskOption.dryRun: "true", + TaskOption.root: root.absolutePath, })); expect(result.isOk, true, reason: result.message ?? ""); }); - } -Context context(Map options) => - Context( - taskName: TaskName.get, - workingDirectory: Directory.current, - taskOptions: options); \ No newline at end of file +Context context(Map options) => Context( + taskName: TaskName.get, + workingDirectory: Directory.current, + taskOptions: options); diff --git a/test/src/cli/task_project_build_test.dart b/test/src/cli/task_project_build_test.dart index cbed699..1f7ca13 100644 --- a/test/src/cli/task_project_build_test.dart +++ b/test/src/cli/task_project_build_test.dart @@ -27,8 +27,6 @@ import "package:test/test.dart"; import "../common/executor_test.dart"; void main() { - - test("Verify build command executes gradlew clean build", () { final pathToRoot = Directory("${Directory.systemTemp.absolute.path}/build_test".normalize) @@ -38,11 +36,13 @@ void main() { expectedPathToWorkingDirectory: pathToRoot.absolutePath, expectedCommand: "gradlew clean build -p platform"); - BuildProject(executor: executor).toBeExecuted(Context( - workingDirectory: pathToRoot, - taskName: TaskName.build, - taskOptions: { }, - ), {}); + BuildProject(executor: executor).toBeExecuted( + Context( + workingDirectory: pathToRoot, + taskName: TaskName.build, + taskOptions: {}, + ), + {}); expect(executor.run().stdout, "Test OK!"); }); diff --git a/test/src/cli/task_project_init_test.dart b/test/src/cli/task_project_init_test.dart index 1a5d30e..1e4c1d4 100644 --- a/test/src/cli/task_project_init_test.dart +++ b/test/src/cli/task_project_init_test.dart @@ -25,7 +25,6 @@ import "package:klutter/src/cli/context.dart"; import "package:test/test.dart"; void main() { - test("Verify init in consumer project skips producer init", () async { final pathToRoot = Directory("${Directory.systemTemp.absolute.path}/build_test".normalize) @@ -39,30 +38,25 @@ void main() { group: "my.org", ); + final pathToConsumer = project.resolveFolder("example"); final task = ProjectInit(); - final context = Context(workingDirectory: project.resolveFolder("example"), - taskName: TaskName.init, - taskOptions: {}); + final context = Context( + workingDirectory: pathToConsumer, + taskName: TaskName.init, + taskOptions: {}, + ); + final result = await task.execute(context); expect(result.isOk, true); - - final mainDartFile = File("${project.absolutePath}/example/lib/main.dart" - .normalize); - expect(mainDartFile.existsSync(), - true, - reason: "example/lib/main.dart file should exist"); - - expect(mainDartFile - .readAsStringSync() - .contains('String _greeting = "There shall be no greeting for now!";'), - true, - reason: "main.dart content is overwritten"); - - final registry = - File("${project.absolutePath}/example/.klutter-plugins".normalize); - - expect(registry.existsSync(), true, - reason: "klutter-plugins file should be created"); - + final file = pathToConsumer.resolveFile("/lib/main.dart"); + var reason = "example/lib/main.dart file should exist"; + expect(file.existsSync(), true, reason: reason); + const content = 'String _greeting = "There shall be no greeting for now!";'; + final containsContent = file.readAsStringSync().contains(content); + reason = "main.dart content is overwritten:\n${file.readAsStringSync()}"; + expect(containsContent, true, reason: reason); + final registry = pathToConsumer.resolveFile(".klutter-plugins"); + reason = "klutter-plugins file should be created"; + expect(registry.existsSync(), true, reason: reason); }); } diff --git a/test/src/cli/task_service_test.dart b/test/src/cli/task_service_test.dart index 1fee35c..1cd99d1 100644 --- a/test/src/cli/task_service_test.dart +++ b/test/src/cli/task_service_test.dart @@ -35,8 +35,9 @@ void main() { expect(tasks.length, 6); - expect(tasks.getTask(TaskName.add).toString(), - "add\n lib (Required) name of the library to add.\n" + expect( + tasks.getTask(TaskName.add).toString(), + "add\n lib (Required) name of the library to add.\n" " root (Optional) the klutter project root directory. Defaults to \'current working directory\'.\n", ); @@ -44,7 +45,6 @@ void main() { tasks.getTask(TaskName.init).toString(), "init\n bom (Optional) the klutter gradle version. Defaults to '2024.1.1.beta'.\n flutter (Optional) the flutter sdk version in format major.minor.patch. Defaults to '3.10.6'.\n root (Optional) the klutter project root directory. Defaults to \'current working directory\'.\n", ); - }); test("Verify exception is thrown if duplicate tasks are found", () { @@ -106,7 +106,6 @@ void main() { tearDownAll(() => pathToRoot.deleteSync(recursive: true)); } - extension on Set { Task getTask(TaskName taskName) => firstWhere((task) { return task.taskName == taskName; diff --git a/test/src/cli/task_test.dart b/test/src/cli/task_test.dart index 7d975fc..f610bb2 100644 --- a/test/src/cli/task_test.dart +++ b/test/src/cli/task_test.dart @@ -26,9 +26,10 @@ import "package:test/test.dart"; void main() { test("When a task fails with a KlutterException, it is caught", () async { - final result = await _ExplodingTask().execute( - Context(workingDirectory: Directory.current, taskName: TaskName.build, taskOptions: {}) - ); + final result = await _ExplodingTask().execute(Context( + workingDirectory: Directory.current, + taskName: TaskName.build, + taskOptions: {})); expect(result.isOk, false); expect(result.message, "BOOM!"); }); @@ -41,5 +42,4 @@ class _ExplodingTask extends Task { Future toBeExecuted(Context context, Map options) { throw KlutterException("BOOM!"); } - -} \ No newline at end of file +} diff --git a/test/src/common/config_test.dart b/test/src/common/config_test.dart index 28b75a5..b730f7c 100644 --- a/test/src/common/config_test.dart +++ b/test/src/common/config_test.dart @@ -23,24 +23,31 @@ import "package:test/test.dart"; void main() { test("Valid Flutter versions are returned as VerifiedFlutterVersion", () { - for(final version in supportedFlutterVersions.keys) { - expect(version.verifyFlutterVersion != null, true, reason: "Version should be valid: $version"); - expect("$version.windows.x64".verifyFlutterVersion != null, true, reason: "Version should be valid: $version.windows.x64"); - expect("$version.macos.x64".verifyFlutterVersion != null, true, reason: "Version should be valid: $version.macos.x64"); - expect("$version.linux.x64".verifyFlutterVersion != null, true, reason: "Version should be valid: $version.linux.x64"); - expect("$version.windows.arm64".verifyFlutterVersion != null, true, reason: "Version should be valid: $version.windows.arm64"); - expect("$version.macos.arm64".verifyFlutterVersion != null, true, reason: "Version should be valid: $version.macos.arm64"); - expect("$version.linux.arm64".verifyFlutterVersion != null, true, reason: "Version should be valid: $version.linux.arm64"); + for (final version in supportedFlutterVersions.keys) { + expect(version.verifyFlutterVersion != null, true, + reason: "Version should be valid: $version"); + expect("$version.windows.x64".verifyFlutterVersion != null, true, + reason: "Version should be valid: $version.windows.x64"); + expect("$version.macos.x64".verifyFlutterVersion != null, true, + reason: "Version should be valid: $version.macos.x64"); + expect("$version.linux.x64".verifyFlutterVersion != null, true, + reason: "Version should be valid: $version.linux.x64"); + expect("$version.windows.arm64".verifyFlutterVersion != null, true, + reason: "Version should be valid: $version.windows.arm64"); + expect("$version.macos.arm64".verifyFlutterVersion != null, true, + reason: "Version should be valid: $version.macos.arm64"); + expect("$version.linux.arm64".verifyFlutterVersion != null, true, + reason: "Version should be valid: $version.linux.arm64"); } }); test("Invalid Flutter versions are returned as null", () { - expect("thisIsNotAFlutterVersion".verifyFlutterVersion == null, true); + expect("thisIsNotAFlutterVersion".verifyFlutterVersion == null, true); }); group("Verify version sort order is descending by default", () { void testSorting(String a, String b, List expected) { - test("$a > $b",() { + test("$a > $b", () { final sortedList = [a.toVersion, b.toVersion]..sort(); expect(sortedList.map((e) => e.prettyPrint).toList(), expected); }); @@ -51,7 +58,6 @@ void main() { testSorting("1.0.0", "1.0.1", ["1.0.1", "1.0.0"]); testSorting("0.1.0", "0.0.1", ["0.1.0", "0.0.1"]); }); - } extension on String { @@ -63,4 +69,4 @@ extension on String { patch: int.parse(splitted[2]), ); } -} \ No newline at end of file +} diff --git a/test/src/common/project_kradle_test.dart b/test/src/common/project_kradle_test.dart index 5287549..16c3931 100644 --- a/test/src/common/project_kradle_test.dart +++ b/test/src/common/project_kradle_test.dart @@ -210,8 +210,10 @@ void main() { test( "When kradle.env contains cache property and the directory is not found then it is created", () { - final dotKradleDirectory = Directory.systemTemp.resolveFolder(".kradle")..createSync(); - final cacheDirectory = Directory("${dotKradleDirectory.absolutePath}/cache".normalize); + final dotKradleDirectory = Directory.systemTemp.resolveFolder(".kradle") + ..createSync(); + final cacheDirectory = + Directory("${dotKradleDirectory.absolutePath}/cache".normalize); final rootDirectory = _newProjectFolder; setPlatformMacos(rootDirectory); createCacheFolder(rootDirectory); @@ -220,7 +222,7 @@ void main() { contents: "cache=${cacheDirectory.absolutePath}", ); - if(cacheDirectory.existsSync()) { + if (cacheDirectory.existsSync()) { cacheDirectory.deleteSync(); } @@ -230,7 +232,7 @@ void main() { rootDirectory.kradleCache; // then - expect(cacheDirectory.existsSync(), true); + expect(cacheDirectory.existsSync(), true); }); tearDownAll(() { @@ -256,4 +258,4 @@ class FakePlatformWrapper extends PlatformWrapper { set environment(Map value) { _env = value; } -} \ No newline at end of file +} diff --git a/test/src/common/project_test.dart b/test/src/common/project_test.dart index bff9ac9..afcff96 100644 --- a/test/src/common/project_test.dart +++ b/test/src/common/project_test.dart @@ -149,7 +149,6 @@ void main() { }); test("Verify findKlutterBomVersion", () { - // Verify klutterBomVersion is null if kradle.yaml File does not exist. expect(findKlutterBomVersion(root.path), null); diff --git a/test/src/common/utilities_test.dart b/test/src/common/utilities_test.dart index 03ad59d..d77e636 100644 --- a/test/src/common/utilities_test.dart +++ b/test/src/common/utilities_test.dart @@ -33,7 +33,11 @@ void main() { }); test("Verify _substitute correctly normalizes a path", () { - expect(File("foo/bar/res/../../pikachu").normalizeToFile.path.endsWith("foo${Platform.pathSeparator}pikachu"), true); + expect( + File("foo/bar/res/../../pikachu") + .normalizeToFile + .path + .endsWith("foo${Platform.pathSeparator}pikachu"), + true); }); - } diff --git a/test/src/consumer/android_test.dart b/test/src/consumer/android_test.dart index b137443..6790325 100644 --- a/test/src/consumer/android_test.dart +++ b/test/src/consumer/android_test.dart @@ -357,8 +357,7 @@ void main() { root.deleteSync(recursive: true); }); - test("Verify min and compile SDK are updated in build.gradle file", - () { + test("Verify min and compile SDK are updated in build.gradle file", () { final root = Directory("${Directory.systemTemp.path}${s}apl5") ..createSync(); @@ -373,28 +372,27 @@ void main() { throwsA(predicate((e) => e is KlutterException && e.cause.contains( - "Failed to set 'compileSdk' in the root/android/build.gradle file") - ))); + "Failed to set 'compileSdk' in the root/android/build.gradle file")))); root.deleteSync(recursive: true); }); test( "Verify exception is thrown if build.gradle does not exist when setting android SDK settings", - () { - final root = Directory("${Directory.systemTemp.path}${s}apl10") - ..createSync(); + () { + final root = Directory("${Directory.systemTemp.path}${s}apl10") + ..createSync(); - final android = Directory("${root.path}${s}android")..createSync(); + final android = Directory("${root.path}${s}android")..createSync(); - expect( - () => setAndroidSdkConstraints(android.absolute.path), - throwsA(predicate((e) => + expect( + () => setAndroidSdkConstraints(android.absolute.path), + throwsA(predicate((e) => e is KlutterException && - e.cause.startsWith("Missing build.gradle file in folder")))); + e.cause.startsWith("Missing build.gradle file in folder")))); - root.deleteSync(recursive: true); - }); + root.deleteSync(recursive: true); + }); test( "Verify exception is thrown if root/android/app/build.gradle does not exist", @@ -404,7 +402,8 @@ void main() { final android = Directory("${root.path}${s}android")..createSync(); - expect(() => writeAndroidAppBuildGradleFile( + expect( + () => writeAndroidAppBuildGradleFile( pathToAndroid: android.absolute.path, packageName: "", pluginName: ""), diff --git a/test/src/producer/android_test.dart b/test/src/producer/android_test.dart index a04d86c..0eeee28 100644 --- a/test/src/producer/android_test.dart +++ b/test/src/producer/android_test.dart @@ -34,7 +34,7 @@ void main() { test("Verify exception is thrown if root/android does not exist", () { expect( () => writeBuildGradleFile( - pluginName: pluginName, + pluginName: pluginName, pluginVersion: pluginVersion, packageName: packageName, klutterBomVersion: "2023.3.1", @@ -56,11 +56,11 @@ void main() { expect( () => writeBuildGradleFile( - pluginName: pluginName, + pluginName: pluginName, pluginVersion: pluginVersion, packageName: packageName, pathToAndroid: android.path, - klutterBomVersion: "2023.3.1", + klutterBomVersion: "2023.3.1", ), throwsA(predicate((e) => e is KlutterException && @@ -176,10 +176,10 @@ void main() { test("Verify exception is thrown if root/android does not exist", () { expect( - () => - writeAndroidPlugin( - pluginName: pluginName, - packageName: packageName, pathToAndroid: "fake"), + () => writeAndroidPlugin( + pluginName: pluginName, + packageName: packageName, + pathToAndroid: "fake"), throwsA(predicate((e) => e is KlutterException && e.cause.startsWith("Path does not exist:") && @@ -190,10 +190,9 @@ void main() { final android = Directory("${Directory.systemTemp.path}${s}wag1") ..createSync(recursive: true); expect( - () => - setGradleWrapperVersion(pathToAndroid: android.absolutePath), + () => setGradleWrapperVersion(pathToAndroid: android.absolutePath), throwsA(predicate((e) => - e is KlutterException && + e is KlutterException && e.cause.contains("Missing gradle-wrapper.properties file in")))); }); @@ -209,13 +208,12 @@ void main() { expect( () => writeAndroidPlugin( - pluginName: pluginName, + pluginName: pluginName, packageName: packageName, pathToAndroid: android.path, ), throwsA(predicate((e) => - e is KlutterException && - e.cause.startsWith("Missing src")))); + e is KlutterException && e.cause.startsWith("Missing src")))); root.deleteSync(recursive: true); }); @@ -234,7 +232,7 @@ void main() { expect( () => writeAndroidPlugin( - pluginName: pluginName, + pluginName: pluginName, packageName: packageName, pathToAndroid: android.path, ), @@ -258,7 +256,7 @@ void main() { expect( () => writeAndroidPlugin( - pluginName: pluginName, + pluginName: pluginName, packageName: packageName, pathToAndroid: android.path, ), diff --git a/test/src/producer/kradle_test.dart b/test/src/producer/kradle_test.dart index c737598..6587e2a 100644 --- a/test/src/producer/kradle_test.dart +++ b/test/src/producer/kradle_test.dart @@ -45,12 +45,9 @@ void main() { final env = File("${root.path}/kradle.env").normalizeToFile; final yaml = File("${root.path}/kradle.yaml").normalizeToFile; - expect(env.existsSync(), true, - reason: "kradle.env should exist"); - expect(yaml.existsSync(), true, - reason: "kradle.yaml should exist"); + expect(env.existsSync(), true, reason: "kradle.env should exist"); + expect(yaml.existsSync(), true, reason: "kradle.yaml should exist"); root.deleteSync(recursive: true); }); - } diff --git a/test/src/producer/platform_test.dart b/test/src/producer/platform_test.dart index 9382489..39192cc 100644 --- a/test/src/producer/platform_test.dart +++ b/test/src/producer/platform_test.dart @@ -117,9 +117,10 @@ void main() { test("Verify exception is thrown if root does not exist", () { expect( () => writeRootBuildGradleFile( - pathToRoot: "fake", - pluginName: "some_plugin", - klutterBomVersion: "2023.3.1",), + pathToRoot: "fake", + pluginName: "some_plugin", + klutterBomVersion: "2023.3.1", + ), throwsA(predicate((e) => e is KlutterException && e.cause.startsWith("Path does not exist:") && @@ -157,7 +158,8 @@ void main() { classpath("dev.buijs.klutter:gradle") } } - """.replaceAll(" ", "")); + """ + .replaceAll(" ", "")); root.deleteSync(recursive: true); }); @@ -194,7 +196,8 @@ void main() { classpath("dev.buijs.klutter:gradle") } } - """.replaceAll(" ", "")); + """ + .replaceAll(" ", "")); root.deleteSync(recursive: true); }); @@ -262,8 +265,7 @@ void main() { root.resolveFile("kradle.yaml") ..maybeCreate - ..writeAsStringSync("flutter-version: '3.0.5.macos.arm64'") - ; + ..writeAsStringSync("flutter-version: '3.0.5.macos.arm64'"); createPlatformModule( pathToRoot: root.path, @@ -428,7 +430,8 @@ void main() { mustRunAfter(tasks.named("kspCommonMainKotlinMetadata")) } } - """.replaceAll(" ", ""), + """ + .replaceAll(" ", ""), platformBuildGradle.readAsStringSync().replaceAll(" ", ""), ); diff --git a/test/src/producer/resource_test.dart b/test/src/producer/resource_test.dart index 6342c2c..89b5162 100644 --- a/test/src/producer/resource_test.dart +++ b/test/src/producer/resource_test.dart @@ -22,18 +22,22 @@ import "package:klutter/src/producer/resource.dart"; import "package:test/test.dart"; void main() { - test("When Platform is windows then first '/' character of a resource path is removed", () async { + test( + "When Platform is windows then first '/' character of a resource path is removed", + () async { final resource = await loadResource( - uri: Uri.parse("package:klutter/res/gradlew.bat"), - targetRelativeToRoot: "", - filename: "gradlew.bat", - isWindows: true, - ); + uri: Uri.parse("package:klutter/res/gradlew.bat"), + targetRelativeToRoot: "", + filename: "gradlew.bat", + isWindows: true, + ); expect(resource.pathToSource.startsWith("/"), false); }); - test("When Platform is NOT windows then first '/' character of a resource path is NOT removed", () async { + test( + "When Platform is NOT windows then first '/' character of a resource path is NOT removed", + () async { final resource = await loadResource( uri: Uri.parse("package:klutter/res/gradlew.bat"), targetRelativeToRoot: "", diff --git a/test/src/systemtest/e2e_test.dart b/test/src/systemtest/e2e_test.dart index a18fef8..117067a 100644 --- a/test/src/systemtest/e2e_test.dart +++ b/test/src/systemtest/e2e_test.dart @@ -47,8 +47,8 @@ void main() { try { test("end-to-end test", () async { /// Run a Klutter task without an existing Flutter project - final result = await sut.execute( - toContextOrNull(producerPlugin,["add", "lib=foo"])!); + final result = await sut + .execute(toContextOrNull(producerPlugin, ["add", "lib=foo"])!); expect( result.contains("finished unsuccessfully"), @@ -60,7 +60,9 @@ void main() { await createFlutterPlugin( organisation: organisation, pluginName: pluginName, - root: Directory(pathToRoot.absolutePath).normalizeToDirectory.absolutePath, + root: Directory(pathToRoot.absolutePath) + .normalizeToDirectory + .absolutePath, ); expect(producerPlugin.existsSync(), true, @@ -159,20 +161,19 @@ void main() { "Plugin should be created in: '${producerPlugin.absolute.path}'"); /// Example/lib/main.dart file should be created. - final mainDartFile = File("${producerPlugin.absolutePath}/example/lib/main.dart" - .normalize); - expect(mainDartFile.existsSync(), - true, + final mainDartFile = File( + "${producerPlugin.absolutePath}/example/lib/main.dart".normalize); + expect(mainDartFile.existsSync(), true, reason: "example/lib/main.dart file should exist"); - expect(mainDartFile - .readAsStringSync() - .contains('String _greeting = "There shall be no greeting for now!";'), + expect( + mainDartFile.readAsStringSync().contains( + 'String _greeting = "There shall be no greeting for now!";'), true, - reason: "main.dart content is overwritten"); + reason: "main.dart content is overwritten"); final registry = - File("${consumerPlugin.absolutePath}/.klutter-plugins".normalize); + File("${consumerPlugin.absolutePath}/.klutter-plugins".normalize); expect(registry.existsSync(), true, reason: "klutter-plugins file should be created"); @@ -184,7 +185,6 @@ void main() { reason: "add task should have added plugin name to the .klutter-plugins file: ${registry.readAsStringSync()}"); }); - } catch (e, s) { print(s); } @@ -200,19 +200,19 @@ Future createFlutterPlugin({ String? config, }) async { final context = Context( - workingDirectory: Directory(root), - taskName: TaskName.create, + workingDirectory: Directory(root), + taskName: TaskName.create, taskOptions: { - TaskOption.root:root, - TaskOption.group:organisation, - TaskOption.name:pluginName, - TaskOption.flutter:"3.10.6", - TaskOption.klutter:"local@${Directory.current.resolveFolder("./../".normalize).absolutePath}", - }); + TaskOption.root: root, + TaskOption.group: organisation, + TaskOption.name: pluginName, + TaskOption.flutter: "3.10.6", + TaskOption.klutter: + "local@${Directory.current.resolveFolder("./../".normalize).absolutePath}", + }); final res = await sut.toTask(context)!.execute(context); - if(!res.isOk) { - assert(res.isOk,res.message); + if (!res.isOk) { + assert(res.isOk, res.message); } - -} \ No newline at end of file +} diff --git a/test/src/systemtest/e2e_test_with_config.dart b/test/src/systemtest/e2e_test_with_config.dart index 30c69cb..eed63e0 100644 --- a/test/src/systemtest/e2e_test_with_config.dart +++ b/test/src/systemtest/e2e_test_with_config.dart @@ -42,7 +42,6 @@ void main() { Directory("${pathToRoot.absolute.path}/$pluginName".normalize); test("end-to-end test", () async { - /// Create Flutter plugin project. await createFlutterPlugin( organisation: organisation, @@ -60,25 +59,35 @@ void main() { ); /// Root build.gradle file should be created. - final rootBuildGradle = File("${producerPlugin.absolutePath}/build.gradle.kts".normalize); - expect(rootBuildGradle.existsSync(), true, reason: "root/build.gradle.kts should exist"); + final rootBuildGradle = + File("${producerPlugin.absolutePath}/build.gradle.kts".normalize); + expect(rootBuildGradle.existsSync(), true, + reason: "root/build.gradle.kts should exist"); expect(rootBuildGradle.readAsStringSync().contains("bom:9999.1.1"), true, - reason: "root/build.gradle.kts should contains BOM version from config."); + reason: + "root/build.gradle.kts should contains BOM version from config."); /// Root settings.gradle file should be created. - expect(File("${producerPlugin.absolutePath}/settings.gradle.kts".normalize).existsSync(), - true, reason: "root/settings.gradle.kts should exist"); + expect( + File("${producerPlugin.absolutePath}/settings.gradle.kts".normalize) + .existsSync(), + true, + reason: "root/settings.gradle.kts should exist"); /// Android/Klutter build.gradle file should be created. - final androidKlutterBuildGradle = File("${producerPlugin.absolutePath}/android/klutter/build.gradle.kts".normalize); - expect(androidKlutterBuildGradle.existsSync(), true, reason: "android/klutter/build.gradle.kts should exist"); + final androidKlutterBuildGradle = File( + "${producerPlugin.absolutePath}/android/klutter/build.gradle.kts" + .normalize); + expect(androidKlutterBuildGradle.existsSync(), true, + reason: "android/klutter/build.gradle.kts should exist"); /// Android/Klutter build.gradle file should be created. - final androidBuildGradle = File("${producerPlugin.absolutePath}/android/build.gradle".normalize); - expect(androidBuildGradle.existsSync(), true, reason: "android/build.gradle.kts should exist"); + final androidBuildGradle = + File("${producerPlugin.absolutePath}/android/build.gradle".normalize); + expect(androidBuildGradle.existsSync(), true, + reason: "android/build.gradle.kts should exist"); expect(androidBuildGradle.readAsStringSync().contains("bom:9999.1.1"), true, reason: "android/build.gradle should contain BOM version from config."); - }); tearDownAll(() => pathToRoot.deleteSync(recursive: true)); @@ -93,4 +102,4 @@ void createConfigYaml({ ..writeAsStringSync(""" bom-version:9999.1.1 """); -} \ No newline at end of file +}