Browse Source

Updated the tests

tags/v8.0.0
Cédric Belin 2 months ago
parent
commit
1f5b2132f7
5 changed files with 22 additions and 26 deletions
  1. +2
    -0
      CHANGELOG.md
  2. +0
    -4
      lib/src/io/finder.dart
  3. +4
    -4
      test/file_stat_test.dart
  4. +6
    -7
      test/finder_test.dart
  5. +10
    -11
      test/where_test.dart

+ 2
- 0
CHANGELOG.md View File

@@ -2,6 +2,8 @@

## Version [8.0.0](https://git.belin.io/cedx/where.dart/compare/v7.0.0...v8.0.0)
- Breaking change: removed the `Finder.pathSeparator` property.
- Breaking change: the `extensions` and `path` arguments don't accept strings anymore.
- Replaced the build system based on [Grinder](https://pub.dev/packages/grinder) by [PowerShell](https://docs.microsoft.com/en-us/powershell) scripts.
- Updated the package dependencies.

## Version [7.0.0](https://git.belin.io/cedx/where.dart/compare/v6.6.0...v6.7.0)


+ 0
- 4
lib/src/io/finder.dart View File

@@ -50,20 +50,16 @@ class Finder {

/// Checks that the file referenced by the specified [fileStats] is executable according to its permissions.
Future<bool> _checkFilePermissions(FileStat fileStats) async {
// Others.
final perms = fileStats.mode;
if (perms & int.parse("001", radix: 8) != 0) return true;

// Group.
final execByGroup = int.parse("010", radix: 8);
if (perms & execByGroup != 0) return fileStats.gid == await _getProcessId("g");

// Owner.
final execByOwner = int.parse("100", radix: 8);
final userId = await _getProcessId("u");
if (perms & execByOwner != 0) return fileStats.uid == userId;

// Root.
return (perms & (execByOwner | execByGroup) != 0) && userId == 0;
}



+ 4
- 4
test/file_stat_test.dart View File

@@ -20,12 +20,12 @@ void main() => group("FileStat", () {

test("should return a numeric identity greater than or equal to 0 for the file owner", () async {
final fileStats = await FileStat.stat("test/file_stat_test.dart");
expect(fileStats.uid, Platform.isWindows ? -1 : greaterThanOrEqualTo(0));
expect(fileStats.uid, Finder.isWindows ? -1 : greaterThanOrEqualTo(0));
});

test("should return a numeric identity greater than or equal to 0 for the file group", () async {
final fileStats = await FileStat.stat("test/file_stat_test.dart");
expect(fileStats.gid, Platform.isWindows ? -1 : greaterThanOrEqualTo(0));
expect(fileStats.gid, Finder.isWindows ? -1 : greaterThanOrEqualTo(0));
});
});

@@ -38,12 +38,12 @@ void main() => group("FileStat", () {

test("should return a numeric identity greater than or equal to 0 for the file owner", () {
final fileStats = FileStat.statSync("test/file_stat_test.dart");
expect(fileStats.uid, Platform.isWindows ? -1 : greaterThanOrEqualTo(0));
expect(fileStats.uid, Finder.isWindows ? -1 : greaterThanOrEqualTo(0));
});

test("should return a numeric identity greater than or equal to 0 for the file group", () {
final fileStats = FileStat.statSync("test/file_stat_test.dart");
expect(fileStats.gid, Platform.isWindows ? -1 : greaterThanOrEqualTo(0));
expect(fileStats.gid, Finder.isWindows ? -1 : greaterThanOrEqualTo(0));
});
});
});

+ 6
- 7
test/finder_test.dart View File

@@ -1,4 +1,3 @@
import "dart:io";
import "package:test/test.dart";
import "package:where/where.dart";

@@ -7,14 +6,14 @@ void main() => group("Finder", () {
group(".find()", () {
test("should return the path of the `executable.cmd` file on Windows", () async {
final executables = await Finder(path: ["test/fixtures"]).find("executable").toList();
expect(executables.length, Platform.isWindows ? 1 : 0);
if (Platform.isWindows) expect(executables.first.path, endsWith(r"\test\fixtures\executable.cmd"));
expect(executables.length, Finder.isWindows ? 1 : 0);
if (Finder.isWindows) expect(executables.first.path, endsWith(r"\test\fixtures\executable.cmd"));
});

test("should return the path of the `executable.sh` file on POSIX", () async {
final executables = await Finder(path: ["test/fixtures"]).find("executable.sh").toList();
expect(executables.length, Platform.isWindows ? 0 : 1);
if (!Platform.isWindows) expect(executables.first.path, endsWith("/test/fixtures/executable.sh"));
expect(executables.length, Finder.isWindows ? 0 : 1);
if (!Finder.isWindows) expect(executables.first.path, endsWith("/test/fixtures/executable.sh"));
});
});

@@ -28,11 +27,11 @@ void main() => group("Finder", () {
});

test("should return `false` for a POSIX executable, when test is run on Windows", () async {
expect(await Finder().isExecutable("test/fixtures/executable.sh"), isNot(Platform.isWindows));
expect(await Finder().isExecutable("test/fixtures/executable.sh"), isNot(Finder.isWindows));
});

test("should return `false` for a Windows executable, when test is run on POSIX", () async {
expect(await Finder().isExecutable("test/fixtures/executable.cmd"), Platform.isWindows);
expect(await Finder().isExecutable("test/fixtures/executable.cmd"), Finder.isWindows);
});
});
});

+ 10
- 11
test/where_test.dart View File

@@ -1,4 +1,3 @@
import "dart:io";
import "package:test/test.dart";
import "package:where/where.dart";

@@ -7,12 +6,12 @@ void main() => group("where()", () {
test("should return the path of the `executable.cmd` file on Windows", () async {
try {
final executable = await where("executable", all: false, path: ["test/fixtures"]);
if (!Platform.isWindows) fail("Exception not thrown");
if (!Finder.isWindows) fail("Exception not thrown");
else expect(executable, allOf(const TypeMatcher<String>(), endsWith(r"\test\fixtures\executable.cmd")));
}

on Exception catch (err) {
if (Platform.isWindows) fail(err.toString());
if (Finder.isWindows) fail(err.toString());
else expect(err, const TypeMatcher<FinderException>());
}
});
@@ -20,7 +19,7 @@ void main() => group("where()", () {
test("should return all the paths of the `executable.cmd` file on Windows", () async {
try {
final executables = await where("executable", all: true, path: ["test/fixtures"]);
if (!Platform.isWindows) fail("Exception not thrown");
if (!Finder.isWindows) fail("Exception not thrown");
else {
expect(executables, allOf(isList, hasLength(1)));
expect(executables.first, allOf(const TypeMatcher<String>(), endsWith(r"\test\fixtures\executable.cmd")));
@@ -28,7 +27,7 @@ void main() => group("where()", () {
}

on Exception catch (err) {
if (Platform.isWindows) fail(err.toString());
if (Finder.isWindows) fail(err.toString());
else expect(err, const TypeMatcher<FinderException>());
}
});
@@ -36,12 +35,12 @@ void main() => group("where()", () {
test("should return the path of the `executable.sh` file on POSIX", () async {
try {
final executable = await where("executable.sh", all: false, path: ["test/fixtures"]);
if (Platform.isWindows) fail("Exception not thrown");
if (Finder.isWindows) fail("Exception not thrown");
else expect(executable, allOf(const TypeMatcher<String>(), endsWith("/test/fixtures/executable.sh")));
}

on Exception catch (err) {
if (!Platform.isWindows) fail(err.toString());
if (!Finder.isWindows) fail(err.toString());
else expect(err, const TypeMatcher<FinderException>());
}
});
@@ -49,7 +48,7 @@ void main() => group("where()", () {
test("should return all the paths of the `executable.sh` file on POSIX", () async {
try {
final executables = await where("executable.sh", all: true, path: ["test/fixtures"]);
if (Platform.isWindows) fail("Exception not thrown");
if (Finder.isWindows) fail("Exception not thrown");
else {
expect(executables, allOf(isList, hasLength(1)));
expect(executables.first, allOf(const TypeMatcher<String>(), endsWith("/test/fixtures/executable.sh")));
@@ -57,17 +56,17 @@ void main() => group("where()", () {
}

on Exception catch (err) {
if (!Platform.isWindows) fail(err.toString());
if (!Finder.isWindows) fail(err.toString());
else expect(err, const TypeMatcher<FinderException>());
}
});

test("should return the value of the `onError` handler", () async {
final executable = await where("executable", all: false, onError: (_) => "foo", path: ["test/fixtures"]);
if (!Platform.isWindows) expect(executable, "foo");
if (!Finder.isWindows) expect(executable, "foo");

final executables = await where("executable.sh", all: true, onError: (_) => ["foo"], path: ["test/fixtures"]);
if (Platform.isWindows) {
if (Finder.isWindows) {
expect(executables, allOf(isList, hasLength(1)));
expect(executables.first, "foo");
}


Loading…
Cancel
Save