checks: add tests for core extensions (#1727)
100% code coverage of core extensions
diff --git a/.github/workflows/dart.yml b/.github/workflows/dart.yml
index 441c99c..0ecb4d2 100644
--- a/.github/workflows/dart.yml
+++ b/.github/workflows/dart.yml
@@ -241,16 +241,16 @@
- job_001
- job_002
job_006:
- name: "unit_test; linux; Dart dev; PKG: pkgs/test; `xvfb-run -s \"-screen 0 1024x768x24\" dart test --preset travis --total-shards 5 --shard-index 0`"
+ name: "unit_test; linux; Dart dev; PKG: pkgs/checks; `dart test`"
runs-on: ubuntu-latest
steps:
- name: Cache Pub hosted dependencies
uses: actions/cache@4504faf7e9bcf8f3ed0bc863c4e1d21499ab8ef8
with:
path: "~/.pub-cache/hosted"
- key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:pkgs/test;commands:command_00"
+ key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:pkgs/checks;commands:command_00"
restore-keys: |
- os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:pkgs/test
+ os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:pkgs/checks
os:ubuntu-latest;pub-cache-hosted;sdk:dev
os:ubuntu-latest;pub-cache-hosted
os:ubuntu-latest
@@ -259,20 +259,20 @@
sdk: dev
- id: checkout
uses: actions/checkout@d0651293c4a5a52e711f25b41b05b2212f385d28
- - id: pkgs_test_pub_upgrade
- name: pkgs/test; dart pub upgrade
+ - id: pkgs_checks_pub_upgrade
+ name: pkgs/checks; dart pub upgrade
if: "always() && steps.checkout.conclusion == 'success'"
- working-directory: pkgs/test
+ working-directory: pkgs/checks
run: dart pub upgrade
- - name: "pkgs/test; xvfb-run -s \"-screen 0 1024x768x24\" dart test --preset travis --total-shards 5 --shard-index 0"
- if: "always() && steps.pkgs_test_pub_upgrade.conclusion == 'success'"
- working-directory: pkgs/test
- run: "xvfb-run -s \"-screen 0 1024x768x24\" dart test --preset travis --total-shards 5 --shard-index 0"
+ - name: pkgs/checks; dart test
+ if: "always() && steps.pkgs_checks_pub_upgrade.conclusion == 'success'"
+ working-directory: pkgs/checks
+ run: dart test
needs:
- job_001
- job_002
job_007:
- name: "unit_test; linux; Dart dev; PKG: pkgs/test; `xvfb-run -s \"-screen 0 1024x768x24\" dart test --preset travis --total-shards 5 --shard-index 1`"
+ name: "unit_test; linux; Dart dev; PKG: pkgs/test; `xvfb-run -s \"-screen 0 1024x768x24\" dart test --preset travis --total-shards 5 --shard-index 0`"
runs-on: ubuntu-latest
steps:
- name: Cache Pub hosted dependencies
@@ -295,15 +295,15 @@
if: "always() && steps.checkout.conclusion == 'success'"
working-directory: pkgs/test
run: dart pub upgrade
- - name: "pkgs/test; xvfb-run -s \"-screen 0 1024x768x24\" dart test --preset travis --total-shards 5 --shard-index 1"
+ - name: "pkgs/test; xvfb-run -s \"-screen 0 1024x768x24\" dart test --preset travis --total-shards 5 --shard-index 0"
if: "always() && steps.pkgs_test_pub_upgrade.conclusion == 'success'"
working-directory: pkgs/test
- run: "xvfb-run -s \"-screen 0 1024x768x24\" dart test --preset travis --total-shards 5 --shard-index 1"
+ run: "xvfb-run -s \"-screen 0 1024x768x24\" dart test --preset travis --total-shards 5 --shard-index 0"
needs:
- job_001
- job_002
job_008:
- name: "unit_test; linux; Dart dev; PKG: pkgs/test; `xvfb-run -s \"-screen 0 1024x768x24\" dart test --preset travis --total-shards 5 --shard-index 2`"
+ name: "unit_test; linux; Dart dev; PKG: pkgs/test; `xvfb-run -s \"-screen 0 1024x768x24\" dart test --preset travis --total-shards 5 --shard-index 1`"
runs-on: ubuntu-latest
steps:
- name: Cache Pub hosted dependencies
@@ -326,15 +326,15 @@
if: "always() && steps.checkout.conclusion == 'success'"
working-directory: pkgs/test
run: dart pub upgrade
- - name: "pkgs/test; xvfb-run -s \"-screen 0 1024x768x24\" dart test --preset travis --total-shards 5 --shard-index 2"
+ - name: "pkgs/test; xvfb-run -s \"-screen 0 1024x768x24\" dart test --preset travis --total-shards 5 --shard-index 1"
if: "always() && steps.pkgs_test_pub_upgrade.conclusion == 'success'"
working-directory: pkgs/test
- run: "xvfb-run -s \"-screen 0 1024x768x24\" dart test --preset travis --total-shards 5 --shard-index 2"
+ run: "xvfb-run -s \"-screen 0 1024x768x24\" dart test --preset travis --total-shards 5 --shard-index 1"
needs:
- job_001
- job_002
job_009:
- name: "unit_test; linux; Dart dev; PKG: pkgs/test; `xvfb-run -s \"-screen 0 1024x768x24\" dart test --preset travis --total-shards 5 --shard-index 3`"
+ name: "unit_test; linux; Dart dev; PKG: pkgs/test; `xvfb-run -s \"-screen 0 1024x768x24\" dart test --preset travis --total-shards 5 --shard-index 2`"
runs-on: ubuntu-latest
steps:
- name: Cache Pub hosted dependencies
@@ -357,15 +357,15 @@
if: "always() && steps.checkout.conclusion == 'success'"
working-directory: pkgs/test
run: dart pub upgrade
- - name: "pkgs/test; xvfb-run -s \"-screen 0 1024x768x24\" dart test --preset travis --total-shards 5 --shard-index 3"
+ - name: "pkgs/test; xvfb-run -s \"-screen 0 1024x768x24\" dart test --preset travis --total-shards 5 --shard-index 2"
if: "always() && steps.pkgs_test_pub_upgrade.conclusion == 'success'"
working-directory: pkgs/test
- run: "xvfb-run -s \"-screen 0 1024x768x24\" dart test --preset travis --total-shards 5 --shard-index 3"
+ run: "xvfb-run -s \"-screen 0 1024x768x24\" dart test --preset travis --total-shards 5 --shard-index 2"
needs:
- job_001
- job_002
job_010:
- name: "unit_test; linux; Dart dev; PKG: pkgs/test; `xvfb-run -s \"-screen 0 1024x768x24\" dart test --preset travis --total-shards 5 --shard-index 4`"
+ name: "unit_test; linux; Dart dev; PKG: pkgs/test; `xvfb-run -s \"-screen 0 1024x768x24\" dart test --preset travis --total-shards 5 --shard-index 3`"
runs-on: ubuntu-latest
steps:
- name: Cache Pub hosted dependencies
@@ -388,6 +388,37 @@
if: "always() && steps.checkout.conclusion == 'success'"
working-directory: pkgs/test
run: dart pub upgrade
+ - name: "pkgs/test; xvfb-run -s \"-screen 0 1024x768x24\" dart test --preset travis --total-shards 5 --shard-index 3"
+ if: "always() && steps.pkgs_test_pub_upgrade.conclusion == 'success'"
+ working-directory: pkgs/test
+ run: "xvfb-run -s \"-screen 0 1024x768x24\" dart test --preset travis --total-shards 5 --shard-index 3"
+ needs:
+ - job_001
+ - job_002
+ job_011:
+ name: "unit_test; linux; Dart dev; PKG: pkgs/test; `xvfb-run -s \"-screen 0 1024x768x24\" dart test --preset travis --total-shards 5 --shard-index 4`"
+ runs-on: ubuntu-latest
+ steps:
+ - name: Cache Pub hosted dependencies
+ uses: actions/cache@4504faf7e9bcf8f3ed0bc863c4e1d21499ab8ef8
+ with:
+ path: "~/.pub-cache/hosted"
+ key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:pkgs/test;commands:command_05"
+ restore-keys: |
+ os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:pkgs/test
+ os:ubuntu-latest;pub-cache-hosted;sdk:dev
+ os:ubuntu-latest;pub-cache-hosted
+ os:ubuntu-latest
+ - uses: dart-lang/setup-dart@6a218f2413a3e78e9087f638a238f6b40893203d
+ with:
+ sdk: dev
+ - id: checkout
+ uses: actions/checkout@d0651293c4a5a52e711f25b41b05b2212f385d28
+ - id: pkgs_test_pub_upgrade
+ name: pkgs/test; dart pub upgrade
+ if: "always() && steps.checkout.conclusion == 'success'"
+ working-directory: pkgs/test
+ run: dart pub upgrade
- name: "pkgs/test; xvfb-run -s \"-screen 0 1024x768x24\" dart test --preset travis --total-shards 5 --shard-index 4"
if: "always() && steps.pkgs_test_pub_upgrade.conclusion == 'success'"
working-directory: pkgs/test
@@ -395,7 +426,7 @@
needs:
- job_001
- job_002
- job_011:
+ job_012:
name: "unit_test; linux; Dart dev; PKG: pkgs/test_api; `dart test --preset travis -x browser`"
runs-on: ubuntu-latest
steps:
@@ -403,7 +434,7 @@
uses: actions/cache@4504faf7e9bcf8f3ed0bc863c4e1d21499ab8ef8
with:
path: "~/.pub-cache/hosted"
- key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:pkgs/test_api;commands:command_10"
+ key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:pkgs/test_api;commands:command_11"
restore-keys: |
os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:pkgs/test_api
os:ubuntu-latest;pub-cache-hosted;sdk:dev
@@ -426,7 +457,7 @@
needs:
- job_001
- job_002
- job_012:
+ job_013:
name: "unit_test; linux; Dart stable; PKG: integration_tests/nnbd_opted_in; `dart test -p chrome,vm,node`"
runs-on: ubuntu-latest
steps:
@@ -457,7 +488,7 @@
needs:
- job_001
- job_002
- job_013:
+ job_014:
name: "unit_test; linux; Dart stable; PKG: integration_tests/nnbd_opted_out; `dart test -p chrome,vm,node`"
runs-on: ubuntu-latest
steps:
@@ -488,7 +519,7 @@
needs:
- job_001
- job_002
- job_014:
+ job_015:
name: "unit_test; linux; Dart stable; PKG: integration_tests/spawn_hybrid; `dart test -p chrome,vm,node`"
runs-on: ubuntu-latest
steps:
@@ -519,39 +550,8 @@
needs:
- job_001
- job_002
- job_015:
- name: "unit_test; linux; Dart stable; PKG: pkgs/test; `xvfb-run -s \"-screen 0 1024x768x24\" dart test --preset travis --total-shards 5 --shard-index 0`"
- runs-on: ubuntu-latest
- steps:
- - name: Cache Pub hosted dependencies
- uses: actions/cache@4504faf7e9bcf8f3ed0bc863c4e1d21499ab8ef8
- with:
- path: "~/.pub-cache/hosted"
- key: "os:ubuntu-latest;pub-cache-hosted;sdk:stable;packages:pkgs/test;commands:command_00"
- restore-keys: |
- os:ubuntu-latest;pub-cache-hosted;sdk:stable;packages:pkgs/test
- os:ubuntu-latest;pub-cache-hosted;sdk:stable
- os:ubuntu-latest;pub-cache-hosted
- os:ubuntu-latest
- - uses: dart-lang/setup-dart@6a218f2413a3e78e9087f638a238f6b40893203d
- with:
- sdk: stable
- - id: checkout
- uses: actions/checkout@d0651293c4a5a52e711f25b41b05b2212f385d28
- - id: pkgs_test_pub_upgrade
- name: pkgs/test; dart pub upgrade
- if: "always() && steps.checkout.conclusion == 'success'"
- working-directory: pkgs/test
- run: dart pub upgrade
- - name: "pkgs/test; xvfb-run -s \"-screen 0 1024x768x24\" dart test --preset travis --total-shards 5 --shard-index 0"
- if: "always() && steps.pkgs_test_pub_upgrade.conclusion == 'success'"
- working-directory: pkgs/test
- run: "xvfb-run -s \"-screen 0 1024x768x24\" dart test --preset travis --total-shards 5 --shard-index 0"
- needs:
- - job_001
- - job_002
job_016:
- name: "unit_test; linux; Dart stable; PKG: pkgs/test; `xvfb-run -s \"-screen 0 1024x768x24\" dart test --preset travis --total-shards 5 --shard-index 1`"
+ name: "unit_test; linux; Dart stable; PKG: pkgs/test; `xvfb-run -s \"-screen 0 1024x768x24\" dart test --preset travis --total-shards 5 --shard-index 0`"
runs-on: ubuntu-latest
steps:
- name: Cache Pub hosted dependencies
@@ -574,15 +574,15 @@
if: "always() && steps.checkout.conclusion == 'success'"
working-directory: pkgs/test
run: dart pub upgrade
- - name: "pkgs/test; xvfb-run -s \"-screen 0 1024x768x24\" dart test --preset travis --total-shards 5 --shard-index 1"
+ - name: "pkgs/test; xvfb-run -s \"-screen 0 1024x768x24\" dart test --preset travis --total-shards 5 --shard-index 0"
if: "always() && steps.pkgs_test_pub_upgrade.conclusion == 'success'"
working-directory: pkgs/test
- run: "xvfb-run -s \"-screen 0 1024x768x24\" dart test --preset travis --total-shards 5 --shard-index 1"
+ run: "xvfb-run -s \"-screen 0 1024x768x24\" dart test --preset travis --total-shards 5 --shard-index 0"
needs:
- job_001
- job_002
job_017:
- name: "unit_test; linux; Dart stable; PKG: pkgs/test; `xvfb-run -s \"-screen 0 1024x768x24\" dart test --preset travis --total-shards 5 --shard-index 2`"
+ name: "unit_test; linux; Dart stable; PKG: pkgs/test; `xvfb-run -s \"-screen 0 1024x768x24\" dart test --preset travis --total-shards 5 --shard-index 1`"
runs-on: ubuntu-latest
steps:
- name: Cache Pub hosted dependencies
@@ -605,15 +605,15 @@
if: "always() && steps.checkout.conclusion == 'success'"
working-directory: pkgs/test
run: dart pub upgrade
- - name: "pkgs/test; xvfb-run -s \"-screen 0 1024x768x24\" dart test --preset travis --total-shards 5 --shard-index 2"
+ - name: "pkgs/test; xvfb-run -s \"-screen 0 1024x768x24\" dart test --preset travis --total-shards 5 --shard-index 1"
if: "always() && steps.pkgs_test_pub_upgrade.conclusion == 'success'"
working-directory: pkgs/test
- run: "xvfb-run -s \"-screen 0 1024x768x24\" dart test --preset travis --total-shards 5 --shard-index 2"
+ run: "xvfb-run -s \"-screen 0 1024x768x24\" dart test --preset travis --total-shards 5 --shard-index 1"
needs:
- job_001
- job_002
job_018:
- name: "unit_test; linux; Dart stable; PKG: pkgs/test; `xvfb-run -s \"-screen 0 1024x768x24\" dart test --preset travis --total-shards 5 --shard-index 3`"
+ name: "unit_test; linux; Dart stable; PKG: pkgs/test; `xvfb-run -s \"-screen 0 1024x768x24\" dart test --preset travis --total-shards 5 --shard-index 2`"
runs-on: ubuntu-latest
steps:
- name: Cache Pub hosted dependencies
@@ -636,15 +636,15 @@
if: "always() && steps.checkout.conclusion == 'success'"
working-directory: pkgs/test
run: dart pub upgrade
- - name: "pkgs/test; xvfb-run -s \"-screen 0 1024x768x24\" dart test --preset travis --total-shards 5 --shard-index 3"
+ - name: "pkgs/test; xvfb-run -s \"-screen 0 1024x768x24\" dart test --preset travis --total-shards 5 --shard-index 2"
if: "always() && steps.pkgs_test_pub_upgrade.conclusion == 'success'"
working-directory: pkgs/test
- run: "xvfb-run -s \"-screen 0 1024x768x24\" dart test --preset travis --total-shards 5 --shard-index 3"
+ run: "xvfb-run -s \"-screen 0 1024x768x24\" dart test --preset travis --total-shards 5 --shard-index 2"
needs:
- job_001
- job_002
job_019:
- name: "unit_test; linux; Dart stable; PKG: pkgs/test; `xvfb-run -s \"-screen 0 1024x768x24\" dart test --preset travis --total-shards 5 --shard-index 4`"
+ name: "unit_test; linux; Dart stable; PKG: pkgs/test; `xvfb-run -s \"-screen 0 1024x768x24\" dart test --preset travis --total-shards 5 --shard-index 3`"
runs-on: ubuntu-latest
steps:
- name: Cache Pub hosted dependencies
@@ -667,6 +667,37 @@
if: "always() && steps.checkout.conclusion == 'success'"
working-directory: pkgs/test
run: dart pub upgrade
+ - name: "pkgs/test; xvfb-run -s \"-screen 0 1024x768x24\" dart test --preset travis --total-shards 5 --shard-index 3"
+ if: "always() && steps.pkgs_test_pub_upgrade.conclusion == 'success'"
+ working-directory: pkgs/test
+ run: "xvfb-run -s \"-screen 0 1024x768x24\" dart test --preset travis --total-shards 5 --shard-index 3"
+ needs:
+ - job_001
+ - job_002
+ job_020:
+ name: "unit_test; linux; Dart stable; PKG: pkgs/test; `xvfb-run -s \"-screen 0 1024x768x24\" dart test --preset travis --total-shards 5 --shard-index 4`"
+ runs-on: ubuntu-latest
+ steps:
+ - name: Cache Pub hosted dependencies
+ uses: actions/cache@4504faf7e9bcf8f3ed0bc863c4e1d21499ab8ef8
+ with:
+ path: "~/.pub-cache/hosted"
+ key: "os:ubuntu-latest;pub-cache-hosted;sdk:stable;packages:pkgs/test;commands:command_05"
+ restore-keys: |
+ os:ubuntu-latest;pub-cache-hosted;sdk:stable;packages:pkgs/test
+ os:ubuntu-latest;pub-cache-hosted;sdk:stable
+ os:ubuntu-latest;pub-cache-hosted
+ os:ubuntu-latest
+ - uses: dart-lang/setup-dart@6a218f2413a3e78e9087f638a238f6b40893203d
+ with:
+ sdk: stable
+ - id: checkout
+ uses: actions/checkout@d0651293c4a5a52e711f25b41b05b2212f385d28
+ - id: pkgs_test_pub_upgrade
+ name: pkgs/test; dart pub upgrade
+ if: "always() && steps.checkout.conclusion == 'success'"
+ working-directory: pkgs/test
+ run: dart pub upgrade
- name: "pkgs/test; xvfb-run -s \"-screen 0 1024x768x24\" dart test --preset travis --total-shards 5 --shard-index 4"
if: "always() && steps.pkgs_test_pub_upgrade.conclusion == 'success'"
working-directory: pkgs/test
@@ -674,7 +705,7 @@
needs:
- job_001
- job_002
- job_020:
+ job_021:
name: "unit_test; linux; Dart stable; PKG: pkgs/test_api; `dart test --preset travis -x browser`"
runs-on: ubuntu-latest
steps:
@@ -682,7 +713,7 @@
uses: actions/cache@4504faf7e9bcf8f3ed0bc863c4e1d21499ab8ef8
with:
path: "~/.pub-cache/hosted"
- key: "os:ubuntu-latest;pub-cache-hosted;sdk:stable;packages:pkgs/test_api;commands:command_10"
+ key: "os:ubuntu-latest;pub-cache-hosted;sdk:stable;packages:pkgs/test_api;commands:command_11"
restore-keys: |
os:ubuntu-latest;pub-cache-hosted;sdk:stable;packages:pkgs/test_api
os:ubuntu-latest;pub-cache-hosted;sdk:stable
@@ -705,7 +736,7 @@
needs:
- job_001
- job_002
- job_021:
+ job_022:
name: "unit_test; windows; Dart dev; PKG: integration_tests/nnbd_opted_in; `dart test -p chrome,vm,node`"
runs-on: windows-latest
steps:
@@ -726,7 +757,7 @@
needs:
- job_001
- job_002
- job_022:
+ job_023:
name: "unit_test; windows; Dart dev; PKG: integration_tests/nnbd_opted_out; `dart test -p chrome,vm,node`"
runs-on: windows-latest
steps:
@@ -747,7 +778,7 @@
needs:
- job_001
- job_002
- job_023:
+ job_024:
name: "unit_test; windows; Dart dev; PKG: integration_tests/spawn_hybrid; `dart test -p chrome,vm,node`"
runs-on: windows-latest
steps:
@@ -768,7 +799,7 @@
needs:
- job_001
- job_002
- job_024:
+ job_025:
name: "unit_test; windows; Dart stable; PKG: integration_tests/nnbd_opted_in; `dart test -p chrome,vm,node`"
runs-on: windows-latest
steps:
@@ -789,7 +820,7 @@
needs:
- job_001
- job_002
- job_025:
+ job_026:
name: "unit_test; windows; Dart stable; PKG: integration_tests/nnbd_opted_out; `dart test -p chrome,vm,node`"
runs-on: windows-latest
steps:
@@ -810,7 +841,7 @@
needs:
- job_001
- job_002
- job_026:
+ job_027:
name: "unit_test; windows; Dart stable; PKG: integration_tests/spawn_hybrid; `dart test -p chrome,vm,node`"
runs-on: windows-latest
steps:
@@ -831,7 +862,7 @@
needs:
- job_001
- job_002
- job_027:
+ job_028:
name: "unit_test; windows; Dart stable; PKG: pkgs/test; `dart test --preset travis --total-shards 5 --shard-index 0`"
runs-on: windows-latest
steps:
@@ -852,7 +883,7 @@
needs:
- job_001
- job_002
- job_028:
+ job_029:
name: "unit_test; windows; Dart stable; PKG: pkgs/test; `dart test --preset travis --total-shards 5 --shard-index 1`"
runs-on: windows-latest
steps:
@@ -873,7 +904,7 @@
needs:
- job_001
- job_002
- job_029:
+ job_030:
name: "unit_test; windows; Dart stable; PKG: pkgs/test; `dart test --preset travis --total-shards 5 --shard-index 2`"
runs-on: windows-latest
steps:
@@ -894,7 +925,7 @@
needs:
- job_001
- job_002
- job_030:
+ job_031:
name: "unit_test; windows; Dart stable; PKG: pkgs/test; `dart test --preset travis --total-shards 5 --shard-index 3`"
runs-on: windows-latest
steps:
@@ -915,7 +946,7 @@
needs:
- job_001
- job_002
- job_031:
+ job_032:
name: "unit_test; windows; Dart stable; PKG: pkgs/test; `dart test --preset travis --total-shards 5 --shard-index 4`"
runs-on: windows-latest
steps:
@@ -936,7 +967,7 @@
needs:
- job_001
- job_002
- job_032:
+ job_033:
name: Notify failure
runs-on: ubuntu-latest
if: "(github.event_name == 'push' || github.event_name == 'schedule') && failure()"
@@ -979,3 +1010,4 @@
- job_029
- job_030
- job_031
+ - job_032
diff --git a/pkgs/checks/lib/src/extensions/core.dart b/pkgs/checks/lib/src/extensions/core.dart
index 2fe29a2..446bea2 100644
--- a/pkgs/checks/lib/src/extensions/core.dart
+++ b/pkgs/checks/lib/src/extensions/core.dart
@@ -52,26 +52,36 @@
///
/// Asynchronous expectations are not allowed in [condition].
void not(void Function(Check<T>) condition) {
- context.expect(() {
- return ['is not a value that:', ...indent(describe(condition))];
- }, (actual) {
- if (softCheck(actual, condition) != null) return null;
- return Rejection(
+ context.expect(
+ () => ['is not a value that:', ...indent(describe(condition))],
+ (actual) {
+ if (softCheck(actual, condition) != null) return null;
+ return Rejection(
actual: literal(actual),
- which: ['is a value that: ', ...indent(describe(condition))]);
- });
+ which: ['is a value that: ', ...indent(describe(condition))],
+ );
+ },
+ );
}
}
extension BoolChecks on Check<bool> {
void isTrue() {
- context.expect(() => ['is true'],
- (actual) => actual ? null : Rejection(actual: literal(actual)));
+ context.expect(
+ () => ['is true'],
+ (actual) => actual
+ ? null // force coverage
+ : Rejection(actual: literal(actual)),
+ );
}
void isFalse() {
- context.expect(() => ['is false'],
- (actual) => !actual ? null : Rejection(actual: literal(actual)));
+ context.expect(
+ () => ['is false'],
+ (actual) => !actual
+ ? null // force coverage
+ : Rejection(actual: literal(actual)),
+ );
}
}
@@ -112,10 +122,12 @@
extension StringChecks on Check<String> {
/// Expects that the value contains [pattern] according to [String.contains];
void contains(Pattern pattern) {
- context.expect(() => ['contains $pattern'], (actual) {
+ context.expect(() => ['contains ${literal(pattern)}'], (actual) {
if (actual.contains(pattern)) return null;
return Rejection(
- actual: literal(actual), which: ['Does not contain $pattern']);
+ actual: literal(actual),
+ which: ['Does not contain ${literal(pattern)}'],
+ );
});
}
diff --git a/pkgs/checks/mono_pkg.yaml b/pkgs/checks/mono_pkg.yaml
index 099f481..033bd63 100644
--- a/pkgs/checks/mono_pkg.yaml
+++ b/pkgs/checks/mono_pkg.yaml
@@ -8,3 +8,6 @@
- group:
- format
- analyze: --fatal-infos
+- unit_test:
+ - group:
+ - command: dart test
diff --git a/pkgs/checks/test/extensions/core_test.dart b/pkgs/checks/test/extensions/core_test.dart
new file mode 100644
index 0000000..432419e
--- /dev/null
+++ b/pkgs/checks/test/extensions/core_test.dart
@@ -0,0 +1,159 @@
+import 'package:checks/checks.dart';
+import 'package:checks/context.dart';
+import 'package:test/scaffolding.dart';
+
+void main() {
+ group('TypeChecks', () {
+ test('isA', () {
+ checkThat(1).isA<int>();
+
+ checkThat(
+ softCheck(1, (p0) => p0.isA<String>()),
+ ).isARejection(actual: '<1>', which: ['Is a int']);
+ });
+ });
+
+ group('HasField', () {
+ test('has', () {
+ checkThat(1).has((v) => v.isOdd, 'isOdd').isTrue();
+
+ checkThat(
+ softCheck<int>(
+ 2,
+ (p0) => p0.has((v) => throw UnimplementedError(), 'isOdd'),
+ ),
+ ).isARejection(
+ actual: '<2>',
+ which: ['threw while trying to read property'],
+ );
+ });
+
+ test('that', () {
+ checkThat(true).that((p0) => p0.isTrue());
+ });
+
+ test('not', () {
+ checkThat(false).not((p0) => p0.isTrue());
+
+ checkThat(
+ softCheck<bool>(
+ true,
+ (p0) => p0.not((p0) => p0.isTrue()),
+ ),
+ ).isARejection(
+ actual: '<true>',
+ which: ['is a value that: ', ' is true'],
+ );
+ });
+ });
+
+ group('BoolChecks', () {
+ test('isTrue', () {
+ checkThat(true).isTrue();
+
+ checkThat(
+ softCheck<bool>(
+ false,
+ (p0) => p0.isTrue(),
+ ),
+ ).isARejection(actual: '<false>');
+ });
+
+ test('isFalse', () {
+ checkThat(false).isFalse();
+
+ checkThat(softCheck<bool>(
+ true,
+ (p0) => p0.isFalse(),
+ )).isARejection(actual: '<true>');
+ });
+ });
+
+ group('EqualityChecks', () {
+ test('equals', () {
+ checkThat(1).equals(1);
+
+ checkThat(
+ softCheck(1, (p0) => p0.equals(2)),
+ ).isARejection(actual: '<1>', which: ['are not equal']);
+ });
+
+ test('identical', () {
+ checkThat(1).identicalTo(1);
+
+ checkThat(softCheck(1, (p0) => p0.identicalTo(2)))
+ .isARejection(actual: '<1>', which: ['is not identical']);
+ });
+ });
+
+ group('NullabilityChecks', () {
+ test('isNotNull', () {
+ checkThat(1).isNotNull();
+
+ checkThat(softCheck(null, (p0) => p0.isNotNull()))
+ .isARejection(actual: '<null>');
+ });
+
+ test('isNull', () {
+ checkThat(null).isNull();
+
+ checkThat(softCheck(1, (p0) => p0.isNull())).isARejection(actual: '<1>');
+ });
+ });
+
+ group('StringChecks', () {
+ test('contains', () {
+ checkThat('bob').contains('bo');
+ checkThat(
+ softCheck<String>('bob', (p0) => p0.contains('kayleb')),
+ ).isARejection(actual: "'bob'", which: ["Does not contain 'kayleb'"]);
+ });
+ test('length', () {
+ checkThat('bob').length.equals(3);
+ });
+ test('isEmpty', () {
+ checkThat('').isEmpty();
+ checkThat(
+ softCheck<String>('bob', (p0) => p0.isEmpty()),
+ ).isARejection(actual: "'bob'", which: ['is not empty']);
+ });
+ test('isNotEmpty', () {
+ checkThat('bob').isNotEmpty();
+ checkThat(
+ softCheck<String>('', (p0) => p0.isNotEmpty()),
+ ).isARejection(actual: "''", which: ['is empty']);
+ });
+ test('startsWith', () {
+ checkThat('bob').startsWith('bo');
+ checkThat(
+ softCheck<String>('bob', (p0) => p0.startsWith('kayleb')),
+ ).isARejection(actual: "'bob'", which: ["does not start with 'kayleb'"]);
+ });
+ test('endsWith', () {
+ checkThat('bob').endsWith('ob');
+ checkThat(softCheck<String>('bob', (p0) => p0.endsWith('kayleb')))
+ .isARejection(actual: "'bob'", which: ["does not end with 'kayleb'"]);
+ });
+ });
+}
+
+extension on Check<Iterable<String>?> {
+ // TODO: remove this once we have a deepEquals or equivalent
+ void toStringEquals(List<String>? other) {
+ final otherToString = other.toString();
+ context.expect(() => ['toString equals'], (actual) {
+ final actualToString = actual.toString();
+ return actual.toString() == otherToString
+ ? null
+ : Rejection(actual: actualToString);
+ });
+ }
+}
+
+extension on Check<Rejection?> {
+ void isARejection({List<String>? which, required String actual}) {
+ this.isNotNull()
+ ..has((p0) => p0.actual, 'actual').equals(actual)
+ ..has((p0) => p0.which, 'which').toStringEquals(which);
+ }
+}
diff --git a/tool/ci.sh b/tool/ci.sh
index b5178ff..ec94227 100755
--- a/tool/ci.sh
+++ b/tool/ci.sh
@@ -72,46 +72,50 @@
dart analyze --fatal-infos || EXIT_CODE=$?
;;
command_00)
+ echo 'dart test'
+ dart test || EXIT_CODE=$?
+ ;;
+ command_01)
echo 'xvfb-run -s "-screen 0 1024x768x24" dart test --preset travis --total-shards 5 --shard-index 0'
xvfb-run -s "-screen 0 1024x768x24" dart test --preset travis --total-shards 5 --shard-index 0 || EXIT_CODE=$?
;;
- command_01)
+ command_02)
echo 'xvfb-run -s "-screen 0 1024x768x24" dart test --preset travis --total-shards 5 --shard-index 1'
xvfb-run -s "-screen 0 1024x768x24" dart test --preset travis --total-shards 5 --shard-index 1 || EXIT_CODE=$?
;;
- command_02)
+ command_03)
echo 'xvfb-run -s "-screen 0 1024x768x24" dart test --preset travis --total-shards 5 --shard-index 2'
xvfb-run -s "-screen 0 1024x768x24" dart test --preset travis --total-shards 5 --shard-index 2 || EXIT_CODE=$?
;;
- command_03)
+ command_04)
echo 'xvfb-run -s "-screen 0 1024x768x24" dart test --preset travis --total-shards 5 --shard-index 3'
xvfb-run -s "-screen 0 1024x768x24" dart test --preset travis --total-shards 5 --shard-index 3 || EXIT_CODE=$?
;;
- command_04)
+ command_05)
echo 'xvfb-run -s "-screen 0 1024x768x24" dart test --preset travis --total-shards 5 --shard-index 4'
xvfb-run -s "-screen 0 1024x768x24" dart test --preset travis --total-shards 5 --shard-index 4 || EXIT_CODE=$?
;;
- command_05)
+ command_06)
echo 'dart test --preset travis --total-shards 5 --shard-index 0'
dart test --preset travis --total-shards 5 --shard-index 0 || EXIT_CODE=$?
;;
- command_06)
+ command_07)
echo 'dart test --preset travis --total-shards 5 --shard-index 1'
dart test --preset travis --total-shards 5 --shard-index 1 || EXIT_CODE=$?
;;
- command_07)
+ command_08)
echo 'dart test --preset travis --total-shards 5 --shard-index 2'
dart test --preset travis --total-shards 5 --shard-index 2 || EXIT_CODE=$?
;;
- command_08)
+ command_09)
echo 'dart test --preset travis --total-shards 5 --shard-index 3'
dart test --preset travis --total-shards 5 --shard-index 3 || EXIT_CODE=$?
;;
- command_09)
+ command_10)
echo 'dart test --preset travis --total-shards 5 --shard-index 4'
dart test --preset travis --total-shards 5 --shard-index 4 || EXIT_CODE=$?
;;
- command_10)
+ command_11)
echo 'dart test --preset travis -x browser'
dart test --preset travis -x browser || EXIT_CODE=$?
;;