Skip to content

Passing moose_tests

jacklinzoho edited this page Dec 10, 2015 · 11 revisions

From the Moose dev team:

The process that we use is pull request centered. Changes to the app are made via a pull request. Typically from a forked >version but this is not required. The pull requests are made against the "devel" branch of the repo. Once a pull request is made, the webhook will notify www.moosebuild.org and it will grab the PR, build the app, and run >the tests. You will be able to see the results and output on www.moosebuild.org but you can see pass/fail results on the >PR on github.

Once the PR is accepted and then merged into devel, the same process happens against the devel branch. This will test it >and if all the tests pass, it will get merged into master.

The system is pretty flexible so if this sort of workflow doesn't work for you we can change it ( like if you don't want >PRs and just want to push to a branch ).

Right now I just set it up to run your "run_tests".

On the backend it is just shell scripts so if there is anything special you need it is easily doable.

The automated pre-test is as follows:

function tab_files()
{
  find . \( -name '*.[Chi]' -or -name '*.py' -or \( -name "crow" -or -name "contrib" -or -name "libmesh" -or -name ".git" \) -prune -and -type f \) -print0 | xargs -0 perl -nle 'if ($ARGV   ne $oldargv && /\t/) { print "\t$ARGV"; $oldargv=$ARGV }'
}

function banned_keywords()
{
  find . \( -name '*.[Chi]' -or \( -name "contrib" -or -name "libmesh" -or -name ".git" \) -prune -and -type f \) -print0 | xargs -0 perl -nle 'if ($ARGV ne $oldargv && (/std::cout|std::cerr/ || /sleep\s*\(/ || ($ARGV !~ /MooseError.h/ && /print_trace/))) { print "\t$ARGV"; $oldargv=$ARGV }'
}

function style_files()
{
  find . \( -name '*.[Ch]' -or \( -name "contrib" -or -name "libmesh" -or -name ".git" \) -prune -and -type f \) -print0 | xargs -0 perl -nle 'if ($ARGV ne $oldargv &&   (/\bfor\(/ || /\bif\(/ || /\bwhile\(/ || /\bswitch\(/)) { print "\t$ARGV"; $oldargv=$ARGV }'
}

function whitespace_files()
{
  find . \( -name '*.[Chi]' -or -name '*.py' -or \( -name "crow" -or -name "contrib" -or -name "libmesh" -or -name ".git" \) -prune -and -type f \) -print0 | xargs -0 perl -nle 'if ($ARGV ne $oldargv && /\s+$/) { print "\t$ARGV"; $oldargv=$ARGV }'
}

A local version of this test has been included in the Redback folder, under moose_tests.sh.

To use it, run:

./moose_tests.sh [test]

Where [test] = 0 runs all tests, 1-4 runs the tests individually.

#Update: Passing the tests automatically

Now automated! Run the following from the Redback directory to format your code before a commit:

./formatter.sh

#Passing the tests, long version

Basically, we are setting up our files to pass the tests on this page:

http://mooseframework.org/wiki/CodeStandards/

##Test 1: Tab Files For each of the files pointed out by moose_tests, open in Atom; go to Packages->Whitespace->Convert Tabs to Spaces. Save and rerun moose_tests, it should now pass for the file.

##Test 2: Banned Keywords Run moose_tests 2; manually remove each of the banned keywords while making sure you're not breaking the code.

We're asking the Moose team to exclude the Unit folder so we can use e.g. std::cerr.

##Test 3: Style Files Run moose_tests 3; for each of the files it complains about, open in Atom, go to Packages-> Clang-format -> Format. This auto-formats your file to match most of the Moose guidelines regarding spaces and newlines. Note that it will not fix variable naming or other more complicated stuff.

Also, this only works for .C and .h files. Using clang-format on .i or .py files will produce nonsense.

##Test 4: Whitespaces

After your code passes the first three tests, run this command in the console, from the Redback directory, to strip trailing whitespaces and tabs from your .py and .i files:

find . -name '*.[Chi]' -or -name '*.py' | xargs perl -pli -e 's/\s+$//'