os_utils_test.dart 1.58 KB
Newer Older
1 2 3 4
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

5 6
// @dart = 2.8

7
import 'package:flutter_tools/src/base/file_system.dart';
8
import 'package:flutter_tools/src/base/logger.dart';
9
import 'package:flutter_tools/src/base/os.dart';
10 11
import 'package:flutter_tools/src/base/platform.dart';
import 'package:flutter_tools/src/base/signals.dart';
12
import 'package:process/process.dart';
13 14 15 16 17 18

import '../../src/common.dart';

void main() {
  group('OperatingSystemUtils', () {
    Directory tempDir;
19
    FileSystem fileSystem;
20 21

    setUp(() {
22 23
      fileSystem = LocalFileSystem.test(signals: Signals.test());
      tempDir = fileSystem.systemTempDirectory.createTempSync('flutter_tools_os_utils_test.');
24 25 26 27 28 29
    });

    tearDown(() {
      tryToDelete(tempDir);
    });

30 31 32 33 34 35 36 37 38
    testWithoutContext('makeExecutable', () async {
      const Platform platform = LocalPlatform();
      final OperatingSystemUtils operatingSystemUtils = OperatingSystemUtils(
        fileSystem: fileSystem,
        logger: BufferLogger.test(),
        platform: platform,
        processManager: const LocalProcessManager(),
      );
      final File file = fileSystem.file(fileSystem.path.join(tempDir.path, 'foo.script'));
39
      file.writeAsStringSync('hello world');
40
      operatingSystemUtils.makeExecutable(file);
41 42

      // Skip this test on windows.
43
      if (!platform.isWindows) {
44 45 46 47 48 49 50
        final String mode = file.statSync().modeString();
        // rwxr--r--
        expect(mode.substring(0, 3), endsWith('x'));
      }
    });
  });
}