| // Copyright 2015 Google Inc. All rights reserved. |
| // |
| // Licensed under the Apache License, Version 2.0 (the "License"); |
| // you may not use this file except in compliance with the License. |
| // You may obtain a copy of the License at |
| // |
| // http://www.apache.org/licenses/LICENSE-2.0 |
| // |
| // Unless required by applicable law or agreed to in writing, software |
| // distributed under the License is distributed on an "AS IS" BASIS, |
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| // See the License for the specific language governing permissions and |
| // limitations under the License. |
| package com.google.devtools.build.lib.shell; |
| |
| import static org.junit.Assert.assertEquals; |
| import static org.junit.Assert.assertNotNull; |
| |
| import org.junit.Before; |
| import org.junit.Test; |
| import org.junit.runner.RunWith; |
| import org.junit.runners.JUnit4; |
| |
| import java.util.logging.Level; |
| import java.util.logging.Logger; |
| |
| /** |
| * Unit tests for {@link Shell}. |
| */ |
| @RunWith(JUnit4.class) |
| public class ShellTest { |
| |
| @Before |
| public void setUp() throws Exception { |
| |
| // enable all log statements to ensure there are no problems with |
| // logging code |
| Logger.getLogger("com.google.devtools.build.lib.shell.Command").setLevel(Level.FINEST); |
| } |
| |
| @Test |
| public void testPlatformShell() { |
| assertNotNull(Shell.getPlatformShell()); |
| } |
| |
| @Test |
| public void testLinux() { |
| if (!"Linux".equals(System.getProperty("os.name"))) { |
| return; |
| } |
| final Shell shell = Shell.getPlatformShell(); |
| final String[] shellified = shell.shellify("echo FOO"); |
| assertNotNull(shellified); |
| assertEquals(3, shellified.length); |
| assertEquals("/bin/sh", shellified[0]); |
| assertEquals("-c", shellified[1]); |
| assertEquals("echo FOO", shellified[2]); |
| } |
| |
| } |