|
1 | 1 | // Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file |
2 | 2 | // for details. All rights reserved. Use of this source code is governed by a |
3 | 3 | // BSD-style license that can be found in the LICENSE file. |
4 | | -// |
5 | | -// Dart test program for testing error path in datagram bind call. |
6 | | -// |
7 | | -// OtherResources=datagram_error.dart |
8 | 4 |
|
9 | 5 | import 'dart:io'; |
10 | 6 |
|
| 7 | +import "package:async_helper/async_helper.dart"; |
11 | 8 | import "package:expect/expect.dart"; |
12 | | -import 'package:path/path.dart' as path; |
13 | 9 |
|
14 | 10 | void main() async { |
15 | | - var sdkPath = path.absolute(path.dirname(Platform.executable)); |
16 | | - var dartPath = path.absolute( |
17 | | - sdkPath, |
18 | | - Platform.isWindows ? 'dart.exe' : 'dart', |
19 | | - ); |
20 | | - // Get the Dart script file that generates output. |
21 | | - var scriptFile = new File( |
22 | | - Platform.script.resolve("datagram_error.dart").toFilePath(), |
23 | | - ); |
24 | | - var args = <String>[scriptFile.path]; |
25 | | - ProcessResult syncResult = Process.runSync(dartPath, args); |
26 | | - Expect.notEquals(0, syncResult.exitCode); |
27 | | - Expect.stringEquals( |
28 | | - syncResult.stderr, |
29 | | - "Unexpected type for socket address" + Platform.lineTerminator, |
| 11 | + SocketException? error; |
| 12 | + try { |
| 13 | + await RawDatagramSocket.bind( |
| 14 | + InternetAddress('/tmp/test_socket', type: InternetAddressType.unix), |
| 15 | + 0, |
| 16 | + ); |
| 17 | + } on SocketException catch (e) { |
| 18 | + error = e; |
| 19 | + } |
| 20 | + Expect.contains( |
| 21 | + 'Cannot bind datagram socket on non-IPv4/IPv6 address', |
| 22 | + '$error', |
30 | 23 | ); |
31 | 24 | } |
0 commit comments