import benchbuild.project as prj
import benchbuild.utils.compiler as compiler
import benchbuild.utils.run as run
import benchbuild.utils.wrapping as wrapping

class TestProject(prj.Project):
    """
        Test project that does nothing.
    """
    NAME = "test"
    DOMAIN = "test"
    GROUP = "test"
    VERSION = "1.0"
    SRC_FILE = "test.cpp"

    def prepare(self):
        with open(self.src_file, 'w') as test_source:
            lines = """
#include <iostream>
int main(int argc, char **argv) {
    std::cout << "Hello (stdout) World" << std::endl;    
    std::cerr << "Hello (stderr) World" << std::endl;
    return 0;
}
            """
            test_source.write(lines)

    def configure(self):
        pass

    def build(self):
        clang = compiler.lt_clang_cxx(self.cflags, self.ldflags,
                                      self.compiler_extension)
        run.run(clang[self.src_file, "-o", self.src_file + ".out"])

    def run_tests(self, experiment, run):
        exp = wrapping.wrap(self.src_file + ".out", experiment)
        run(exp)
@@ -191,25 +191,16 @@
 %0A    %22%22%22
-%0A        
 Test pro
@@ -222,21 +222,16 @@
 nothing.
-%0A    
 %22%22%22%0A    
@@ -597,16 +597,16 @@
 ::endl;%0A
-
     retu
@@ -1046,8 +1046,930 @@
 run(exp)
+%0A%0Aclass TestProjectRuntimeFail(prj.Project):%0A    %22%22%22Test project that _always_ fails at runtime.%22%22%22%0A%0A    NAME = %22test-fail%22%0A    DOMAIN = %22test%22%0A    GROUP = %22test%22%0A    VERSION = %221.0%22%0A    SRC_FILE = %22test.cpp%22%0A%0A    def prepare(self):%0A        with open(self.src_file, 'w') as test_source:%0A            lines = %22%22%22%0A#include %3Ciostream%3E%0Aint main(int argc, char **argv) %7B%0A    std::cout %3C%3C %22Hello (stdout) World%22 %3C%3C std::endl;%0A    std::cerr %3C%3C %22Hello (stderr) World%22 %3C%3C std::endl;%0A    return 1;%0A%7D%0A            %22%22%22%0A            test_source.write(lines)%0A%0A    def configure(self):%0A        pass%0A%0A    def build(self):%0A        clang = compiler.lt_clang_cxx(self.cflags, self.ldflags,%0A                                      self.compiler_extension)%0A        run.run(clang%5Bself.src_file, %22-o%22, self.src_file + %22.out%22%5D)%0A%0A    def run_tests(self, experiment, run):%0A        exp = wrapping.wrap(self.src_file + %22.out%22, experiment)%0A        run(exp)

add a project that always fails at run-time