Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename .h files to .hpp and update docs. #51

Merged
merged 1 commit into from
Aug 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ Unit Test Framework

[![`main` Build Status](https://travis-ci.com/eecs280staff/unit_test_framework.svg?branch=main)](https://travis-ci.com/eecs280staff/unit_test_framework)

A lightweight, easy to use, C++11 unit testing framework implemented in a single `.h` file.
A lightweight, easy to use, C++11 unit testing framework implemented in a single `.hpp` file.

Publicly available tutorial: [https://eecs280staff.github.io/unit_test_framework/](https://eecs280staff.github.io/unit_test_framework/)


## Quickstart
Install the unit test framework by copying `unit_test_framework.h` into your project.
Install the unit test framework by copying `unit_test_framework.hpp` into your project.
```console
$ wget https://raw.githubusercontent.com/eecs280staff/unit_test_framework/main/unit_test_framework.h
$ wget https://raw.githubusercontent.com/eecs280staff/unit_test_framework/main/unit_test_framework.hpp
```

Get the unit test example.
Expand Down Expand Up @@ -40,7 +40,7 @@ The example `my_tests.cpp` looks like this:
```c++
// File: my_tests.cpp

#include "unit_test_framework.h"
#include "unit_test_framework.hpp"

// TEST takes in one argument: the name of the test case.
// Note that the name of the test case must be a valid function name in C++.
Expand All @@ -64,7 +64,7 @@ TEST_MAIN()


## How to write a test case: The `TEST()` macro
Test cases can be declared using the special `TEST()` macro defined in `unit_test_framework.h`:
Test cases can be declared using the special `TEST()` macro defined in `unit_test_framework.hpp`:
```c++
TEST(<test_name>) {
// test case code
Expand Down
24 changes: 12 additions & 12 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@ In this tutorial, you will learn how to write test cases using a lightweight fra

# Setting Up

First, you will need the file `unit_test_framework.h`. This file is included with the starter code for EECS 280 projects where you are expected to use it. You can also download it directly (e.g. for this tutorial) with the following command.
First, you will need the file `unit_test_framework.hpp`. This file is included with the starter code for EECS 280 projects where you are expected to use it. You can also download it directly (e.g. for this tutorial) with the following command.

```console
$ wget https://raw.githubusercontent.com/eecs280staff/unit_test_framework/main/unit_test_framework.h
$ wget https://raw.githubusercontent.com/eecs280staff/unit_test_framework/main/unit_test_framework.hpp
```

For this tutorial, you'll need two files, `arrays.h` and `arrays.cpp`.
For this tutorial, you'll need two files, `arrays.hpp` and `arrays.cpp`.

```console
$ wget https://eecs280staff.github.io/unit_test_framework/arrays.h
$ wget https://eecs280staff.github.io/unit_test_framework/arrays.hpp
$ wget https://eecs280staff.github.io/unit_test_framework/arrays.cpp
```

Expand All @@ -35,8 +35,8 @@ These functions contain implementations of two functions (`slideRight()` and `fl
Your tests should go in a new file, called `arrays_tests.cpp`. Add the following code to `arrays_tests.cpp`:

```c++
#include "arrays.h"
#include "unit_test_framework.h"
#include "arrays.hpp"
#include "unit_test_framework.hpp"

// We define a test case with the TEST(<test_name>) macro.
// <test_name> can be any valid C++ function name.
Expand Down Expand Up @@ -112,8 +112,8 @@ Assertion | Description

# Example: Tests for an `add()` function

Suppose we have an `add()` function that computes the sum of two
`double` arguments:
Suppose we have an `add()` function, defined in the file
`eecs280math.hpp`, that computes the sum of two `double` arguments:

```c++
double add(double first, double second) {
Expand Down Expand Up @@ -190,8 +190,8 @@ TEST(add_basic) {
Finally, let's add `TEST_MAIN()` and any `#include`s that we need:

```c++
#include "eecs280math.h"
#include "unit_test_framework.h"
#include "eecs280math.hpp"
#include "unit_test_framework.hpp"

TEST(add_basic) {
double a = 0.1;
Expand All @@ -212,8 +212,8 @@ Now, let's add some real test cases for `slideRight()` and `flip()` to `arrays_t
For example, here's one test for each function (you can replace your existing code in `arrays_tests.cpp` with the code below):

```c++
#include "arrays.h"
#include "unit_test_framework.h"
#include "arrays.hpp"
#include "unit_test_framework.hpp"

// A helper function for comparing arrays. Returns true if the
// arrays are the same size and contain the same values.
Expand Down
2 changes: 1 addition & 1 deletion docs/arrays.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "arrays.h"
#include "arrays.hpp"

// REQUIRES: there are at least n elements in arr;
// n >= 1
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion docs/my_tests.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// File: my_tests.cpp

#include "unit_test_framework.h"
#include "unit_test_framework.hpp"

// TEST takes in one argument: the name of the test case.
// Note that the name of the test case must be a valid function name in C++.
Expand Down
2 changes: 1 addition & 1 deletion test/array_compare_error.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "unit_test_framework.h"
#include "unit_test_framework.hpp"

TEST(foo) {
int c[] = { 1, 2 };
Expand Down
2 changes: 1 addition & 1 deletion test/char_array.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include <string>
#include <vector>
#include <utility>
#include "unit_test_framework.h"
#include "unit_test_framework.hpp"

using namespace std;

Expand Down
2 changes: 1 addition & 1 deletion test/end_to_end_test.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "unit_test_framework.h"
#include "unit_test_framework.hpp"

#include <stdexcept>

Expand Down
2 changes: 1 addition & 1 deletion test/missing_overload_error.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "unit_test_framework.h"
#include "unit_test_framework.hpp"

struct A {
bool operator==(const A &rhs) const {
Expand Down
2 changes: 1 addition & 1 deletion test/pairs_and_sequences.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include <string>
#include <vector>
#include <utility>
#include "unit_test_framework.h"
#include "unit_test_framework.hpp"

using namespace std;

Expand Down
2 changes: 1 addition & 1 deletion test/sequence_equal.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include <vector>
#include "unit_test_framework.h"
#include "unit_test_framework.hpp"

TEST(array_equal) {
int a[] = { 1, 2 };
Expand Down
2 changes: 1 addition & 1 deletion test/size_t_and_int.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "unit_test_framework.h"
#include "unit_test_framework.hpp"

TEST(size_t_and_int) {
std::size_t s = 3u;
Expand Down
2 changes: 1 addition & 1 deletion test/string_equal.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include <string>
#include "unit_test_framework.h"
#include "unit_test_framework.hpp"

TEST(string_equal) {
std::string s1 = "hello";
Expand Down
2 changes: 1 addition & 1 deletion test/test_early_exit.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "unit_test_framework.h"
#include "unit_test_framework.hpp"

TEST(early_exit) {
std::exit(0);
Expand Down
2 changes: 1 addition & 1 deletion test/test_name_conflict_file_with_tests.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "unit_test_framework.h"
#include "unit_test_framework.hpp"

// We have a function with the same name in
// test_name_conflict_file_with_non_static_func.cpp.
Expand Down
2 changes: 1 addition & 1 deletion test/test_special_asserts.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "unit_test_framework.h"
#include "unit_test_framework.hpp"

#include <iostream>
#include <cassert>
Expand Down
6 changes: 3 additions & 3 deletions unit_test_framework.h → unit_test_framework.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef UNIT_TEST_FRAMEWORK_H
#define UNIT_TEST_FRAMEWORK_H
#ifndef UNIT_TEST_FRAMEWORK_HPP
#define UNIT_TEST_FRAMEWORK_HPP

#include <map>
#include <utility>
Expand Down Expand Up @@ -648,4 +648,4 @@ void assert_almost_equal(double first, double second, double precision,
throw TestFailure(reason.str(), line_number, assertion_text);
}

#endif // UNIT_TEST_FRAMEWORK_H
#endif // UNIT_TEST_FRAMEWORK_HPP
Loading