Skip to content

Correction for issue #102 #110

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

Closed
wants to merge 3 commits into from
Closed
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
16 changes: 16 additions & 0 deletions SampleProjects/DoSomething/do-something.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,19 @@ int doSomething(void) {
millis(); // this line is only here to test that we're able to refer to the builtins
return 4;
};

static const struct something table[] = {
{ 1, "abc" },
{ 2, "xyz" },
{ 4, "123" },
};

const struct something *findSomething(int id) {
for (unsigned int i = 0; i < 3; i++) {
if (table[i].id == id) {
return &table[i];
}
}
return nullptr;
}

8 changes: 8 additions & 0 deletions SampleProjects/DoSomething/do-something.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
#pragma once
#include <Arduino.h>
int doSomething(void);

struct something {
int id;
const char *text;
};

const struct something *findSomething(int id);

3 changes: 3 additions & 0 deletions SampleProjects/DoSomething/test/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Naming convention #

Files in this directory is expected to have names that either contains "bad" if it is expected to fail or "good" if it is expected to pass.
21 changes: 21 additions & 0 deletions SampleProjects/DoSomething/test/good-find-something.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include <ArduinoUnitTests.h>

#include "do-something.h"

unittest(find_something_that_exists)
{
const struct something *result;
result = findSomething(1);
assertNotNull(result);
assertEqual("abc", result->text);
}

unittest(find_something_that_does_not_exists)
{
const struct something *result;
result = findSomething(1000);
assertNull(result);
}

unittest_main()

1 change: 1 addition & 0 deletions spec/cpp_library_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ def get_relative_dir(sampleprojects_tests_dir)
dosomething_test_files = [
"DoSomething/test/good-null.cpp",
"DoSomething/test/good-library.cpp",
"DoSomething/test/good-find-something.cpp",
"DoSomething/test/bad-null.cpp",
].map { |f| Pathname.new(f) }
relative_paths = cpp_library.test_files.map { |f| get_relative_dir(f) }
Expand Down