xref: /llvm-project/llvm/test/tools/llvm-ar/extract.test (revision bf223e43fe68da22f185a12c1a2fe36a726f4fe9)
1## Test extract operation.
2# XFAIL: system-darwin
3
4# RUN: rm -rf %t && mkdir -p %t/extracted/
5
6## Extracting from an empty archive should not warn or error:
7# RUN: llvm-ar cr --format=gnu %t/empty.a
8# RUN: llvm-ar xv %t/empty.a 2>&1 | count 0
9
10# RUN: echo filea > %t/a.txt
11# RUN: echo fileb > %t/b.txt
12# RUN: llvm-ar rc %t/archive.a %t/a.txt %t/b.txt
13
14## Single member:
15# RUN: cd %t/extracted && llvm-ar xv %t/archive.a a.txt | FileCheck %s --check-prefix=A
16# RUN: diff %t/a.txt %t/extracted/a.txt
17# A: x - a.txt
18
19## All members:
20# RUN: rm %t/extracted/a.txt
21# RUN: cd %t/extracted && llvm-ar xv %t/archive.a | FileCheck %s --check-prefix=AB
22# RUN: diff %t/a.txt %t/extracted/a.txt
23# RUN: diff %t/b.txt %t/extracted/b.txt
24# AB: x - a.txt
25# AB: x - b.txt
26
27## Thin archive
28# RUN: llvm-ar Trc %t/thin-archive.a
29# RUN: not llvm-ar x %t/thin-archive.a 2>&1 | FileCheck %s --check-prefix=THIN
30# THIN: extracting from a thin archive is not supported
31
32## No output if 'v' is not specified.
33# RUN: rm a.txt b.txt
34# RUN: llvm-ar x %t/archive.a 2>&1 | count 0
35# RUN: diff %t/a.txt %t/extracted/a.txt
36# RUN: diff %t/b.txt %t/extracted/b.txt
37
38## --output specifies the directory to extract archive members to. `1/2` is created by llvm-ar.
39# RUN: llvm-ar --output=1/2 x %t/archive.a
40# RUN: diff %t/a.txt %t/extracted/1/2/a.txt
41# RUN: diff %t/b.txt %t/extracted/1/2/b.txt
42
43## --output can be used with an absolute path and can be specified elsewhere on the command line.
44# RUN: rm 1/2/a.txt
45# RUN: llvm-ar xv %t/archive.a a.txt --output %t/extracted/1/2/../2 | FileCheck %s --check-prefix=OUTPUT-A
46# RUN: diff %t/a.txt %t/extracted/1/2/a.txt
47# OUTPUT-A: x - {{.*}}extracted{{.*}}a.txt
48
49# RUN: not llvm-ar x --output=%t/a.txt %t/archive.a 2>&1 | FileCheck %s --check-prefix=OUTPUT-NOTDIR
50# RUN: not llvm-ar x --output=%t/b.txt/a.txt %t/archive.a 2>&1 | FileCheck %s --check-prefix=OUTPUT-NOTDIR
51# OUTPUT-NOTDIR: error: '{{.*}}a.txt' is not a directory
52
53# RUN: not llvm-ar rc --output=1/2 %t/archive.a %t/a.txt 2>&1 | FileCheck %s --check-prefix=OUTPUT-ERR
54# OUTPUT-ERR: error: --output is only applicable to the 'x' operation
55