Coder Social home page Coder Social logo

Comments (6)

sftrabbit avatar sftrabbit commented on August 16, 2024

Great idea. It is definitely on my to-do list (currently doing a manual rebuild and deploy). Thanks for the links.

from cpppatterns-patterns.

jatindhankhar avatar jatindhankhar commented on August 16, 2024

👍

from cpppatterns-patterns.

sftrabbit avatar sftrabbit commented on August 16, 2024

I would like to do continuous deployment as well as integration. This project involves two repos though (CppSamples-Web and CppSamples-Samples) - anybody know if you can have Travis-CI trigger a build when either repo is updated?

Edit: Looks like maybe this would work if I used git submodules. Then I just need to push updates the submodule.

from cpppatterns-patterns.

jatindhankhar avatar jatindhankhar commented on August 16, 2024

Glad you found the right way. I am not a expert 😅 , so can't help much .

from cpppatterns-patterns.

sftrabbit avatar sftrabbit commented on August 16, 2024

I've implemented continuous integration/deployment for the website itself, which basically pulls in the samples, builds the site, and then pushes it to the GitHub Pages repository where it is hosted. I'll soon do some CI for this samples repository, but I need to think of a better way to test the samples (not just seeing if they compile). (sorry, just putting my thoughts here to keep note)

from cpppatterns-patterns.

DarkerStar avatar DarkerStar commented on August 16, 2024

Just a suggestion off the top of my head:

Given the simplicity of the tests, incorporating a proper test and mock framework is probably insane overkill. You could probably get by with simple hand-cranked tests in each sample file. Also it would probably be better if each sample was entirely self-contained - and thus self-testing. Trying to shadow the sample tree with a test tree just seems like an unnecessary pain.

The sample format already looks like this:

// preamble

<sample code>

// text

<hidden code>

If you specify that the "sample code" has to be a function, and the "hidden code" has to be a legal main function that calls the sample code function, you could then further specify that the main function has to do tests on the sample code.

For example (borrowing from the count() sample):

// Count occurrences of value in a range

# include <iostream>
# include <algorithm>
# include <vector>

template <typename Range>
int count_occurrences_of_3(Range const& range)
{
    int count = std::count(std::begin(range),
                           std::end(range),
                           3);

    return count;
}

// Sample description
// ...
// ...
// ...

int main()
{
    auto result = 0;

    std::vector<int> numbers = {1, 2, 3, 5, 6, 3, 4, 1};

    auto e1 = std::count(std::begin(numbers), std::end(numbers), 3);
    auto r1 = count_occurrences_of_3(numbers);
    if (r1 != e1)
    {
        std::cout << "[count-values-in-range] test 1 failed; expected [" <<
            e1 << "], got [" << r1 << "]\n";
        ++result;
    }

    // Maybe other tests...

    return result;
}

Now you can test by building the sample cpp file, and running it. The non-zero exit status will alert your CI tool - whatever you use - that there was an error, and you get some info on stdout about what went wrong. And because everything after the sample text comment block is invisible on the site, you could add as many tests as you like, or make the tests as complex as you please.

from cpppatterns-patterns.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.