qute

A software analysis framework built around the QBE intermediate language

git clone https://git.8pit.net/qute.git

 1-- SPDX-FileCopyrightText: 2026 Sören Tempel <soeren+git@soeren-tempel.net>
 2--
 3-- SPDX-License-Identifier: GPL-3.0-only
 4
 5module Archive (archiveTests) where
 6
 7import Data.Archive (Object (..))
 8import Test.Tasty
 9import Test.Tasty.HUnit
10import Util (readArchive)
11
12archiveTests :: TestTree
13archiveTests =
14  testGroup
15    "Test the parser for the ar(5) format"
16    [ testCase "single file" $
17        do
18          objs <- readArchive "archive/single-file.ar"
19          objs
20            @?= [ Object
21                    { oName = "hello.txt/",
22                      oTime = 0,
23                      oUser = 0,
24                      oGroup = 0,
25                      oMode = 0o644,
26                      oSize = length "hello, world!\n",
27                      oData = "hello, world!\n"
28                    }
29                ],
30      testCase "single file with padding" $
31        do
32          objs <- readArchive "archive/single-file-with-padding.ar"
33          case objs of
34            [obj] -> oData obj @?= "12\n" -- padding removed
35            _ -> assertFailure "unexpected object amount",
36      testCase "multiple files" $
37        do
38          objs <- readArchive "archive/two-files-first-with-padding.ar"
39          objs
40            @?= [ Object
41                    { oName = "world.txt/",
42                      oTime = 0,
43                      oUser = 0,
44                      oGroup = 0,
45                      oMode = 0o644,
46                      oSize = length "world!\n",
47                      oData = "world!\n"
48                    },
49                  Object
50                    { oName = "hello.txt/",
51                      oTime = 0,
52                      oUser = 1000,
53                      oGroup = 1005,
54                      oMode = 0o644,
55                      oSize = length "hello\n",
56                      oData = "hello\n"
57                    }
58                ],
59      testCase "file name with space" $
60        do
61          objs <- readArchive "archive/file-name-containing-space.ar"
62          case objs of
63            -- See https://man.freebsd.org/cgi/man.cgi?query=ar&sektion=5
64            [obj] -> do
65              oName obj @?= "A B"
66              oData obj @?= "C D"
67            _ -> assertFailure "unexpected object amount"
68    ]