Initial commit with minimal examples
This commit is contained in:
35
test/BUILD.bazel
Normal file
35
test/BUILD.bazel
Normal 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
20
test/boost_exception.cpp
Normal 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
12
test/exception.cpp
Normal 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
5
test/hello.cpp
Normal file
@@ -0,0 +1,5 @@
|
||||
#include <iostream>
|
||||
|
||||
int main() {
|
||||
std::cout << "Hello World!" << std::endl;
|
||||
}
|
||||
Reference in New Issue
Block a user