blob: ac2e13c2ea8203768014f8ab7a96f9ceabe89d6b [file] [log] [blame]
Damien Martin-Guillerezf88f4d82015-09-25 13:56:55 +00001// Copyright 2014 The Bazel Authors. All rights reserved.
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +01002//
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 Adams8afbd3c2017-02-28 10:42:48 +000014package com.google.devtools.build.lib.unix;
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010015
lberkiaea56b32017-05-30 12:35:33 +020016import static com.google.common.truth.Truth.assertThat;
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010017import static org.junit.Assert.fail;
18
Ulf Adams8afbd3c2017-02-28 10:42:48 +000019import com.google.devtools.build.lib.vfs.FileSystem;
20import com.google.devtools.build.lib.vfs.FileSystemUtils;
21import com.google.devtools.build.lib.vfs.Path;
22import com.google.devtools.build.lib.vfs.SymlinkAwareFileSystemTest;
23import com.google.devtools.build.lib.vfs.Symlinks;
24import java.io.IOException;
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010025import org.junit.Test;
26import org.junit.runner.RunWith;
27import org.junit.runners.JUnit4;
28
Ulf Adams8afbd3c2017-02-28 10:42:48 +000029/** Tests for the {@link com.google.devtools.build.lib.unix.UnixFileSystem} class. */
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010030@RunWith(JUnit4.class)
31public 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 {
lberkiaea56b32017-05-30 12:35:33 +020045 assertThat(path.statIfFound()).isNull();
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010046 }
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);
lberkiaea56b32017-05-30 12:35:33 +020056 assertThat(linkA.exists(Symlinks.FOLLOW)).isFalse();
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010057 try {
58 linkA.statIfFound(Symlinks.FOLLOW);
59 fail();
60 } catch (IOException expected) {
61 // Expected.
62 }
63 }
Nathan Harmatad8b6ff22015-10-20 21:54:34 +000064
65 @Test
66 public void testIsSpecialFile() throws Exception {
67 Path regular = absolutize("regular");
68 Path fifo = absolutize("fifo");
69 FileSystemUtils.createEmptyFile(regular);
Lukacs Berki7ecb2ce2016-01-26 15:40:42 +000070 NativePosixFiles.mkfifo(fifo.toString(), 0777);
lberkiaea56b32017-05-30 12:35:33 +020071 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 Harmatad8b6ff22015-10-20 21:54:34 +000079 }
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010080}