File: 07_subshells_fix.patch

package info (click to toggle)
kcov 43%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,684 kB
  • sloc: cpp: 12,619; ansic: 2,379; python: 2,000; sh: 333; makefile: 140; javascript: 65; xml: 7; asm: 4
file content (50 lines) | stat: -rw-r--r-- 2,051 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
From: =?utf-8?b?TWF0dMOpbyBSb3NzaWxsb2zigJHigJFMYXJ1ZWxsZQ==?=
 <beatussum@protonmail.com>
Date: Wed, 31 Jul 2024 14:39:48 +0200
Subject: Fix subshells

Origin: upstream
Forwarded: https://github.com/SimonKagstrom/kcov/commit/645c9a6c9d3f3eba54b5bb1959998a4203761517, https://github.com/SimonKagstrom/kcov/commit/a750d4793d811dcfe1f849942bb00d66aff043a0
Acked-by: William Desportes <williamdes@wdes.fr>
---
 src/engines/bash-engine.cc | 6 +++++-
 tests/tools/test_bash.py   | 2 +-
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/src/engines/bash-engine.cc b/src/engines/bash-engine.cc
index 2f76e04..75b79f0 100644
--- a/src/engines/bash-engine.cc
+++ b/src/engines/bash-engine.cc
@@ -619,7 +619,7 @@ private:
 				continue;
 
 			// While, if, switch endings
-			if (s == "esac" || s == "fi" || s == "do" || s == "done" || s == "else" || s == "then" || s == "}" || s == "{")
+			if (s == "esac" || s == "fi" || s == "do" || s == "done" || s == "else" || s == "then" || s == "}" || s == "{" || s == ")" || s == "(")
 				continue;
 
 			// Functions
@@ -684,6 +684,10 @@ private:
 			if ((s[0] == '{' || s[0] == '}') && s.size() == 1)
 				continue;
 
+			// Empty parentheses
+			if ((s[0] == '(' || s[0] == ')') && s.size() == 1)
+				continue;
+
 			// While, if, switch endings
 			if (s == "esac" || s == "fi" || s == "do" || s == "done" || s == "else" || s == "then")
 				continue;
diff --git a/tests/tools/test_bash.py b/tests/tools/test_bash.py
index 6a522ee..c2df053 100644
--- a/tests/tools/test_bash.py
+++ b/tests/tools/test_bash.py
@@ -351,7 +351,7 @@ class bash_subshell(libkcov.TestCase):
         dom = cobertura.parseFile(self.outbase + "/kcov/subshell.sh/cobertura.xml")
         self.assertIsNone(cobertura.hitsPerLine(dom, "subshell.sh", 1))
         self.assertEqual(2, cobertura.hitsPerLine(dom, "subshell.sh", 4))
-        self.assertEqual(0, cobertura.hitsPerLine(dom, "subshell.sh", 8))
+        assert cobertura.hitsPerLine(dom, "subshell.sh", 8) is None
 
 
 class bash_handle_all_output(libkcov.TestCase):