Skip to content

Commit 862ad9f

Browse files
committed
Test coverage, code cleanup, formatting.
1 parent 61935c4 commit 862ad9f

File tree

7 files changed

+61
-61
lines changed

7 files changed

+61
-61
lines changed

bin/kradle.dart

+2-2
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@ Future<void> main(List<String> args) async {
4848
print(taskService.displayKradlewHelpText);
4949
} else if (taskName == null) {
5050
print("received unknown task name: $firstArgument");
51-
print("use kradlew help for more information");
51+
print("use kradle help for more information");
5252
} else if (taskOptions == null) {
5353
print("received invalid task options: $args");
54-
print("use kradlew help for more information");
54+
print("use kradle help for more information");
5555
} else {
5656
print(await execute(Context(
5757
workingDirectory: Directory.current,

lib/src/cli/task_get_flutter.dart

+31
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1919
// SOFTWARE.
2020

21+
import "dart:ffi";
2122
import "dart:io";
2223

2324
import "package:meta/meta.dart";
@@ -103,6 +104,36 @@ class GetFlutterSDK extends Task<Directory> {
103104
"Failed to determine download URL for Flutter SDK: ${dist.prettyPrintedString}"));
104105
}
105106

107+
/// Find applicable [FlutterDistribution] for the current
108+
/// [OperatingSystem] and [Architecture] or throw [KlutterException].
109+
FlutterDistribution toFlutterDistributionOrThrow(
110+
{required VerifiedFlutterVersion version,
111+
required String pathToRoot,
112+
PlatformWrapper? platformWrapper}) {
113+
final p = platformWrapper ?? platform;
114+
OperatingSystem? os;
115+
116+
if (version.os != null) {
117+
os = version.os;
118+
} else if (p.isWindows) {
119+
os = OperatingSystem.windows;
120+
} else if (p.isMacos) {
121+
os = OperatingSystem.macos;
122+
} else if (p.isLinux) {
123+
os = OperatingSystem.linux;
124+
} else {
125+
throw KlutterException(
126+
"Current OS is not supported (supported: macos, windows or linux): ${Platform.operatingSystem}");
127+
}
128+
129+
final arch = version.arch ??
130+
(Abi.current().toString().contains("arm")
131+
? Architecture.arm64
132+
: Architecture.x64);
133+
134+
return FlutterDistribution(version: version.version, os: os!, arch: arch);
135+
}
136+
106137
Map<FlutterDistribution, String> get _compatibleFlutterVersions {
107138
final dist = [
108139
_windows(

lib/src/common/executor.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919
// SOFTWARE.
2020

2121
import "dart:io";
22-
import "package:klutter/klutter.dart";
2322

2423
import "exception.dart";
24+
import "utilities.dart";
2525

2626
/// Wrapper for using the commandline.
2727
class Executor {

lib/src/common/project.dart

+1-35
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,9 @@
1818
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1919
// SOFTWARE.
2020

21-
import "dart:ffi";
2221
import "dart:io";
2322

24-
import "../../klutter.dart";
25-
import "environment.dart";
26-
import "exception.dart";
27-
import "utilities.dart";
23+
import "common.dart";
2824

2925
/// Create and/or append the .klutter-plugins file to register a Klutter plugin.
3026
///
@@ -163,36 +159,6 @@ String findDependencyPath({
163159
return cachePath.normalize;
164160
}
165161

166-
/// Find applicable [FlutterDistribution] for the current
167-
/// [OperatingSystem] and [Architecture] or throw [KlutterException].
168-
FlutterDistribution toFlutterDistributionOrThrow(
169-
{required VerifiedFlutterVersion version,
170-
required String pathToRoot,
171-
PlatformWrapper? platformWrapper}) {
172-
final p = platformWrapper ?? platform;
173-
OperatingSystem? os;
174-
175-
if (version.os != null) {
176-
os = version.os;
177-
} else if (p.isWindows) {
178-
os = OperatingSystem.windows;
179-
} else if (p.isMacos) {
180-
os = OperatingSystem.macos;
181-
} else if (p.isLinux) {
182-
os = OperatingSystem.linux;
183-
} else {
184-
throw KlutterException(
185-
"Current OS is not supported (supported: macos, windows or linux): ${Platform.operatingSystem}");
186-
}
187-
188-
final arch = version.arch ??
189-
(Abi.current().toString().contains("arm")
190-
? Architecture.arm64
191-
: Architecture.x64);
192-
193-
return FlutterDistribution(version: version.version, os: os!, arch: arch);
194-
}
195-
196162
extension on String {
197163
/// Create a path to the root-project/.klutter-plugins file.
198164
/// If the file does not exist create it.

pubspec.yaml

+3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ version: 3.0.0
44
homepage: https://buijs.dev
55
repository: https://github.com/buijs-dev/klutter-dart
66

7+
executables:
8+
kradle:
9+
710
environment:
811
sdk: ">=2.17.6 <4.0.0"
912

test/src/cli/task_get_flutter_test.dart

+23
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,32 @@ void main() {
7676
expect(task.requiresDownload(realDirectory, false), false);
7777
expect(task.requiresDownload(realDirectory, true), true);
7878
});
79+
80+
test(
81+
"Verify toFlutterDistributionOrThrow throws exception for unsupported platform",
82+
() {
83+
expect(
84+
() => toFlutterDistributionOrThrow(
85+
platformWrapper: UnknownPlatform(),
86+
pathToRoot: Directory.systemTemp.resolveFolder("foo").absolutePath,
87+
version: const VerifiedFlutterVersion(
88+
Version(major: 1, minor: 1, patch: 1))),
89+
throwsA(predicate((e) => e is KlutterException)));
90+
});
7991
}
8092

8193
Context context(Map<TaskOption, String> options) => Context(
8294
taskName: TaskName.get,
8395
workingDirectory: Directory.current,
8496
taskOptions: options);
97+
98+
class UnknownPlatform extends PlatformWrapper {
99+
@override
100+
bool get isWindows => false;
101+
102+
@override
103+
bool get isMacos => false;
104+
105+
@override
106+
bool get isLinux => false;
107+
}

test/src/common/project_test.dart

-23
Original file line numberDiff line numberDiff line change
@@ -282,28 +282,5 @@ void main() {
282282
"${s}foo${s}bar$s.pub-cache${s}hosted${s}pub.dartlang.org${s}awesome_plugin${s}android${s}klutter");
283283
});
284284

285-
test(
286-
"Verify toFlutterDistributionOrThrow throws exception for unsupported platform",
287-
() {
288-
expect(
289-
() => toFlutterDistributionOrThrow(
290-
platformWrapper: UnknownPlatform(),
291-
pathToRoot: Directory.systemTemp.resolveFolder("foo").absolutePath,
292-
version: const VerifiedFlutterVersion(
293-
Version(major: 1, minor: 1, patch: 1))),
294-
throwsA(predicate((e) => e is KlutterException)));
295-
});
296-
297285
tearDownAll(() => root.deleteSync(recursive: true));
298286
}
299-
300-
class UnknownPlatform extends PlatformWrapper {
301-
@override
302-
bool get isWindows => false;
303-
304-
@override
305-
bool get isMacos => false;
306-
307-
@override
308-
bool get isLinux => false;
309-
}

0 commit comments

Comments
 (0)