compiler_test.cpp
Go to the documentation of this file.
1 #include <gtest/gtest.h>
2 #include <stan/lang/compiler.hpp>
3 #include <test/unit/util.hpp>
4 #include <boost/algorithm/string.hpp>
5 
6 TEST(LangCompiler, compile) {
7  std::stringstream msgs, stan_lang_in, cpp_out;
8  std::string model_name = "m";
9  stan_lang_in << "model { }";
10 
11  stan::lang::compile(&msgs, stan_lang_in, cpp_out, model_name);
12  EXPECT_EQ("", msgs.str());
13  EXPECT_EQ(std::string::npos, cpp_out.str().find("int main("));
14 }
15 
16 TEST(LangCompiler, emptyProgram) {
17  std::stringstream msgs, stan_lang_in, cpp_out;
18  std::string model_name = "m";
19  stan_lang_in << "";
20 
21  stan::lang::compile(&msgs, stan_lang_in, cpp_out, model_name);
22 
23  EXPECT_EQ(1,count_matches("WARNING: empty program",msgs.str()));
24  EXPECT_EQ(std::string::npos, cpp_out.str().find("int main("));
25 
26  // can't test equivalence of "" and "model { }" because of the
27  // recording of the positions in the file
28 }
bool compile(std::ostream *msgs, std::istream &in, std::ostream &out, const std::string &name, const bool allow_undefined=false, const std::string &filename="unknown file name", const std::vector< std::string > &include_paths=std::vector< std::string >())
Definition: compiler.hpp:35
int count_matches(const std::string &target, const std::string &s)
Definition: util.hpp:19
TEST(LangCompiler, compile)
enum BeamMode string