Files
sdk/pkg/dart2wasm/test/wasm_read_write_test.dart
Kevin Moore d36049165b [dart2wasm] Use Expect.listEquals instead of home-rolled solution
Change-Id: Ida9bf4d7f4ace30ed51240b854212b330309f65c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/469000
Auto-Submit: Kevin Moore <kevmoo@google.com>
Commit-Queue: Ömer Ağacan <omersa@google.com>
Reviewed-by: Ömer Ağacan <omersa@google.com>
2025-12-18 01:24:41 -08:00

46 lines
1.3 KiB
Dart

// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'dart:io';
import 'dart:typed_data';
import 'package:expect/expect.dart';
import 'package:path/path.dart' as path;
import 'package:wasm_builder/wasm_builder.dart';
import 'util.dart';
Future main() async {
if (!Platform.isLinux && !Platform.isMacOS) return;
await withTempDir((String tempDir) async {
final dartFilename = 'third_party/flute/benchmarks/lib/complex.dart';
final wasmFilename = path.join(tempDir, 'flute.wasm');
final wasmFile = File(wasmFilename);
await run([
Platform.executable,
'compile',
'wasm',
'-O0',
dartFilename,
'-o',
wasmFilename,
]);
final wasmBytes = wasmFile.readAsBytesSync();
Expect.listEquals(wasmBytes, readWrite(wasmBytes));
// Temporary files will be deleted when returning to [withTempDir].
});
}
Uint8List readWrite(Uint8List wasmBytes) {
final deserializer = Deserializer(wasmBytes);
final module = Module.deserialize(deserializer);
final serializer = Serializer();
module.serialize(serializer);
return serializer.data;
}