1#!/usr/bin/env python 2 3import json 4import os 5import urllib2 6 7from scriptCommon import catchPath 8 9def upload(options): 10 request = urllib2.Request('http://melpon.org/wandbox/api/compile.json') 11 request.add_header('Content-Type', 'application/json') 12 response = urllib2.urlopen(request, json.dumps(options)) 13 return json.loads(response.read()) 14 15main_file = ''' 16#define CATCH_CONFIG_MAIN // This tells Catch to provide a main() - only do this in one cpp file 17#include "catch.hpp" 18 19unsigned int Factorial( unsigned int number ) { 20 return number <= 1 ? number : Factorial(number-1)*number; 21} 22 23TEST_CASE( "Factorials are computed", "[factorial]" ) { 24 REQUIRE( Factorial(1) == 1 ); 25 REQUIRE( Factorial(2) == 2 ); 26 REQUIRE( Factorial(3) == 6 ); 27 REQUIRE( Factorial(10) == 3628800 ); 28} 29''' 30 31def uploadFiles(): 32 response = upload({ 33 'compiler': 'gcc-head', 34 'code': main_file, 35 'codes': [{ 36 'file': 'catch.hpp', 37 'code': open(os.path.join(catchPath, 'single_include', 'catch2', 'catch.hpp')).read() 38 }], 39 'options': 'c++11,cpp-no-pedantic,boost-nothing', 40 'compiler-option-raw': '-DCATCH_CONFIG_FAST_COMPILE', 41 'save': True 42 }) 43 44 if 'status' in response and 'compiler_error' not in response: 45 return True, response['url'] 46 else: 47 return False, response 48