Skip to content
This repository has been archived by the owner on Nov 30, 2023. It is now read-only.

Commit

Permalink
Add Bazel test project
Browse files Browse the repository at this point in the history
  • Loading branch information
shikanime committed May 17, 2019
1 parent b927086 commit 4989329
Show file tree
Hide file tree
Showing 7 changed files with 119 additions and 4 deletions.
8 changes: 4 additions & 4 deletions containers/bazel/.devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ ENV BAZEL_SHA256=7ca3bbec5730afc3732514cbebb1e8f451df455d85d6bed5eb5614c2bfe36f1
RUN apt-get -y install curl pkg-config zip g++ zlib1g-dev unzip python
RUN curl -fSsL -o bazel-installer.sh https://github.com/bazelbuild/bazel/releases/download/${BAZEL_VERSION}/bazel-${BAZEL_VERSION}-installer-linux-x86_64.sh \
&& chmod +x bazel-installer.sh \
&& ./bazel-installer.sh --user \
&& ./bazel-installer.sh \
&& rm ./bazel-installer.sh

RUN echo '\n\
export PATH="$PATH:$HOME/bin" \n\
'\
>> $HOME/.bashrc
export PATH="$PATH:$HOME/bin" \n\
'\
>> $HOME/.bashrc

# Clean up
RUN apt-get autoremove -y \
Expand Down
17 changes: 17 additions & 0 deletions containers/bazel/.vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "build",
"command": "cd test-project && bazel build",
"type": "shell",
"group": "build",
"presentation": {
"reveal": "silent"
},
"problemMatcher": "$msCompile"
}
]
}
24 changes: 24 additions & 0 deletions containers/bazel/test-project/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package(default_visibility = ["//visibility:public"])

cc_library(
name = "hello-lib",
srcs = ["hello-lib.cc"],
hdrs = ["hello-lib.h"],
)

cc_binary(
name = "hello-world",
srcs = ["hello-world.cc"],
deps = [":hello-lib"],
)

cc_test(
name = "hello-test",
srcs = ["hello-world.cc"],
deps = [":hello-lib"],
)

filegroup(
name = "srcs",
srcs = glob(["**"]),
)
1 change: 1 addition & 0 deletions containers/bazel/test-project/WORKSPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
workspace(name = "hello_world")
22 changes: 22 additions & 0 deletions containers/bazel/test-project/hello-lib.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include "./hello-lib.h"

#include <iostream>

using std::cout;
using std::endl;
using std::string;

namespace hello
{

HelloLib::HelloLib(const string &greeting)
: greeting_(new string(greeting))
{
}

void HelloLib::greet(const string &thing)
{
cout << *greeting_ << " " << thing << endl;
}

} // namespace hello
23 changes: 23 additions & 0 deletions containers/bazel/test-project/hello-lib.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#ifndef EXAMPLES_CPP_HELLO_LIB_H_
#define EXAMPLES_CPP_HELLO_LIB_H_

#include <string>
#include <memory>

namespace hello
{

class HelloLib
{
public:
explicit HelloLib(const std::string &greeting);

void greet(const std::string &thing);

private:
std::unique_ptr<const std::string> greeting_;
};

} // namespace hello

#endif // EXAMPLES_CPP_HELLO_LIB_H_
28 changes: 28 additions & 0 deletions containers/bazel/test-project/hello-world.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include "./hello-lib.h"

#include <string>

using hello::HelloLib;
using std::string;

/**
* This prints "Hello world". If it is run with arguments, it will use the first
* argument instead of "world". Build and run //examples/cpp:hello-world to see
* this program in action.
*
* This file does double-duty as a "test." It is a cc_binary, so it can also be
* compiled as a cc_test and Bazel will decide on whether it passed or failed
* based on exit code (which is always 0 here, so the test "passes"). See
* hello-fail.cc for an example of making a test fail.
*/
int main(int argc, char **argv)
{
HelloLib lib("Hello");
string thing = "world";
if (argc > 1)
{
thing = argv[1];
}
lib.greet(thing);
return 0;
}

0 comments on commit 4989329

Please sign in to comment.