os_utils_test.dart 1.55 KB
Newer Older
1 2 3 4 5
// 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.

import 'package:flutter_tools/src/base/file_system.dart';
6
import 'package:flutter_tools/src/base/logger.dart';
7
import 'package:flutter_tools/src/base/os.dart';
8
import 'package:flutter_tools/src/base/platform.dart';
9
import 'package:process/process.dart';
10 11

import '../../src/common.dart';
12
import '../../src/context.dart';
13 14 15

void main() {
  group('OperatingSystemUtils', () {
16 17
    late Directory tempDir;
    late FileSystem fileSystem;
18 19

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

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

28 29 30 31 32 33 34 35 36
    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'));
37
      file.writeAsStringSync('hello world');
38
      operatingSystemUtils.makeExecutable(file);
39 40

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