From 936d5d36469ee4b094757773a38de9c0c21078a9 Mon Sep 17 00:00:00 2001 From: Nic McPhee Date: Mon, 26 Sep 2016 21:15:55 -0500 Subject: [PATCH 1/7] Added a fuller set of C files to git ignore I also removed the exclusion for the old CMockery library, and added `*~` for emacs. --- .gitignore | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 4b7263a..b967c6a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,10 +1,25 @@ +####### +# C/C++ +####### + +# Prerequisites +*.d + # Object files *.o +*.ko +*.obj +*.elf + +# Precompiled Headers +*.gch +*.pch # Libraries *.lib *.a -!lib/libcmockery_la-cmockery.o +*.la +*.lo # Shared objects (inc. Windows DLLs) *.dll @@ -16,3 +31,16 @@ *.exe *.out *.app +*.i*86 +*.x86_64 +*.hex + +# Debug files +*.dSYM/ +*.su + +####### +# emacs +####### + +*~ From 83f2632d41cacaaa59ab997c1256417d25c50205 Mon Sep 17 00:00:00 2001 From: Nic McPhee Date: Mon, 26 Sep 2016 21:31:32 -0500 Subject: [PATCH 2/7] Remove references to `main.c` I decided that writing a `main` that can be meaningfully called from the command line isn't really worth the trouble, so I just removed references to it. --- README.md | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/README.md b/README.md index 3b0d456..3beb223 100644 --- a/README.md +++ b/README.md @@ -78,9 +78,6 @@ The basic structure for each project is (for an imaginary project want to include them in the tests. - `foo.c`, which includes the initial stub (or an incorrect version) of the program you're working with in that part. -- `main.c`, which gives you a "main" function that you can use to - run your code separate from the test code. You don't have to ever - do this, but you might find it useful in debugging. - `foo_test.cpp`, which is the test file we wrote using `gtest`. The `.cpp` ending is because this is actually a C++ file not a strict C file. That will affect how you compile the test code, but you @@ -89,16 +86,6 @@ The basic structure for each project is (for an imaginary project Your job then is typically to complete or fix `foo.c`, which provides the implementation of the function listed in `foo.h`. -To compile the `main` use the following: - -```bash -gcc -Wall -g -o foo foo.c main.c -``` - -(where you replace `foo` with the appropriate name for the project -you're working on). If all goes well, that should generate an executable -`foo` that you can run with `./foo`. - To compile the test code use the following: ```bash From a187cc1b251aea78079b49daf00065084415dbc7 Mon Sep 17 00:00:00 2001 From: Nic McPhee Date: Mon, 26 Sep 2016 21:32:54 -0500 Subject: [PATCH 3/7] Ignore the generated testing binary I added a `.gitignore` that has the testing binary in it so we don't commit that. --- mergesort/.gitignore | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 mergesort/.gitignore diff --git a/mergesort/.gitignore b/mergesort/.gitignore new file mode 100644 index 0000000..1677180 --- /dev/null +++ b/mergesort/.gitignore @@ -0,0 +1,2 @@ +# Ignore the generated binary +mergesort_test From 6525961376ee0e382eeb47d94d2d6d48a4c131d8 Mon Sep 17 00:00:00 2001 From: Nic McPhee Date: Mon, 26 Sep 2016 21:33:52 -0500 Subject: [PATCH 4/7] Updated mergesort tests to use gtest This updates the mergesort tests to use the Google Test framework. That also involves renaming the test from `.c` to `.cpp` since Google Test uses C++. --- mergesort/mergesort_test.c | 78 ------------------------------------ mergesort/mergesort_test.cpp | 65 ++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+), 78 deletions(-) delete mode 100644 mergesort/mergesort_test.c create mode 100644 mergesort/mergesort_test.cpp diff --git a/mergesort/mergesort_test.c b/mergesort/mergesort_test.c deleted file mode 100644 index 5047d80..0000000 --- a/mergesort/mergesort_test.c +++ /dev/null @@ -1,78 +0,0 @@ -#include -#include -#include - -#include "../include/cmockery.h" -#include "mergesort.h" - -bool arrays_match(int size, int a[], int b[]) { - int i; - - for (i=0; i + +#include "mergesort.h" + +void arrays_match(int size, int a[], int b[]) { + int i; + + for (i=0; i Date: Mon, 26 Sep 2016 21:47:25 -0500 Subject: [PATCH 5/7] Ignore generated test executable for array merge This adds a `.gitignore` that ignores the generated executable for `array_merge_test`. --- array_merge/.gitignore | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 array_merge/.gitignore diff --git a/array_merge/.gitignore b/array_merge/.gitignore new file mode 100644 index 0000000..9caf2dc --- /dev/null +++ b/array_merge/.gitignore @@ -0,0 +1,2 @@ +# Ignore the generated test executable +array_merge_test \ No newline at end of file From 70dc965d4946ed6d8770817db45e271224fb3226 Mon Sep 17 00:00:00 2001 From: Nic McPhee Date: Mon, 26 Sep 2016 21:48:56 -0500 Subject: [PATCH 6/7] Remove unnecessary `stdbool` include I'm not sure why that include was here, but this cleans that up. --- array_merge/array_merge.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/array_merge/array_merge.h b/array_merge/array_merge.h index b3c193f..8359aa6 100644 --- a/array_merge/array_merge.h +++ b/array_merge/array_merge.h @@ -1,8 +1,6 @@ #ifndef ARRAY_MERGE_H_GUARD #define ARRAY_MERGE_H_GUARD -#include - #define UNIT_TESTING int* array_merge(int num_arrays, int* sizes, int** values); From 8b4e8a75b606be76811405def992407844427e59 Mon Sep 17 00:00:00 2001 From: Nic McPhee Date: Mon, 26 Sep 2016 21:49:39 -0500 Subject: [PATCH 7/7] Update tests to use Google Test framework This modified the tests to use the newer Google Test framework. I also needed to rename the test file from `.c` to `.cpp` since Google Test files are C++. --- ...rray_merge_test.c => array_merge_test.cpp} | 55 +++++++------------ 1 file changed, 21 insertions(+), 34 deletions(-) rename array_merge/{array_merge_test.c => array_merge_test.cpp} (61%) diff --git a/array_merge/array_merge_test.c b/array_merge/array_merge_test.cpp similarity index 61% rename from array_merge/array_merge_test.c rename to array_merge/array_merge_test.cpp index 7c4b6a1..35fbd4a 100644 --- a/array_merge/array_merge_test.c +++ b/array_merge/array_merge_test.cpp @@ -1,31 +1,26 @@ -#include -#include -#include +#include -#include "../include/cmockery.h" #include "array_merge.h" -bool arrays_match(int size, int a[], int b[]) { +void arrays_match(int size, int a[], int b[]) { int i; for (i=0; i=0; --i) { sizes[i] = i; - a[i] = calloc(i, sizeof(int)); + a[i] = (int*) calloc(i, sizeof(int)); for (j=0; j