Skip to content

Commit 5a6250c

Browse files
committed
fix: Enhance Makefile testing commands and improve Unity controller error handling
This commit updates the Makefile to skip testing for packages without test directories and modifies the static analysis and test commands to use `--no-fatal-infos` for better error handling. Additionally, it refines the Unity controller implementation by replacing `print` statements with `debugPrint` for improved logging consistency. A new method for setting the streaming cache path is added to the Unreal controller, and minor adjustments are made to various test files for consistency and clarity.
1 parent 7c43836 commit 5a6250c

File tree

10 files changed

+74
-26
lines changed

10 files changed

+74
-26
lines changed

Makefile

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,12 @@ setup: bootstrap ## Alias for bootstrap (install all dependencies)
4444
test: ## Run all tests across workspace packages
4545
@echo "$(BLUE)Running tests across workspace...$(NC)"
4646
@for pkg in $(PACKAGES) $(EXAMPLE); do \
47-
echo "$(BLUE)Testing $$pkg...$(NC)"; \
48-
cd $$pkg && flutter test && cd - > /dev/null || exit 1; \
47+
if [ -d "$$pkg/test" ]; then \
48+
echo "$(BLUE)Testing $$pkg...$(NC)"; \
49+
cd $$pkg && flutter test && cd - > /dev/null || exit 1; \
50+
else \
51+
echo "$(YELLOW)Skipping $$pkg (no tests)$(NC)"; \
52+
fi; \
4953
done
5054
@echo "$(GREEN)✓ All tests passed!$(NC)"
5155

@@ -66,7 +70,7 @@ analyze: ## Run static analysis across workspace
6670
@echo "$(BLUE)Running static analysis across workspace...$(NC)"
6771
@for pkg in $(PACKAGES) $(EXAMPLE); do \
6872
echo "$(BLUE)Analyzing $$pkg...$(NC)"; \
69-
cd $$pkg && flutter analyze && cd - > /dev/null || exit 1; \
73+
cd $$pkg && flutter analyze --no-fatal-infos && cd - > /dev/null || exit 1; \
7074
done
7175
@echo "$(GREEN)✓ No issues found!$(NC)"
7276

@@ -86,12 +90,16 @@ lint: ## Run all linting checks (format, analyze, test) across workspace
8690
@dart format --set-exit-if-changed . > /dev/null 2>&1 && echo "$(GREEN) ✓ Format check passed$(NC)" || (echo "$(RED) ✗ Format check failed$(NC)" && exit 1)
8791
@echo "2. Running static analysis..."
8892
@for pkg in $(PACKAGES) $(EXAMPLE); do \
89-
cd $$pkg && flutter analyze > /dev/null 2>&1 && cd - > /dev/null || (echo "$(RED) ✗ Analysis failed in $$pkg$(NC)" && exit 1); \
93+
(cd $$pkg && flutter analyze --no-fatal-infos > /dev/null 2>&1) || (echo "$(RED) ✗ Analysis failed in $$pkg$(NC)" && exit 1); \
9094
done
9195
@echo "$(GREEN) ✓ Analysis passed$(NC)"
9296
@echo "3. Running tests..."
9397
@for pkg in $(PACKAGES) $(EXAMPLE); do \
94-
cd $$pkg && flutter test > /dev/null 2>&1 && cd - > /dev/null || (echo "$(RED) ✗ Tests failed in $$pkg$(NC)" && exit 1); \
98+
if [ -d "$$pkg/test" ]; then \
99+
(cd $$pkg && flutter test > /dev/null 2>&1) || (echo "$(RED) ✗ Tests failed in $$pkg$(NC)" && exit 1); \
100+
else \
101+
echo "$(YELLOW) ⊘ Skipping $$pkg (no tests)$(NC)"; \
102+
fi; \
95103
done
96104
@echo "$(GREEN) ✓ Tests passed$(NC)"
97105
@echo ""

engines/unity/dart/lib/src/unity_controller.dart

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import 'dart:async';
2+
import 'package:flutter/foundation.dart';
23
import 'package:flutter/services.dart';
34
import 'package:gameframework/gameframework.dart';
45

@@ -150,11 +151,11 @@ class UnityController implements GameEngineController {
150151
if (attempt == 0) {
151152
// First attempt is expected to fail, don't log
152153
} else if (attempt < 3) {
153-
print(
154+
debugPrint(
154155
'Platform view not ready, retrying in ${delayMs}ms (attempt ${attempt + 1}/$maxAttempts)');
155156
} else {
156-
print(
157-
'Warning: Platform view still not ready after ${attempt} attempts, retrying in ${delayMs}ms');
157+
debugPrint(
158+
'Warning: Platform view still not ready after $attempt attempts, retrying in ${delayMs}ms');
158159
}
159160

160161
await Future.delayed(Duration(milliseconds: delayMs));
@@ -271,11 +272,11 @@ class UnityController implements GameEngineController {
271272
if (attempt == 0) {
272273
// First attempt failure is expected, don't log
273274
} else if (attempt < 3) {
274-
print(
275+
debugPrint(
275276
'Platform view not ready for create(), retrying in ${delayMs}ms (attempt ${attempt + 1}/$maxAttempts)');
276277
} else {
277-
print(
278-
'Warning: Platform view still not ready for create() after ${attempt} attempts, retrying in ${delayMs}ms');
278+
debugPrint(
279+
'Warning: Platform view still not ready for create() after $attempt attempts, retrying in ${delayMs}ms');
279280
}
280281

281282
await Future.delayed(Duration(milliseconds: delayMs));

engines/unity/dart/lib/src/unity_controller_web.dart

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import 'dart:async';
2+
// ignore: deprecated_member_use, avoid_web_libraries_in_flutter
23
import 'dart:html' as html;
4+
// ignore: deprecated_member_use, avoid_web_libraries_in_flutter
35
import 'dart:js' as js;
6+
import 'package:flutter/foundation.dart';
47
import 'package:gameframework/gameframework.dart';
58

69
/// Unity WebGL-specific implementation of GameEngineController
@@ -288,6 +291,14 @@ class UnityControllerWeb implements GameEngineController {
288291
dispose();
289292
}
290293

294+
@override
295+
Future<void> setStreamingCachePath(String path) async {
296+
// WebGL doesn't support local file system cache paths
297+
// Streaming assets are loaded via HTTP from the web server
298+
// This is a no-op for web platform
299+
return;
300+
}
301+
291302
@override
292303
void dispose() {
293304
if (_disposed) return;
@@ -368,7 +379,7 @@ class UnityControllerWeb implements GameEngineController {
368379
_unityInstance!.callMethod('SetFullscreen', [fullscreen ? 1 : 0]);
369380
} catch (e) {
370381
// Fullscreen might not be supported
371-
print('Failed to set fullscreen: $e');
382+
debugPrint('Failed to set fullscreen: $e');
372383
}
373384
}
374385
}

engines/unity/dart/lib/src/unity_engine_plugin.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import 'package:gameframework/gameframework.dart';
2-
import 'unity_controller.dart';
32
import 'unity_controller_web.dart' if (dart.library.io) 'unity_controller.dart'
43
as platform;
54

engines/unity/dart/test/unity_controller_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ void main() {
246246

247247
group('createUnityController', () {
248248
test('should create UnityController instance', () {
249-
final config = const GameEngineConfig();
249+
const config = GameEngineConfig();
250250
final controller = createUnityController(1, config);
251251

252252
expect(controller, isA<UnityController>());

engines/unreal/dart/lib/src/unreal_controller.dart

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,24 @@ class UnrealController implements GameEngineController {
428428
}
429429
}
430430

431+
@override
432+
Future<void> setStreamingCachePath(String path) async {
433+
_throwIfDisposed();
434+
435+
try {
436+
await _channel.invokeMethod('engine#setStreamingCachePath', {
437+
'path': path,
438+
});
439+
} catch (e) {
440+
throw EngineCommunicationException(
441+
'Failed to set streaming cache path: $e',
442+
target: 'UnrealController',
443+
method: 'setStreamingCachePath',
444+
engineType: engineType,
445+
);
446+
}
447+
}
448+
431449
@override
432450
Future<void> dispose() async {
433451
if (_isDisposed) return;

example/integration_test/unity_embedding_test.dart

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,15 +128,12 @@ void main() {
128128
testWidgets('Unity handles dispose during initialization gracefully',
129129
(WidgetTester tester) async {
130130
// This test verifies race condition fixes
131-
var initStarted = false;
132-
133131
await tester.pumpWidget(
134132
MaterialApp(
135133
home: Scaffold(
136134
body: GameWidget(
137135
engineType: GameEngineType.unity,
138136
onEngineCreated: (controller) {
139-
initStarted = true;
140137
debugPrint('Unity initialization started');
141138
},
142139
),

example/lib/main.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ class _UnityExampleScreenState extends State<UnityExampleScreen> {
206206
color: Colors.white,
207207
boxShadow: [
208208
BoxShadow(
209-
color: Colors.black.withOpacity(0.1),
209+
color: Colors.black.withValues(alpha: 0.1),
210210
blurRadius: 4,
211211
offset: const Offset(0, -2),
212212
),

example/lib/platform_view_modes_example.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import 'package:flutter/material.dart';
22
import 'package:gameframework/gameframework.dart';
3-
import 'package:gameframework_unity/gameframework_unity.dart';
43

54
/// Example demonstrating Android platform view mode switching
65
///
@@ -254,7 +253,7 @@ class PlatformViewModeInfoCard extends StatelessWidget {
254253
padding: const EdgeInsets.only(left: 32, top: 4),
255254
child: Row(
256255
children: [
257-
Icon(Icons.check, size: 16, color: Colors.green),
256+
const Icon(Icons.check, size: 16, color: Colors.green),
258257
const SizedBox(width: 8),
259258
Expanded(child: Text(feature)),
260259
],

example/test/widget_test.dart

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,31 @@ import 'package:flutter_test/flutter_test.dart';
1111
import 'package:gameframework_example/main.dart';
1212

1313
void main() {
14-
testWidgets('Verify Platform version', (WidgetTester tester) async {
14+
testWidgets('App loads and displays title', (WidgetTester tester) async {
1515
// Build our app and trigger a frame.
1616
await tester.pumpWidget(const MyApp());
1717

18-
// Verify that platform version is retrieved.
18+
// Verify that the app title is displayed in AppBar.
1919
expect(
20-
find.byWidgetPredicate(
21-
(Widget widget) =>
22-
widget is Text && widget.data!.startsWith('Running on:'),
23-
),
20+
find.widgetWithText(AppBar, 'Flutter Game Framework'),
21+
findsOneWidget,
22+
);
23+
24+
// Verify that the games icon is present.
25+
expect(
26+
find.byIcon(Icons.games),
27+
findsOneWidget,
28+
);
29+
});
30+
31+
testWidgets('App displays Unity example button', (WidgetTester tester) async {
32+
// Build our app and trigger a frame.
33+
await tester.pumpWidget(const MyApp());
34+
await tester.pumpAndSettle();
35+
36+
// Verify that Unity Example button is displayed.
37+
expect(
38+
find.text('Unity Example'),
2439
findsOneWidget,
2540
);
2641
});

0 commit comments

Comments
 (0)