Skip to content

Commit

Permalink
Fix testing (#79)
Browse files Browse the repository at this point in the history
* Avoid `package:test` in `lib/src/`.

Bumped SDK constraint to `^3.0.0` to enable us to use new language
features.
Tweaked code as to not require `package:test` in `lib/src/`, since this
made publishing impossible.

* Upgrade ffigen

* Update changelog to reflect bumped SDK constraint
  • Loading branch information
jonasfj authored Jan 12, 2024
1 parent 7bf1ca5 commit 5e6d20f
Show file tree
Hide file tree
Showing 21 changed files with 362 additions and 306 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* Added Windows desktop support.
* Additional API documentation.
* Add `topics` to `pubspec.yaml`.
* Bumped lower bound SDK constraint to require Dart `>= 3.0.0`.

# 0.5.3
* Migrate to Flutter 3.0
Expand Down
92 changes: 46 additions & 46 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,26 @@ packages:
dependency: transitive
description:
name: _fe_analyzer_shared
sha256: "4897882604d919befd350648c7f91926a9d5de99e67b455bf0917cc2362f4bb8"
sha256: ae92f5d747aee634b87f89d9946000c2de774be1d6ac3e58268224348cd0101a
url: "https://pub.dev"
source: hosted
version: "47.0.0"
version: "61.0.0"
analyzer:
dependency: transitive
description:
name: analyzer
sha256: "690e335554a8385bc9d787117d9eb52c0c03ee207a607e593de3c9d71b1cfe80"
sha256: ea3d8652bda62982addfd92fdc2d0214e5f82e43325104990d4f4c4a2a313562
url: "https://pub.dev"
source: hosted
version: "4.7.0"
version: "5.13.0"
args:
dependency: transitive
description:
name: args
sha256: b003c3098049a51720352d219b0bb5f219b60fbfb68e7a4748139a06a5676515
sha256: eef6c46b622e0494a36c5a12d10d77fb4e855501a91c1b9ef9339326e58f0596
url: "https://pub.dev"
source: hosted
version: "2.3.1"
version: "2.4.2"
async:
dependency: transitive
description:
Expand Down Expand Up @@ -85,18 +85,18 @@ packages:
dependency: transitive
description:
name: crypto
sha256: aa274aa7774f8964e4f4f38cc994db7b6158dd36e9187aaceaddc994b35c6c67
sha256: ff625774173754681d66daaf4a448684fb04b78f902da9cb3d308c19cc5e8bab
url: "https://pub.dev"
source: hosted
version: "3.0.2"
version: "3.0.3"
cupertino_icons:
dependency: "direct main"
description:
name: cupertino_icons
sha256: e35129dc44c9118cee2a5603506d823bab99c68393879edb440e0090d07586be
sha256: d57953e10f9f8327ce64a508a355f0b1ec902193f66288e8cb5070e7c47eeb2d
url: "https://pub.dev"
source: hosted
version: "1.0.5"
version: "1.0.6"
fake_async:
dependency: transitive
description:
Expand All @@ -109,10 +109,10 @@ packages:
dependency: transitive
description:
name: ffi
sha256: a38574032c5f1dd06c4aee541789906c12ccaab8ba01446e800d9c5b79c4a978
sha256: "7bf0adc28a23d395f19f3f1eb21dd7cfd1dd9f8e1c50051c069122e6853bc878"
url: "https://pub.dev"
source: hosted
version: "2.0.1"
version: "2.1.0"
file:
dependency: transitive
description:
Expand Down Expand Up @@ -158,10 +158,10 @@ packages:
dependency: transitive
description:
name: glob
sha256: c51b4fdfee4d281f49b8c957f1add91b815473597f76bcf07377987f66a55729
sha256: "0e7014b3b7d4dac1ca4d6114f82bf1782ee86745b9b42a92c9289c23d8a0ab63"
url: "https://pub.dev"
source: hosted
version: "2.1.0"
version: "2.1.2"
http_multi_server:
dependency: transitive
description:
Expand All @@ -187,10 +187,10 @@ packages:
dependency: transitive
description:
name: io
sha256: "0d4c73c3653ab85bf696d51a9657604c900a370549196a91f33e4c39af760852"
sha256: "2ec25704aba361659e10e3e5f5d672068d332fc8ac516421d483a11e5cbd061e"
url: "https://pub.dev"
source: hosted
version: "1.0.3"
version: "1.0.4"
js:
dependency: transitive
description:
Expand All @@ -203,10 +203,10 @@ packages:
dependency: transitive
description:
name: logging
sha256: c0bbfe94d46aedf9b8b3e695cf3bd48c8e14b35e3b2c639e0aa7755d589ba946
sha256: "623a88c9594aa774443aa3eb2d41807a48486b5613e67599fb4c41c0ad47c340"
url: "https://pub.dev"
source: hosted
version: "1.1.0"
version: "1.2.0"
matcher:
dependency: transitive
description:
Expand Down Expand Up @@ -235,18 +235,18 @@ packages:
dependency: transitive
description:
name: mime
sha256: dab22e92b41aa1255ea90ddc4bc2feaf35544fd0728e209638cad041a6e3928a
sha256: e4ff8e8564c03f255408decd16e7899da1733852a9110a58fe6d1b817684a63e
url: "https://pub.dev"
source: hosted
version: "1.0.2"
version: "1.0.4"
node_preamble:
dependency: transitive
description:
name: node_preamble
sha256: "8ebdbaa3b96d5285d068f80772390d27c21e1fa10fb2df6627b1b9415043608d"
sha256: "6e7eac89047ab8a8d26cf16127b5ed26de65209847630400f9aefd7cd5c730db"
url: "https://pub.dev"
source: hosted
version: "2.0.1"
version: "2.0.2"
package_config:
dependency: transitive
description:
Expand Down Expand Up @@ -291,42 +291,42 @@ packages:
dependency: transitive
description:
name: pub_semver
sha256: b959af0a045c3484c4a8f4997731f5bfe4cac60d732fd8ce35b351f2d6a459fe
sha256: "40d3ab1bbd474c4c2328c91e3a7df8c6dd629b79ece4c4bd04bee496a224fb0c"
url: "https://pub.dev"
source: hosted
version: "2.1.2"
version: "2.1.4"
shelf:
dependency: transitive
description:
name: shelf
sha256: c24a96135a2ccd62c64b69315a14adc5c3419df63b4d7c05832a346fdb73682c
sha256: ad29c505aee705f41a4d8963641f91ac4cee3c8fad5947e033390a7bd8180fa4
url: "https://pub.dev"
source: hosted
version: "1.4.0"
version: "1.4.1"
shelf_packages_handler:
dependency: transitive
description:
name: shelf_packages_handler
sha256: aef74dc9195746a384843102142ab65b6a4735bb3beea791e63527b88cc83306
sha256: "89f967eca29607c933ba9571d838be31d67f53f6e4ee15147d5dc2934fee1b1e"
url: "https://pub.dev"
source: hosted
version: "3.0.1"
version: "3.0.2"
shelf_static:
dependency: transitive
description:
name: shelf_static
sha256: e792b76b96a36d4a41b819da593aff4bdd413576b3ba6150df5d8d9996d2e74c
sha256: a41d3f53c4adf0f57480578c1d61d90342cd617de7fc8077b1304643c2d85c1e
url: "https://pub.dev"
source: hosted
version: "1.1.1"
version: "1.1.2"
shelf_web_socket:
dependency: transitive
description:
name: shelf_web_socket
sha256: "6db16374bc3497d21aa0eebe674d3db9fdf82082aac0f04dc7b44e4af5b08afc"
sha256: "9ca081be41c60190ebcb4766b2486a7d50261db7bd0f5d9615f2d653637a84c1"
url: "https://pub.dev"
source: hosted
version: "1.0.2"
version: "1.0.4"
sky_engine:
dependency: transitive
description: flutter
Expand All @@ -336,18 +336,18 @@ packages:
dependency: transitive
description:
name: source_map_stack_trace
sha256: "8c463326277f68a628abab20580047b419c2ff66756fd0affd451f73f9508c11"
sha256: "84cf769ad83aa6bb61e0aa5a18e53aea683395f196a6f39c4c881fb90ed4f7ae"
url: "https://pub.dev"
source: hosted
version: "2.1.0"
version: "2.1.1"
source_maps:
dependency: transitive
description:
name: source_maps
sha256: "52de2200bb098de739794c82d09c41ac27b2e42fd7e23cce7b9c74bf653c7296"
sha256: "708b3f6b97248e5781f493b765c3337db11c5d2c81c3094f10904bfa8004c703"
url: "https://pub.dev"
source: hosted
version: "0.10.10"
version: "0.10.12"
source_span:
dependency: transitive
description:
Expand Down Expand Up @@ -424,10 +424,10 @@ packages:
dependency: transitive
description:
name: typed_data
sha256: "26f87ade979c47a150c9eaab93ccd2bebe70a27dc0b4b29517f2904f04eb11a5"
sha256: facc8d6582f16042dd49f2463ff1bd6e2c9ef9f3d5da3d9b087e244a7b564b3c
url: "https://pub.dev"
source: hosted
version: "1.3.1"
version: "1.3.2"
vector_math:
dependency: transitive
description:
Expand All @@ -448,10 +448,10 @@ packages:
dependency: transitive
description:
name: watcher
sha256: "6a7f46926b01ce81bfc339da6a7f20afbe7733eff9846f6d6a5466aa4c6667c0"
sha256: "3d2ad6751b3c16cf07c7fca317a1413b3f26530319181b37e3b9039b84fc01d8"
url: "https://pub.dev"
source: hosted
version: "1.0.2"
version: "1.1.0"
web:
dependency: transitive
description:
Expand All @@ -464,10 +464,10 @@ packages:
dependency: transitive
description:
name: web_socket_channel
sha256: "3a969ddcc204a3e34e863d204b29c0752716f78b6f9cc8235083208d268a4ccd"
sha256: d88238e5eac9a42bb43ca4e721edba3c08c6354d4a53063afaa568516217621b
url: "https://pub.dev"
source: hosted
version: "2.2.0"
version: "2.4.0"
webcrypto:
dependency: "direct main"
description:
Expand All @@ -487,18 +487,18 @@ packages:
dependency: transitive
description:
name: webkit_inspection_protocol
sha256: "67d3a8b6c79e1987d19d848b0892e582dbb0c66c57cc1fef58a177dd2aa2823d"
sha256: "87d3f2333bb240704cd3f1c6b5b7acd8a10e7f0bc28c28dcf14e782014f4a572"
url: "https://pub.dev"
source: hosted
version: "1.2.0"
version: "1.2.1"
yaml:
dependency: transitive
description:
name: yaml
sha256: "23812a9b125b48d4007117254bca50abb6c712352927eece9e155207b1db2370"
sha256: "75769501ea3489fca56601ff33454fe45507ea3bfb014161abc3b43ae25989d5"
url: "https://pub.dev"
source: hosted
version: "3.1.1"
version: "3.1.2"
sdks:
dart: ">=3.1.0-185.0.dev <4.0.0"
flutter: ">=3.0.0"
1 change: 1 addition & 0 deletions lib/src/boringssl/bindings/generated_bindings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
// AUTO GENERATED FILE, DO NOT EDIT.
//
// Generated by `package:ffigen`.
// ignore_for_file: type=lint
import 'dart:ffi' as ffi;

/// Bindings to src/webcrypto.h.
Expand Down
20 changes: 12 additions & 8 deletions lib/src/testing/testing.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

import 'utils/utils.dart';
import 'utils/testrunner.dart' show TestRunner;

// TestRunner implementations
Expand Down Expand Up @@ -48,15 +47,20 @@ final _testRunners = <TestRunner>[
rsassapkcs1v15.runner,
];

/// Utility function that runs all tests using [test].
/// Utility function that runs all tests using [testFn].
///
/// This makes it easy to run tests from `flutter drive`, when testing on a
/// device.
void runAllTests(TestFn test) {
for (final r in _testRunners) {
r.runTests(test: test);
void runAllTests(
void Function(String name, Future<void> Function() test) testFn,
) {
final allTests = [
for (final r in _testRunners) ...r.tests(),
...random.tests(),
...digest.tests(),
];

for (final (:name, :test) in allTests) {
testFn(name, test);
}
// We don't use [TestRunner] for all tests, so we just add them manually.
random.runTests(test: test);
digest.runTests(test: test);
}
23 changes: 13 additions & 10 deletions lib/src/testing/utils/testrunner.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import 'dart:convert';
import 'dart:math';
import 'dart:async';

import 'package:test/test.dart' show test;
import 'package:meta/meta.dart';
import 'package:webcrypto/webcrypto.dart';
import 'detected_runtime.dart';
Expand Down Expand Up @@ -606,28 +605,32 @@ class TestRunner<PrivateKey, PublicKey> {
return c.toJson();
}

/// Run tests for [testData] using the given [test] function.
/// Get test cases from [testData].
///
/// If no [testData] is given the `testData` given when the [TestRunner] was
/// created will be used.
///
/// The [test] function must be compatible with `package:test/test.dart`.
void runTests({
TestFn test = test,
/// Returns a list of tuples with test name and test function.
List<({String name, Future<void> Function() test})> tests({
Iterable<Map<dynamic, dynamic>>? testData,
}) {
final tests = <({String name, Future<void> Function() test})>[];
testData ??= _testData;
for (final data in testData) {
final c = _TestCase.fromJson(data);

_runTests(this, c, (String name, FutureOr<void> Function() fn) {
// Prefix test names
test('$algorithm: ${c.name} -- $name', () async {
// Check BoringSSL error stack if running with dart:ffi
await checkErrorStack(fn);
});
tests.add((
// Prefix test names
name: '$algorithm: ${c.name} -- $name',
test: () async {
// Check BoringSSL error stack if running with dart:ffi
await checkErrorStack(fn);
}
));
});
}
return tests;
}
}

Expand Down
Loading

0 comments on commit 5e6d20f

Please sign in to comment.