Compare commits

...

17 Commits

Author SHA1 Message Date
e1677dee66 Finally fix the CI
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
2023-08-22 19:44:21 +02:00
b15b7eb27a Drbug
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
2023-08-22 19:39:14 +02:00
4743badc4b Fix usage of woodpecker-xmpp
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
2023-08-22 19:37:30 +02:00
1dd99802d5 Improve CI
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
2023-08-22 19:35:44 +02:00
0c8b572e82 verbose
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
2023-08-20 21:36:13 +02:00
45cf73dbf5 ci: Use the pub cache
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
2023-08-20 21:08:34 +02:00
a29eddeb66 .
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
2023-08-18 23:36:47 +02:00
4dc0d5652e .
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
2023-08-18 23:33:02 +02:00
c7968ae045 .
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
2023-08-18 23:28:53 +02:00
c188e82888 ci: Test notify
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
2023-08-18 23:19:07 +02:00
ceeb1efde7 .
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
2023-08-18 19:18:19 +02:00
e833e9d9c8 ci: Update pubspec
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
2023-08-18 18:30:34 +02:00
a68a77d172 ci: Add verbose logging
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
2023-08-18 18:18:05 +02:00
e3cbe3b065 ci: Use a newer Dart version
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
2023-08-18 18:15:56 +02:00
5e867e30ee feat: Move the Result type into moxlib
Some checks failed
ci/woodpecker/manual/woodpecker Pipeline failed
Now, `import 'package:moxlib/moxlib.dart';` is enough.
2023-06-17 21:16:41 +02:00
3d3b047097 feat: Lint and format 2023-06-17 21:14:17 +02:00
7e55015948 feat: Remove list helpers
Use the collection package instead.
2023-06-17 21:06:29 +02:00
12 changed files with 142 additions and 156 deletions

View File

@@ -1,11 +1,24 @@
pipeline:
lint:
image: dart:2.18.1
image: dart:3.0.7
commands:
- dart pub get
# Proxy requests to pub.dev using pubcached
- PUB_HOSTED_URL=http://172.17.0.1:8000 dart pub get --no-precompile
- dart analyze --fatal-infos --fatal-warnings
test:
image: dart:2.18.1
image: dart:3.0.7
commands:
- dart pub get
- dart test
notify:
image: git.polynom.me/papatutuwawa/woodpecker-xmpp
settings:
xmpp_tls: 1
xmpp_is_muc: 1
xmpp_recipient: moxxy-build@muc.moxxy.org
xmpp_alias: 2Bot
secrets: [ xmpp_jid, xmpp_password, xmpp_server ]
when:
status:
- success
- failure

View File

@@ -6,10 +6,3 @@ linter:
use_setters_to_change_properties: false
avoid_positional_boolean_parameters: false
avoid_bool_literals_in_conditional_expressions: false
analyzer:
exclude:
- "**/*.g.dart"
- "**/*.freezed.dart"
- "test/"
- "integration_test/"

12
flake.lock generated
View File

@@ -2,11 +2,11 @@
"nodes": {
"flake-utils": {
"locked": {
"lastModified": 1667395993,
"narHash": "sha256-nuEHfE/LcWyuSWnS8t12N1wc105Qtau+/OdUAjtQ0rA=",
"lastModified": 1656065134,
"narHash": "sha256-oc6E6ByIw3oJaIyc67maaFcnjYOz1mMcOtHxbEf9NwQ=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "5aed5285a952e0b949eb3ba02c12fa4fcfef535f",
"rev": "bee6a7250dd1b01844a2de7e02e4df7d8a0a206c",
"type": "github"
},
"original": {
@@ -17,11 +17,11 @@
},
"nixpkgs": {
"locked": {
"lastModified": 1667610399,
"narHash": "sha256-XZd0f4ZWAY0QOoUSdiNWj/eFiKb4B9CJPtl9uO9SYY4=",
"lastModified": 1692311226,
"narHash": "sha256-mRzNup0PIUD6YxbrYvjzL7f+1oaOGy9nmGCV3AZkQus=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "1dd8696f96db47156e1424a49578fe7dd4ce99a4",
"rev": "ef8288935ba859fc3b30632fa6e04705f81b9c2a",
"type": "github"
},
"original": {

View File

@@ -8,39 +8,14 @@
outputs = { self, nixpkgs, flake-utils }: flake-utils.lib.eachDefaultSystem (system: let
pkgs = import nixpkgs {
inherit system;
config = {
android_sdk.accept_license = true;
allowUnfree = true;
};
};
android = pkgs.androidenv.composeAndroidPackages {
# TODO: Find a way to pin these
#toolsVersion = "26.1.1";
#platformToolsVersion = "31.0.3";
#buildToolsVersions = [ "31.0.0" ];
#includeEmulator = true;
#emulatorVersion = "30.6.3";
platformVersions = [ "28" ];
includeSources = false;
includeSystemImages = true;
systemImageTypes = [ "default" ];
abiVersions = [ "x86_64" ];
includeNDK = false;
useGoogleAPIs = false;
useGoogleTVAddOns = false;
};
pinnedJDK = pkgs.jdk;
in {
devShell = pkgs.mkShell {
buildInputs = with pkgs; [
flutter pinnedJDK android.platform-tools dart # Flutter
dart # Dart
gitlint jq # Code hygiene
ripgrep # General utilities
];
ANDROID_HOME = "${android.androidsdk}/libexec/android-sdk";
JAVA_HOME = pinnedJDK;
ANDROID_AVD_HOME = (toString ./.) + "/.android/avd";
};
});
}

View File

@@ -1,16 +0,0 @@
/// A wrapper around List<T>.firstWhere that does not throw but instead just
/// returns true if [test] returns true for an element or false if [test] never
/// returned true.
bool listContains<T>(List<T> list, bool Function(T element) test) {
return firstWhereOrNull<T>(list, test) != null;
}
/// A wrapper around [List<T>.firstWhere] that does not throw but instead just
/// return null if [test] never returned true
T? firstWhereOrNull<T>(List<T> list, bool Function(T element) test) {
try {
return list.firstWhere(test);
} catch(e) {
return null;
}
}

View File

@@ -1,5 +1,5 @@
library moxlib;
export 'awaitabledatasender.dart';
export 'lists.dart';
export 'math.dart';
export 'src/awaitabledatasender.dart';
export 'src/math.dart';
export 'src/result.dart';

View File

@@ -30,15 +30,15 @@ class DataWrapper<T extends JsonImplementation> {
/// The actual data.
final T data;
Map<String, dynamic> toJson() => {
'id': id,
'data': data.toJson()
};
Map<String, dynamic> toJson() => {'id': id, 'data': data.toJson()};
static DataWrapper fromJson<T extends JsonImplementation>(Map<String, dynamic> json) => DataWrapper<T>(
json['id']! as String,
json['data']! as T,
);
static DataWrapper fromJson<T extends JsonImplementation>(
Map<String, dynamic> json,
) =>
DataWrapper<T>(
json['id']! as String,
json['data']! as T,
);
DataWrapper reply(T newData) => DataWrapper(id, newData);
}
@@ -49,10 +49,8 @@ class DataWrapper<T extends JsonImplementation> {
///
/// awaiting [sendData] will return a [Future] that will resolve to the reresponse when
/// received via [onData].
abstract class AwaitableDataSender<
S extends JsonImplementation,
R extends JsonImplementation
> {
abstract class AwaitableDataSender<S extends JsonImplementation,
R extends JsonImplementation> {
@mustCallSuper
AwaitableDataSender();
@@ -82,30 +80,34 @@ abstract class AwaitableDataSender<
/// Sends [data] using [sendDataImpl]. If [awaitable] is true, then a
/// Future will be returned that can be used to await a response. If it
/// is false, then null will be imediately resolved.
Future<R?> sendData(S data, { bool awaitable = true, @visibleForTesting String? id }) async {
Future<R?> sendData(
S data, {
bool awaitable = true,
@visibleForTesting String? id,
}) async {
// ignore: no_leading_underscores_for_local_identifiers
final _id = id ?? _uuid.v4();
var future = Future<R?>.value();
_log.fine('sendData: Waiting to acquire lock...');
await _lock.synchronized(() async {
_log.fine('sendData: Done');
if (awaitable) {
_awaitables[_id] = Completer();
onAdd();
}
_log.fine('sendData: Done');
if (awaitable) {
_awaitables[_id] = Completer();
onAdd();
}
await sendDataImpl(
DataWrapper<S>(
_id,
data,
),
);
await sendDataImpl(
DataWrapper<S>(
_id,
data,
),
);
if (awaitable) {
future = _awaitables[_id]!.future;
}
if (awaitable) {
future = _awaitables[_id]!.future;
}
_log.fine('sendData: Releasing lock...');
_log.fine('sendData: Releasing lock...');
});
return future;

24
lib/src/result.dart Normal file
View File

@@ -0,0 +1,24 @@
/// Holds a value of either [T] or [V].
class Result<T, V> {
/// Constructs a result. [_data] must be either of type [T] or [V].
const Result(this._data)
: assert(
_data is T || _data is V,
'Invalid data type $_data: Must be either $T or $V',
);
final dynamic _data;
/// Returns true if the data contained within is of type [S]. If not, returns false.
bool isType<S>() => _data is S;
/// Returns the data contained within cast to [S]. Before doing this call, it's recommended
/// to check isType<S>() first.
S get<S>() {
assert(_data is S, 'Data is not $S');
return _data as S;
}
/// Returns the runtime type of the data.
Object get dataRuntimeType => _data.runtimeType;
}

View File

@@ -1,11 +1,11 @@
name: moxlib
description: A collection of code for sharing between various moxxy libraries. Not inteded for outside use.
version: 0.1.5
description: A collection of code for sharing between various moxxy libraries. Not intended for outside use.
version: 0.2.0
homepage: https://codeberg.org/moxxy/moxlib
publish_to: https://git.polynom.me/api/packages/Moxxy/pub
environment:
sdk: ">=2.17.0-266.1.beta <3.0.0"
sdk: ">=2.17.0 <3.0.0"
dependencies:
logging: ^1.0.2
@@ -16,4 +16,4 @@ dependencies:
dev_dependencies:
flutter_lints: ^2.0.0
test: ^1.20.1
very_good_analysis: ^3.0.1
very_good_analysis: ^5.0.0

View File

@@ -1,29 +1,23 @@
import "package:moxlib/awaitabledatasender.dart";
import "package:test/test.dart";
import 'package:moxlib/moxlib.dart';
import 'package:test/test.dart';
class TestDataType implements JsonImplementation {
final String data;
TestDataType(this.data);
@override
Map<String, dynamic> toJson() => {
"data": data
};
factory TestDataType.fromJson(Map<String, dynamic> json) =>
TestDataType(json['data']! as String);
factory TestDataType.fromJson(Map<String, dynamic> json) => TestDataType(
json["data"]!
);
final String data;
@override
Map<String, dynamic> toJson() => {'data': data};
}
class FakeAwaitableDataSender<
S extends JsonImplementation,
R extends JsonImplementation
> extends AwaitableDataSender<S, R> {
final void Function()? onAddFunc;
class FakeAwaitableDataSender<S extends JsonImplementation,
R extends JsonImplementation> extends AwaitableDataSender<S, R> {
FakeAwaitableDataSender({this.onAddFunc}) : super();
FakeAwaitableDataSender({ this.onAddFunc }) : super();
final void Function()? onAddFunc;
@override
Future<void> sendDataImpl(DataWrapper data) async {}
@@ -35,39 +29,41 @@ class FakeAwaitableDataSender<
}
void main() {
test("Sending an event without awaiting it", () async {
final handler = FakeAwaitableDataSender<TestDataType, TestDataType>();
final result = await handler.sendData(TestDataType("hallo"), awaitable: false);
test('Sending an event without awaiting it', () async {
final handler = FakeAwaitableDataSender<TestDataType, TestDataType>();
final result =
await handler.sendData(TestDataType('hallo'), awaitable: false);
expect(result, null);
expect(handler.getAwaitables().length, 0);
expect(result, null);
expect(handler.getAwaitables().length, 0);
});
test("Sending an event without awaiting it", () async {
final handler = FakeAwaitableDataSender<TestDataType, TestDataType>();
const id = "abc123";
final result = handler.sendData(TestDataType("hallo"), awaitable: true, id: id);
await handler.onData(DataWrapper(id, TestDataType("welt")));
test('Sending an event without awaiting it', () async {
final handler = FakeAwaitableDataSender<TestDataType, TestDataType>();
const id = 'abc123';
final result =
handler.sendData(TestDataType('hallo'), awaitable: true, id: id);
await handler.onData(DataWrapper(id, TestDataType('welt')));
expect((await result)!.data, "welt");
expect(handler.getAwaitables().length, 0);
expect((await result)!.data, 'welt');
expect(handler.getAwaitables().length, 0);
});
test("Queue multiple data packets and resolve in reverse order", () async {
int i = 0;
final handler = FakeAwaitableDataSender<TestDataType, TestDataType>(
onAddFunc: () {
i++;
expect(i <= 2, true);
}
);
final a = handler.sendData(TestDataType("1"), id: "1");
final b = handler.sendData(TestDataType("2"), id: "2");
test('Queue multiple data packets and resolve in reverse order', () async {
var i = 0;
final handler = FakeAwaitableDataSender<TestDataType, TestDataType>(
onAddFunc: () {
i++;
expect(i <= 2, true);
},
);
final a = handler.sendData(TestDataType('1'), id: '1');
final b = handler.sendData(TestDataType('2'), id: '2');
await handler.onData(DataWrapper("2", TestDataType("4")));
await handler.onData(DataWrapper("1", TestDataType("1")));
await handler.onData(DataWrapper('2', TestDataType('4')));
await handler.onData(DataWrapper('1', TestDataType('1')));
expect((await a)!.data, "1");
expect((await b)!.data, "4");
expect((await a)!.data, '1');
expect((await b)!.data, '4');
});
}

View File

@@ -1,14 +1,13 @@
import "package:moxlib/math.dart";
import "package:test/test.dart";
import 'package:moxlib/moxlib.dart';
import 'package:test/test.dart';
void main() {
group("implies", () {
test("Truth table test", () {
expect(implies(true, true), true);
expect(implies(true, false), false);
expect(implies(false, true), true);
expect(implies(false, false), true);
});
group('implies', () {
test('Truth table test', () {
expect(implies(true, true), true);
expect(implies(true, false), false);
expect(implies(false, true), true);
expect(implies(false, false), true);
});
});
}