Skip to content

Commit 6cd17ad

Browse files
committed
Add tests for SpecialOutput.
1 parent 71b2506 commit 6cd17ad

File tree

2 files changed

+44
-8
lines changed

2 files changed

+44
-8
lines changed

src/SpecialOutput.hs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ toAnnotation v = do
140140
ruleId _ = Nothing
141141

142142
-- | Returns the annotations for the location in a result object.
143-
-- If there are any location annotations, the return value will end with @", "@,
143+
-- If there are any location annotations, the return value will end with @","@,
144144
-- otherwise the return value will be empty.
145145
locationAnnotation :: Object -> Text
146146
locationAnnotation v =
@@ -153,23 +153,23 @@ locationAnnotation v =
153153
]
154154
where
155155
fileAnnotation
156-
| (Just s) <- filename = "file=" <> escapeSpecial s <> ", "
156+
| (Just s) <- filename = "file=" <> escapeSpecial s <> ","
157157
| otherwise = ""
158158

159159
colAnnotation
160-
| (Just n) <- col = "col=" <> pack (show n) <> ", "
160+
| (Just n) <- col = "col=" <> pack (show n) <> ","
161161
| otherwise = ""
162162

163163
endColumnAnnotation
164-
| (Just n) <- endColumn = "endColumn=" <> pack (show n) <> ", "
164+
| (Just n) <- endColumn = "endColumn=" <> pack (show n) <> ","
165165
| otherwise = ""
166166

167167
lineAnnotation
168-
| (Just n) <- line = "line=" <> pack (show n) <> ", "
168+
| (Just n) <- line = "line=" <> pack (show n) <> ","
169169
| otherwise = ""
170170

171171
endLineAnnotation
172-
| (Just n) <- endLine = "endLine=" <> pack (show n) <> ", "
172+
| (Just n) <- endLine = "endLine=" <> pack (show n) <> ","
173173
| otherwise = ""
174174

175175
locations

test/SpecialOutputSpec.hs

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,46 @@ limitations under the License.
1919
-- Copyright: Copyright 2025 Google LLC
2020
-- License: Apache-2.0
2121
-- Maintainer: [email protected]
22-
module SpecialOutputSpec (spec) where
22+
module SpecialOutputSpec where
2323

24+
import Data.Aeson
25+
import Data.Aeson.KeyMap qualified as KeyMap
26+
import Data.Vector qualified as Vector
27+
import SpecialOutput
28+
import System.Exit
2429
import Test.Hspec
2530

2631
spec :: Spec
2732
spec = parallel $ do
28-
it "is pending" pending
33+
it "outputs minimal annotation" $
34+
let v = encode $ Object $ KeyMap.singleton "runs" runs
35+
runs = Array $ Vector.singleton run
36+
run = Object $ KeyMap.singleton "results" results
37+
results = Array $ Vector.singleton result
38+
result =
39+
Object $
40+
KeyMap.fromList
41+
[ ("level", "error"),
42+
("ruleId", "redundant entity"),
43+
("message", Object $ KeyMap.singleton "text" "random comment")
44+
]
45+
in output Never v `shouldBe` ("::error title=redundant entity::random comment\n", ExitSuccess)
46+
47+
it "outputs annotation with some location information" $
48+
let v = encode $ Object $ KeyMap.singleton "runs" runs
49+
runs = Array $ Vector.singleton run
50+
run = Object $ KeyMap.singleton "results" results
51+
results = Array $ Vector.singleton result
52+
result =
53+
Object $
54+
KeyMap.fromList
55+
[ ("level", "error"),
56+
("ruleId", "redundant entity"),
57+
("message", Object $ KeyMap.singleton "text" "random comment"),
58+
("locations", Array $ Vector.singleton location)
59+
]
60+
location = Object $ KeyMap.singleton "physicalLocation" physicalLocation
61+
physicalLocation = Object $ KeyMap.singleton "artifactLocation" artifactLocation
62+
artifactLocation = Object $ KeyMap.singleton "uri" "SpecialOutput.hs"
63+
in output Never v
64+
`shouldBe` ("::error file=SpecialOutput.hs,title=redundant entity::random comment\n", ExitSuccess)

0 commit comments

Comments
 (0)