File tree 7 files changed +64
-3
lines changed
7 files changed +64
-3
lines changed Original file line number Diff line number Diff line change @@ -11,3 +11,4 @@ cmake_install.cmake
11
11
12
12
# Ignore alternate directory of exercises that is used for building
13
13
build_exercises /
14
+ build_hello-world /
Original file line number Diff line number Diff line change @@ -53,4 +53,5 @@ script:
53
53
- bin/fetch-configlet
54
54
- bin/configlet lint .
55
55
- bin/check-configlet-fmt.sh
56
+ - bin/check-hello-world.sh
56
57
- bin/check-exercises.sh
Original file line number Diff line number Diff line change
1
+ #! /usr/bin/env bash
2
+ #
3
+ # Test that the hello-world exercise compiles with no changes and fails.
4
+
5
+ # Fail if any command fails
6
+ set -e
7
+
8
+ repo=$( cd " $( dirname " $0 " ) /.." && pwd)
9
+
10
+ hello_world_tmp_dir=" $repo " /build_hello-world
11
+ hello_world_dir=" $repo " /exercises/hello-world
12
+
13
+ mkdir -p " $hello_world_tmp_dir "
14
+
15
+ cd " $hello_world_tmp_dir "
16
+
17
+ # Configuring should work.
18
+ cmake -G Ninja " $hello_world_dir "
19
+
20
+ echo " Building hello-world, which should fail."
21
+
22
+ # The build will fail, since it runs a failing test.
23
+ if cmake --build . ; then
24
+ # The build succeeded, which is not supposed to happen.
25
+ exit 1
26
+ fi
27
+
28
+ cd " $repo "
Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ using namespace std;
4
4
5
5
namespace hello_world
6
6
{
7
-
7
+
8
8
string hello ()
9
9
{
10
10
return " Hello, World!" ;
Original file line number Diff line number Diff line change
1
+ #include " hello_world.h"
2
+
3
+ // Use everything from the 'std' namespace.
4
+ // This lets us write 'string' instead of 'std::string'.
5
+ using namespace std ;
6
+
7
+ namespace hello_world {
8
+
9
+ // Define the function itself. This could have also been written as:
10
+ // std::string hello_world::hello()
11
+ string hello () {
12
+ // Return the string we need.
13
+ return " Fix me!" ;
14
+ }
15
+
16
+ } // namespace hello_world
Original file line number Diff line number Diff line change
1
+ // This is an include guard.
2
+ // You could alternatively use '#pragma once'
3
+ // See https://en.wikipedia.org/wiki/Include_guard
1
4
#if !defined(HELLO_WORLD_H)
2
5
#define HELLO_WORLD_H
3
6
7
+ // Include the string header so that we have access to 'std::string'
4
8
#include < string>
5
9
10
+ // Declare a namespace for the function(s) we are exporting.
11
+ // https://en.cppreference.com/w/cpp/language/namespace
6
12
namespace hello_world {
7
13
14
+ // Declare the 'hello()' function, which takes no arguments and returns a
15
+ // 'std::string'. The function itself is defined in the hello_world.cpp source
16
+ // file. Because it is inside of the 'hello_world' namespace, it's full name is
17
+ // 'hello_world::hello()'.
8
18
std::string hello ();
9
19
10
- }
20
+ } // namespace hello_world
11
21
12
22
#endif
Original file line number Diff line number Diff line change
1
+ // Include the header file with the definitions of the functions you create.
1
2
#include " hello_world.h"
3
+
4
+ // Include the test framework.
2
5
#include " test/catch.hpp"
3
6
7
+ // Declares a single test.
4
8
TEST_CASE (" test_hello" )
5
9
{
6
- REQUIRE (" Hello, World!" == hello_world::hello ());
10
+ // Check if your function returns "Hello, World!".
11
+ REQUIRE (hello_world::hello () == " Hello, World!" );
7
12
}
You can’t perform that action at this time.
0 commit comments