1# Note: many of these tests depend on relative paths, so we have to cd to a
2# test directory first.
3RUN: mkdir -p %t && cd %t
4RUN: rm -rf a b && mkdir a b
5RUN: echo hello-a      > a/foo.txt
6RUN: echo hello-b      > b/foo.txt
7RUN: echo hello-parent > foo.txt
8
9# Sanity test that P is accepted.
10RUN: rm -f noop.a && llvm-ar rcP noop.a foo.txt
11RUN: llvm-ar p noop.a | FileCheck %s --check-prefix=ACCEPT
12
13ACCEPT: hello-parent
14
15# Regular (non-thin) archives cannot be created with full path names as
16# members, but P can still affect how lookup works (assuming we're reading an
17# archive not created by GNU ar or llvm-ar).
18# Looking up a/foo.txt in a regular archive will fail with P because it is
19# added to the archive as foo.txt.
20RUN: rm -f display.a
21RUN: llvm-ar rcS display.a a/foo.txt foo.txt b/foo.txt
22RUN: llvm-ar t display.a a/foo.txt | FileCheck %s --check-prefix=DISPLAY-FOUND --match-full-lines
23RUN: not llvm-ar tP display.a a/foo.txt 2>&1 | FileCheck %s --check-prefix=DISPLAY-NOT-FOUND
24
25DISPLAY-FOUND: foo.txt
26DISPLAY-NOT-FOUND: 'a/foo.txt' was not found
27
28# Deleting will fail with P because the members exist as foo.txt, not a/foo.txt.
29RUN: rm -f del1.a
30RUN: llvm-ar rcS del1.a foo.txt
31RUN: llvm-ar dP del1.a a/foo.txt
32RUN: llvm-ar t del1.a a/foo.txt | FileCheck %s --check-prefix=DISPLAY-FOUND --match-full-lines
33RUN: llvm-ar d del1.a a/foo.txt
34RUN: not llvm-ar t del1.a a/foo.txt 2>&1 | FileCheck %s --check-prefix=DISPLAY-NOT-FOUND
35
36# Run several checks that P is implied when using thin archives. None of these
37# checks explicitly use P.
38
39# Creating an archive in one step.
40RUN: rm -f add.a
41RUN: llvm-ar rcST add.a a/foo.txt foo.txt b/foo.txt
42RUN: llvm-ar t add.a | FileCheck %s --check-prefix=ADD --match-full-lines
43
44ADD:      a/foo.txt
45ADD-NEXT: foo.txt
46ADD-NEXT: b/foo.txt
47
48# Create an archive incrementally.
49RUN: rm -f add-inc.a
50RUN: llvm-ar rcST add-inc.a a/foo.txt
51RUN: llvm-ar rcST add-inc.a foo.txt
52RUN: llvm-ar rcST add-inc.a b/foo.txt
53RUN: llvm-ar t add-inc.a | FileCheck %s --check-prefix=ADD-INC --match-full-lines
54
55ADD-INC:      a/foo.txt
56ADD-INC-NEXT: foo.txt
57ADD-INC-NEXT: b/foo.txt
58
59# Nesting a thin archive with a name conflict.
60RUN: rm -f a/nested.a b/nested.a nested.a
61RUN: llvm-ar rcST a/nested.a a/foo.txt
62RUN: llvm-ar rcST b/nested.a b/foo.txt
63RUN: llvm-ar rcST nested.a a/nested.a foo.txt b/nested.a
64RUN: llvm-ar t nested.a | FileCheck %s --check-prefix=NESTED --match-full-lines
65
66NESTED:      a/foo.txt
67NESTED-NEXT: foo.txt
68NESTED-NEXT: b/foo.txt
69
70# Printing members.
71RUN: rm -f add.a
72RUN: llvm-ar rcST add.a a/foo.txt foo.txt b/foo.txt
73RUN: llvm-ar p add.a foo.txt | FileCheck %s --check-prefix=PRINT-PARENT --match-full-lines
74RUN: llvm-ar p add.a a/foo.txt | FileCheck %s --check-prefix=PRINT-A --match-full-lines
75RUN: llvm-ar p add.a b/foo.txt | FileCheck %s --check-prefix=PRINT-B --match-full-lines
76PRINT-PARENT: hello-parent
77PRINT-A:      hello-a
78PRINT-B:      hello-b
79
80# Listing members.
81RUN: rm -f add.a
82RUN: llvm-ar rcST add.a a/foo.txt foo.txt b/foo.txt
83RUN: llvm-ar t add.a foo.txt | FileCheck %s --check-prefix=LIST-PARENT --match-full-lines
84RUN: llvm-ar t add.a a/foo.txt | FileCheck %s --check-prefix=LIST-A --match-full-lines
85RUN: llvm-ar t add.a b/foo.txt | FileCheck %s --check-prefix=LIST-B --match-full-lines
86LIST-PARENT:     foo.txt
87LIST-PARENT-NOT: a/foo.txt
88LIST-PARENT-NOT: b/foo.txt
89LIST-A:          a/foo.txt
90LIST-B:          b/foo.txt
91
92# Deleting members.
93RUN: rm -f del1.a
94RUN: llvm-ar rcST del1.a a/foo.txt foo.txt b/foo.txt
95RUN: llvm-ar d del1.a foo.txt
96RUN: llvm-ar t del1.a | FileCheck %s --check-prefix=DEL-1 --match-full-lines
97
98DEL-1-NOT:  foo.txt
99DEL-1:      a/foo.txt
100DEL-1-NEXT: b/foo.txt
101
102RUN: rm -f del2.a
103RUN: llvm-ar rcST del2.a a/foo.txt foo.txt b/foo.txt
104RUN: llvm-ar d del2.a a/foo.txt
105RUN: llvm-ar t del2.a | FileCheck %s --check-prefix=DEL-2 --match-full-lines
106DEL-2-NOT:  a/foo.txt
107DEL-2:      foo.txt
108DEL-2-NEXT: b/foo.txt
109