Damien Martin-Guillerez | f88f4d8 | 2015-09-25 13:56:55 +0000 | [diff] [blame] | 1 | // Copyright 2014 The Bazel Authors. All rights reserved. |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
Ulf Adams | 8afbd3c | 2017-02-28 10:42:48 +0000 | [diff] [blame] | 14 | package com.google.devtools.build.lib.unix; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 15 | |
lberki | aea56b3 | 2017-05-30 12:35:33 +0200 | [diff] [blame] | 16 | import static com.google.common.truth.Truth.assertThat; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 17 | import static org.junit.Assert.fail; |
| 18 | |
Ulf Adams | 8afbd3c | 2017-02-28 10:42:48 +0000 | [diff] [blame] | 19 | import com.google.devtools.build.lib.vfs.FileSystem; |
| 20 | import com.google.devtools.build.lib.vfs.FileSystemUtils; |
| 21 | import com.google.devtools.build.lib.vfs.Path; |
| 22 | import com.google.devtools.build.lib.vfs.SymlinkAwareFileSystemTest; |
| 23 | import com.google.devtools.build.lib.vfs.Symlinks; |
| 24 | import java.io.IOException; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 25 | import org.junit.Test; |
| 26 | import org.junit.runner.RunWith; |
| 27 | import org.junit.runners.JUnit4; |
| 28 | |
Ulf Adams | 8afbd3c | 2017-02-28 10:42:48 +0000 | [diff] [blame] | 29 | /** Tests for the {@link com.google.devtools.build.lib.unix.UnixFileSystem} class. */ |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 30 | @RunWith(JUnit4.class) |
| 31 | public class UnixFileSystemTest extends SymlinkAwareFileSystemTest { |
| 32 | |
| 33 | @Override |
| 34 | protected FileSystem getFreshFileSystem() { |
| 35 | return new UnixFileSystem(); |
| 36 | } |
| 37 | |
| 38 | @Override |
| 39 | public void destroyFileSystem(FileSystem fileSystem) { |
| 40 | // Nothing. |
| 41 | } |
| 42 | |
| 43 | @Override |
| 44 | protected void expectNotFound(Path path) throws IOException { |
lberki | aea56b3 | 2017-05-30 12:35:33 +0200 | [diff] [blame] | 45 | assertThat(path.statIfFound()).isNull(); |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 46 | } |
| 47 | |
| 48 | // Most tests are just inherited from FileSystemTest. |
| 49 | |
| 50 | @Test |
| 51 | public void testCircularSymlinkFound() throws Exception { |
| 52 | Path linkA = absolutize("link-a"); |
| 53 | Path linkB = absolutize("link-b"); |
| 54 | linkA.createSymbolicLink(linkB); |
| 55 | linkB.createSymbolicLink(linkA); |
lberki | aea56b3 | 2017-05-30 12:35:33 +0200 | [diff] [blame] | 56 | assertThat(linkA.exists(Symlinks.FOLLOW)).isFalse(); |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 57 | try { |
| 58 | linkA.statIfFound(Symlinks.FOLLOW); |
| 59 | fail(); |
| 60 | } catch (IOException expected) { |
| 61 | // Expected. |
| 62 | } |
| 63 | } |
Nathan Harmata | d8b6ff2 | 2015-10-20 21:54:34 +0000 | [diff] [blame] | 64 | |
| 65 | @Test |
| 66 | public void testIsSpecialFile() throws Exception { |
| 67 | Path regular = absolutize("regular"); |
| 68 | Path fifo = absolutize("fifo"); |
| 69 | FileSystemUtils.createEmptyFile(regular); |
Lukacs Berki | 7ecb2ce | 2016-01-26 15:40:42 +0000 | [diff] [blame] | 70 | NativePosixFiles.mkfifo(fifo.toString(), 0777); |
lberki | aea56b3 | 2017-05-30 12:35:33 +0200 | [diff] [blame] | 71 | assertThat(regular.isFile()).isTrue(); |
| 72 | assertThat(regular.isSpecialFile()).isFalse(); |
| 73 | assertThat(regular.stat().isFile()).isTrue(); |
| 74 | assertThat(regular.stat().isSpecialFile()).isFalse(); |
| 75 | assertThat(fifo.isFile()).isTrue(); |
| 76 | assertThat(fifo.isSpecialFile()).isTrue(); |
| 77 | assertThat(fifo.stat().isFile()).isTrue(); |
| 78 | assertThat(fifo.stat().isSpecialFile()).isTrue(); |
Nathan Harmata | d8b6ff2 | 2015-10-20 21:54:34 +0000 | [diff] [blame] | 79 | } |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 80 | } |