@@ -49,6 +49,7 @@ TEST_F(FileRuleEvaluatorTest, FileExistsReturnsFound)
49
49
m_ctx.rule = " some/file" ;
50
50
51
51
EXPECT_CALL (*m_rawFsMock, exists (std::filesystem::path (" some/file" ))).WillOnce (::testing::Return (true ));
52
+ EXPECT_CALL (*m_rawFsMock, is_regular_file (std::filesystem::path (" some/file" ))).WillOnce (::testing::Return (true ));
52
53
53
54
auto evaluator = CreateEvaluator ();
54
55
EXPECT_EQ (evaluator.Evaluate (), RuleResult::Found);
@@ -60,6 +61,7 @@ TEST_F(FileRuleEvaluatorTest, PatternRegexMatchesContentReturnsFound)
60
61
m_ctx.rule = " some/file" ;
61
62
62
63
EXPECT_CALL (*m_rawFsMock, exists (std::filesystem::path (" some/file" ))).WillOnce (::testing::Return (true ));
64
+ EXPECT_CALL (*m_rawFsMock, is_regular_file (std::filesystem::path (" some/file" ))).WillOnce (::testing::Return (true ));
63
65
EXPECT_CALL (*m_rawIoMock, getFileContent (" some/file" )).WillOnce (::testing::Return (" foo" ));
64
66
65
67
auto evaluator = CreateEvaluator ();
@@ -72,6 +74,7 @@ TEST_F(FileRuleEvaluatorTest, PatternRegexDoesNotMatchContentReturnsNotFound)
72
74
m_ctx.rule = " some/file" ;
73
75
74
76
EXPECT_CALL (*m_rawFsMock, exists (std::filesystem::path (" some/file" ))).WillOnce (::testing::Return (true ));
77
+ EXPECT_CALL (*m_rawFsMock, is_regular_file (std::filesystem::path (" some/file" ))).WillOnce (::testing::Return (true ));
75
78
EXPECT_CALL (*m_rawIoMock, getFileContent (" some/file" )).WillOnce (::testing::Return (" bar" ));
76
79
77
80
auto evaluator = CreateEvaluator ();
@@ -84,6 +87,7 @@ TEST_F(FileRuleEvaluatorTest, PatternExactLineMatchesReturnsFound)
84
87
m_ctx.rule = " some/file" ;
85
88
86
89
EXPECT_CALL (*m_rawFsMock, exists (std::filesystem::path (" some/file" ))).WillOnce (::testing::Return (true ));
90
+ EXPECT_CALL (*m_rawFsMock, is_regular_file (std::filesystem::path (" some/file" ))).WillOnce (::testing::Return (true ));
87
91
EXPECT_CALL (*m_rawIoMock, readLineByLine (std::filesystem::path (" some/file" ), ::testing::_))
88
92
.WillOnce (::testing::Invoke (
89
93
[](const std::filesystem::path&, const std::function<bool (const std::string&)>& callback)
@@ -102,6 +106,7 @@ TEST_F(FileRuleEvaluatorTest, PatternExactLineNoMatchReturnsNotFound)
102
106
m_ctx.rule = " some/file" ;
103
107
104
108
EXPECT_CALL (*m_rawFsMock, exists (std::filesystem::path (" some/file" ))).WillOnce (::testing::Return (true ));
109
+ EXPECT_CALL (*m_rawFsMock, is_regular_file (std::filesystem::path (" some/file" ))).WillOnce (::testing::Return (true ));
105
110
EXPECT_CALL (*m_rawIoMock, readLineByLine (std::filesystem::path (" some/file" ), ::testing::_))
106
111
.WillOnce (::testing::Invoke (
107
112
[](const std::filesystem::path&, const std::function<bool (const std::string&)>& callback)
@@ -114,13 +119,25 @@ TEST_F(FileRuleEvaluatorTest, PatternExactLineNoMatchReturnsNotFound)
114
119
EXPECT_EQ (evaluator.Evaluate (), RuleResult::NotFound);
115
120
}
116
121
117
- TEST_F (FileRuleEvaluatorTest, PatternGivenButFileDoesNotExistReturnsNotFound )
122
+ TEST_F (FileRuleEvaluatorTest, PatternGivenButFileDoesNotExistReturnsInvalid )
118
123
{
119
124
m_ctx.pattern = std::string (" r:foo" );
120
125
m_ctx.rule = " some/file" ;
121
126
122
127
EXPECT_CALL (*m_rawFsMock, exists (std::filesystem::path (" some/file" ))).WillOnce (::testing::Return (false ));
123
128
124
129
auto evaluator = CreateEvaluator ();
125
- EXPECT_EQ (evaluator.Evaluate (), RuleResult::NotFound);
130
+ EXPECT_EQ (evaluator.Evaluate (), RuleResult::Invalid);
131
+ }
132
+
133
+ TEST_F (FileRuleEvaluatorTest, PatternGivenButPathIsNotRegularFileReturnsInvalid)
134
+ {
135
+ m_ctx.pattern = std::string (" r:foo" );
136
+ m_ctx.rule = " some/file" ;
137
+
138
+ EXPECT_CALL (*m_rawFsMock, exists (std::filesystem::path (" some/file" ))).WillOnce (::testing::Return (true ));
139
+ EXPECT_CALL (*m_rawFsMock, is_regular_file (std::filesystem::path (" some/file" ))).WillOnce (::testing::Return (false ));
140
+
141
+ auto evaluator = CreateEvaluator ();
142
+ EXPECT_EQ (evaluator.Evaluate (), RuleResult::Invalid);
126
143
}
0 commit comments