blob: 913c434dafea7f8f384f000649b91b55c26038b4 [file] [edit]
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// Compile this file for a specific platform, for example as:
//
// dart compile exe --target-os=linux tree_shake_pattern_eq.dart
// dart compile js -o tree_shake_pattern_eq.js tree_shake_pattern_eq.dart
//
// and check that the executable does not contain the strings for
// other platforms. For example on Linux, use:
//
// strings tree_shake_pattern_eq.{exe,js} | grep "RUNNING"
//
// and check that the only retained value is either `RUNNING ON LINUX` or
// `RUNNING IN A BROWSER`.
import 'package:platform/platform.dart';
void main() {
const expectedPlatform = bool.fromEnvironment('dart.library.js_interop')
? 'browser'
: bool.fromEnvironment('dart.library.io')
? 'native'
: 'unknown';
print('Expected platform: $expectedPlatform');
switch (Platform.current) {
case Platform(:var browserPlatform?):
print('RUNNING IN A BROWSER');
print('User-agent: ${browserPlatform.userAgent}');
case Platform(
nativePlatform: NativePlatform(operatingSystem: == NativePlatform.linux)
):
print('RUNNING ON LINUX');
case Platform(
nativePlatform: NativePlatform(operatingSystem: == NativePlatform.macOS)
):
print('RUNNING ON MACOS');
case Platform(
nativePlatform: NativePlatform(
operatingSystem: == NativePlatform.windows
)
):
print('RUNNING ON WINDOWS');
}
}