Files
sdk/pkg/dynamic_modules/test/runner/model.dart
T
Sigmund Cherem fd3cb424e2 [dynamic_modules] Run dynamic module tests in CQ
* Adds support to emit log records for test outcomes and failure logs
* Adds steps to the test_matrix

Change-Id: Ibabf0410a0304aae446387a0d3ca147488f56df3
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/383929
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Commit-Queue: Sigmund Cherem <sigmund@google.com>
2024-09-12 15:36:40 +00:00

88 lines
2.8 KiB
Dart

// Copyright (c) 2024, 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:convert';
/// Data needed to build and run a single dynamic module test.
class DynamicModuleTest {
/// Name of the test. Matches the folder containing the test.
final String name;
/// Absolute path to the test folder.
final Uri folder;
/// Entrypoint of the original application, relative to the test folder.
/// All shared code
/// must be reachable from it.
final String main;
/// Location of the dynamic_interface.yaml declaration.
final String interface;
/// Entrypoint for each dynamic module, keyed by name.
final Map<String, String> dynamicModules;
DynamicModuleTest(
this.name, this.folder, this.main, this.interface, this.dynamicModules);
}
/// Result of an individual module test.
class DynamicModuleTestResult {
final String name;
final Status status;
final String details;
final Duration time;
DynamicModuleTestResult._(this.name, this.status, this.details, this.time);
factory DynamicModuleTestResult.pass(DynamicModuleTest test, Duration time) =>
DynamicModuleTestResult._(test.name, Status.pass, '', time);
factory DynamicModuleTestResult.compileError(
DynamicModuleTest test, String details, Duration time) =>
DynamicModuleTestResult._(
test.name, Status.compileTimeError, details, time);
factory DynamicModuleTestResult.runtimeError(
DynamicModuleTest test, String details, Duration time) =>
DynamicModuleTestResult._(test.name, Status.runtimeError, details, time);
/// Emit the result in the JSON format expected by the test infrastructure.
String toRecordJson(String configuration) {
final outcome = switch (status) {
Status.pass => 'Pass',
Status.compileTimeError => 'CompileTimeError',
Status.runtimeError => 'RuntimeError',
};
return jsonEncode({
'name': 'dynamic_modules_suite/$name',
'configuration': configuration,
'suite': 'dynamic_modules_suite',
'test_name': name,
'time_ms': time.inMilliseconds,
'expected': 'Pass',
'result': outcome,
'matches': status == Status.pass,
});
}
/// Emit the log entry with details of a failure in the JSON format expected
/// by the test infrastructure.
String toLogJson(String configuration) {
final outcome = switch (status) {
Status.pass => 'Pass',
Status.compileTimeError => 'CompileTimeError',
Status.runtimeError => 'RuntimeError',
};
return jsonEncode({
'name': 'dynamic_modules_suite/$name',
'configuration': configuration,
'result': outcome,
'log': details,
});
}
}
enum Status { pass, compileTimeError, runtimeError }