diff --git a/.gitignore b/.gitignore index 0cb2e09466..02f986ce8b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ .fatten.out *.ckan +netkan.exe diff --git a/.travis.yml b/.travis.yml index 753a212798..e421f2c1e5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,7 @@ -language: c +language: csharp install: - - sudo apt-get install python-demjson libtest-most-perl libjson-any-perl + - sudo apt-get install python-demjson libtest-most-perl libjson-any-perl libwww-mechanize-perl libipc-system-simple-perl script: - jsonlint -s -v NetKAN/*.netkan diff --git a/t/kerbalstuff.t b/t/kerbalstuff.t new file mode 100755 index 0000000000..ed007e8f85 --- /dev/null +++ b/t/kerbalstuff.t @@ -0,0 +1,77 @@ +#!/usr/bin/perl -w +use 5.010; +use strict; +use warnings; +use autodie qw(:all); +use Test::More; +use IPC::System::Simple qw(capture); +use WWW::Mechanize; + +my $pr_branch = $ENV{TRAVIS_PULL_REQUEST}; +my $netkan = "./netkan.exe"; + +if (! $pr_branch or $pr_branch eq "false") { + plan skip_all => "Not a pull request"; +} + +if (! -x $netkan) { + + # If we don't already have a netkan executable, then go download the latest. + # This includes unstable netkan.exe builds, as submissions may reference + # experimental features. + + my $agent = WWW::Mechanize->new( agent => "NetKAN travis testing" ); + $agent->get("https://github.com/KSP-CKAN/CKAN/releases"); + $agent->follow_link(text => 'netkan.exe'); + + open(my $fh, '>', $netkan); + binmode($fh); + print {$fh} $agent->content; + close($fh); + chmod(0755, $netkan); +} + +# TODO: What if our PR is against something other than master? +my @changed_files = capture("git diff --name-only master"); +chomp(@changed_files); + +# Walk through our changed files. If any of them mention KS, then +# run netkan over them. (We have @sircmpwn's permission to make KS +# downloads during CI testing.) + +foreach my $file (@changed_files) { + if (is_ks_file($file)) { + netkan_validate($file); + } +} + +done_testing; + +sub is_ks_file { + my ($file) = @_; + + # Not a netkan file? Not something we want to test. + return 0 if ($file !~ m{\.netkan$}); + + local $/; # Slurp mode. + + open(my $fh, '<', $file); + my $content = <$fh>; + close($fh); + + return $content =~ m{#/ckan/kerbalstuff}; +} + +# Simply checks to see if netkan.exe runs without errors on this file +sub netkan_validate { + my ($file) = @_; + + my $valid = eval { + system($netkan, $file); + return 1; + }; + + if ($@) { diag $@ } + + ok($valid, $file); +}