[moulette] switched to boost::signals2
[ozulis.git] / src / moulette / tests / compile-test.cc
blobf7e842a4e92e6027b95d4f0cb7fbda1797aa3a4c
1 #include <fstream>
3 #include <ozulis/core/io-utils.hh>
4 #include "compile-test.hh"
6 namespace moulette
8 CompileTest::CompileTest()
9 : super_t(),
10 source_()
14 void
15 CompileTest::test()
17 process_.setBinary(OZULIS_BINARY);
18 process_.addArg(source_.string());
20 super_t::test();
22 // get the source content
23 std::ifstream is(source_.string().c_str());
24 std::string data;
25 ozulis::core::readAll(is, data);
26 is.close();
28 // get the .ll content
29 boost::filesystem::path llPath(source_);
30 llPath.replace_extension("ll");
31 is.open(llPath.string().c_str());
32 std::string llvmAsm;
33 ozulis::core::readAll(is, llvmAsm);
34 is.close();
36 // remove the .ll file
37 boost::filesystem::remove(llPath);
38 assert(!boost::filesystem::exists(llPath));
40 // remove the .bc file
41 boost::filesystem::path bcPath(source_);
42 bcPath.replace_extension("bc");
43 boost::filesystem::remove(bcPath);
44 assert(!boost::filesystem::exists(bcPath));
46 // remove the binary file
47 boost::filesystem::path binPath(source_);
48 binPath.replace_extension();
49 boost::filesystem::remove(binPath);
50 assert(!boost::filesystem::exists(binPath));
52 result_.details["source"] = data;
53 result_.details["source-path"] = source_.string();
54 result_.details["assembly"] = llvmAsm;
55 result_.details["assembly-path"] = llPath.string();
58 void
59 CompileTest::set(const std::string & key, const std::string & value)
61 if (key == "source")
62 setSource(value);
63 else
64 super_t::set(key, value);
67 void
68 CompileTest::setSource(const std::string & source)
70 source_ = path.parent_path() / source;
73 const std::string &
74 CompileTest::type() const
76 static std::string type_("CompileTest");
78 return type_;