コード例 #1
0
ファイル: dsl.sh.py プロジェクト: vedadux/llvm-project
    def test_caching_is_not_too_aggressive(self):
        # Run a program, then change the substitutions and run it again.
        # Make sure the program is run the second time and the right result
        # is given, to ensure we're not incorrectly caching the result of the
        # first program run.
        source = """
        #include <cstdio>
        int main(int, char**) {
            std::printf("MACRO=%u\\n", MACRO);
            return 0;
        }
        """
        compileFlagsIndex = findIndex(self.config.substitutions,
                                      lambda x: x[0] == '%{compile_flags}')
        compileFlags = self.config.substitutions[compileFlagsIndex][1]

        self.config.substitutions[compileFlagsIndex] = ('%{compile_flags}',
                                                        compileFlags +
                                                        ' -DMACRO=1')
        output1 = dsl.programOutput(self.config, source)
        self.assertEqual(output1, "MACRO=1\n")

        self.config.substitutions[compileFlagsIndex] = ('%{compile_flags}',
                                                        compileFlags +
                                                        ' -DMACRO=2')
        output2 = dsl.programOutput(self.config, source)
        self.assertEqual(output2, "MACRO=2\n")
コード例 #2
0
ファイル: dsl.sh.py プロジェクト: vedadux/llvm-project
 def test_program_that_fails_to_compile_raises_compilation_error(self):
     # The program doesn't compile
     source = """
     int main(int, char**) { this doesnt compile }
     """
     self.assertRaises(dsl.ConfigurationCompilationError,
                       lambda: dsl.programOutput(self.config, source))
コード例 #3
0
ファイル: dsl.sh.py プロジェクト: vedadux/llvm-project
 def test_program_that_fails_to_run_raises_runtime_error(self):
     # The program compiles, but exits with an error
     source = """
     int main(int, char**) { return 1; }
     """
     self.assertRaises(dsl.ConfigurationRuntimeError,
                       lambda: dsl.programOutput(self.config, source))
コード例 #4
0
 def test_pass_arguments_to_program(self):
     source = """
     #include <cassert>
     #include <string>
     int main(int argc, char** argv) {
         assert(argc == 3);
         assert(argv[1] == std::string("first-argument"));
         assert(argv[2] == std::string("second-argument"));
     }
     """
     args = ["first-argument", "second-argument"]
     self.assertEqual(dsl.programOutput(self.config, source, args=args), "")
コード例 #5
0
 def test_program_stderr_is_not_conflated_with_stdout(self):
     # Run a program that produces stdout output and stderr output too, making
     # sure the stderr output does not pollute the stdout output.
     source = """
     #include <cstdio>
     int main(int, char**) {
         std::fprintf(stdout, "STDOUT-OUTPUT");
         std::fprintf(stderr, "STDERR-OUTPUT");
         return 0;
     }
     """
     self.assertEqual(dsl.programOutput(self.config, source), "STDOUT-OUTPUT")
コード例 #6
0
ファイル: dsl.sh.py プロジェクト: vedadux/llvm-project
 def test_valid_program_returns_no_output(self):
     source = """
     int main(int, char**) { return 0; }
     """
     self.assertEqual(dsl.programOutput(self.config, source), "")
コード例 #7
0
ファイル: dsl.sh.py プロジェクト: vedadux/llvm-project
 def test_valid_program_returns_output_newline_handling(self):
     source = """
     #include <cstdio>
     int main(int, char**) { std::printf("FOOBAR\\n"); return 0; }
     """
     self.assertEqual(dsl.programOutput(self.config, source), "FOOBAR\n")
コード例 #8
0
 def test_invalid_program_returns_None_2(self):
     # The program doesn't compile
     source = """
     int main(int, char**) { this doesnt compile }
     """
     self.assertEqual(dsl.programOutput(self.config, source), None)
コード例 #9
0
 def test_invalid_program_returns_None_1(self):
     # The program compiles, but exits with an error
     source = """
     int main(int, char**) { return 1; }
     """
     self.assertEqual(dsl.programOutput(self.config, source), None)