@@ -50,14 +50,29 @@ namespace
50
50
51
51
string const sourceDelimiter (" ==== Source: " );
52
52
53
- const map<string, CompilerStack::State> compilerStateMap = {
54
- {" Empty" , CompilerStack::State::Empty},
55
- {" SourcesSet" , CompilerStack::State::SourcesSet},
56
- {" Parsed" , CompilerStack::State::Parsed},
57
- {" ParsedAndImported" , CompilerStack::State::ParsedAndImported},
58
- {" AnalysisPerformed" , CompilerStack::State::AnalysisPerformed},
59
- {" CompilationSuccessful" , CompilerStack::State::CompilationSuccessful}
60
- };
53
+ string compilerStateToString (CompilerStack::State _state)
54
+ {
55
+ switch (_state)
56
+ {
57
+ case CompilerStack::State::Empty: return " Empty" ;
58
+ case CompilerStack::State::SourcesSet: return " SourcesSet" ;
59
+ case CompilerStack::State::Parsed: return " Parsed" ;
60
+ case CompilerStack::State::ParsedAndImported: return " ParsedAndImported" ;
61
+ case CompilerStack::State::AnalysisPerformed: return " AnalysisPerformed" ;
62
+ case CompilerStack::State::CompilationSuccessful: return " CompilationSuccessful" ;
63
+ }
64
+ soltestAssert (false , " Unexpected value of state parameter" );
65
+ }
66
+
67
+ CompilerStack::State stringToCompilerState (const string& _state)
68
+ {
69
+ for (unsigned int i = CompilerStack::State::Empty; i <= CompilerStack::State::CompilationSuccessful; ++i)
70
+ {
71
+ if (_state == compilerStateToString (CompilerStack::State (i)))
72
+ return CompilerStack::State (i);
73
+ }
74
+ BOOST_THROW_EXCEPTION (runtime_error (" Unsupported compiler state (" + _state + " ) in test contract file" ));
75
+ }
61
76
62
77
void replaceVersionWithTag (string& _input)
63
78
{
@@ -88,11 +103,25 @@ ASTJSONTest::ASTJSONTest(string const& _filename)
88
103
string_view baseName = _filename;
89
104
baseName.remove_suffix (4 );
90
105
91
- m_variants = {
92
- TestVariant (baseName, CompilerStack::State::Parsed) ,
93
- TestVariant (baseName, CompilerStack::State::AnalysisPerformed),
106
+ const std::vector<CompilerStack::State> variantCompileStates = {
107
+ CompilerStack::State::Parsed,
108
+ CompilerStack::State::AnalysisPerformed
94
109
};
95
110
111
+ for (const auto state: variantCompileStates)
112
+ {
113
+ auto variant = TestVariant (baseName, state);
114
+ if (boost::filesystem::exists (variant.astFilename ()))
115
+ {
116
+ variant.expectation = readFileAsString (variant.astFilename ());
117
+ boost::replace_all (variant.expectation , " \r\n " , " \n " );
118
+ m_variants.push_back (variant);
119
+ }
120
+ }
121
+
122
+ if (m_variants.empty ())
123
+ BOOST_THROW_EXCEPTION (runtime_error (" Missing file with expected result for: \" " + _filename + " \" ." ));
124
+
96
125
ifstream file (_filename);
97
126
if (!file)
98
127
BOOST_THROW_EXCEPTION (runtime_error (" Cannot open test contract: \" " + _filename + " \" ." ));
@@ -120,24 +149,16 @@ ASTJSONTest::ASTJSONTest(string const& _filename)
120
149
{
121
150
string state = line.substr (failMarker.size ());
122
151
boost::algorithm::trim (state);
123
- if (compilerStateMap.find (state) == compilerStateMap.end ())
124
- BOOST_THROW_EXCEPTION (runtime_error (" Unsupported compiler state (" + state + " ) in test contract file" ));
125
152
if (m_expectedFailAfter.has_value ())
126
153
BOOST_THROW_EXCEPTION (runtime_error (" Duplicated \" failAfter\" directive" ));
127
- m_expectedFailAfter = compilerStateMap. at (state);
154
+ m_expectedFailAfter = stringToCompilerState (state);
128
155
}
129
156
else if (!line.empty () && !boost::algorithm::starts_with (line, delimiter))
130
157
source += line + " \n " ;
131
158
}
132
159
133
160
m_sources.emplace_back (sourceName.empty () ? " a" : sourceName, source);
134
161
file.close ();
135
-
136
- for (TestVariant& variant: m_variants)
137
- {
138
- variant.expectation = readFileAsString (variant.astFilename ());
139
- boost::replace_all (variant.expectation , " \r\n " , " \n " );
140
- }
141
162
}
142
163
143
164
TestCase::TestResult ASTJSONTest::run (ostream& _stream, string const & _linePrefix, bool const _formatted)
0 commit comments