1

Initial commit with minimal examples

This commit is contained in:
Adam Bouhenguel
2021-04-09 15:05:01 -07:00
commit 2195fb6941
14 changed files with 757 additions and 0 deletions

35
test/BUILD.bazel Normal file
View File

@@ -0,0 +1,35 @@
load("@io_bazel_rules_docker//cc:image.bzl", "cc_image")
cc_binary(
name = "hello",
srcs = ["hello.cpp"],
)
cc_image(
name = "hello_image",
binary = ":hello",
)
cc_binary(
name = "boost_exception",
srcs = ["boost_exception.cpp"],
copts = ["-fexceptions", "-frtti"],
deps = [
"@boost//:lexical_cast",
],
)
cc_image(
name = "boost_exception_image",
binary = ":boost_exception",
)
cc_binary(
name = "exception",
srcs = ["exception.cpp"],
)
cc_image(
name = "exception_image",
binary = ":exception",
)

20
test/boost_exception.cpp Normal file
View File

@@ -0,0 +1,20 @@
#include <iostream>
#include <boost/lexical_cast.hpp>
int main() {
std::cout << "about to cast \"1\" to double!" << std::endl;
std::cout << boost::lexical_cast<double>("1") << std::endl;
std::cout << "about to cast \"z\" to double, but expecting to catch bad_lexical_cast" << std::endl;
try {
std::cout << boost::lexical_cast<double>("z");
std::cout << "uh-oh, should have thrown an exception before here." << std::endl;
} catch (const boost::bad_lexical_cast &e) {
std::cout << "caught bad_lexical_cast" << std::endl;
}
std::cout << "about to cast \"z\" to double, should see an uncaught exception." << std::endl;
std::cout << boost::lexical_cast<double>("z");
std::cout << "uh-oh, should have thrown an exception before here." << std::endl;
}

12
test/exception.cpp Normal file
View File

@@ -0,0 +1,12 @@
#include <iostream>
int main() {
std::cerr << "will throw and expect to catch an error..." << std::endl;
try {
throw "error";
} catch (const char* msg) {
std::cerr << "caught: " << msg << std::endl;
}
std::cerr << "done" << std::endl;
}

5
test/hello.cpp Normal file
View File

@@ -0,0 +1,5 @@
#include <iostream>
int main() {
std::cout << "Hello World!" << std::endl;
}