Add simple build functional test
This commit is contained in:
		
							parent
							
								
									52814a5b7b
								
							
						
					
					
						commit
						c0a58d1bc7
					
				
					 2 changed files with 123 additions and 3 deletions
				
			
		|  | @ -87,10 +87,10 @@ publishing { | ||||||
| """ | """ | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| static String genPropsFile(String mcVersion, String yarnVersion, String loaderVersion, String fabricVersion) { | static String genPropsFile(String mcVersion, String yarnVersion, String loaderVersion, String fabricVersion, boolean caching = true, boolean parallel = true) { | ||||||
| 	""" | 	""" | ||||||
| org.gradle.caching=true | org.gradle.caching=$caching | ||||||
| org.gradle.parallel=true | org.gradle.parallel=$parallel | ||||||
| 
 | 
 | ||||||
| # Fabric Properties | # Fabric Properties | ||||||
| # check these on https://fabricmc.net/use | # check these on https://fabricmc.net/use | ||||||
|  | @ -114,3 +114,62 @@ static String genSettingsFile(String name) { | ||||||
| rootProject.name = '$name' | rootProject.name = '$name' | ||||||
| """ | """ | ||||||
| } | } | ||||||
|  | 
 | ||||||
|  | static String genModJsonFile() { | ||||||
|  | 	""" | ||||||
|  | { | ||||||
|  |   "schemaVersion": 1, | ||||||
|  |   "id": "modid", | ||||||
|  |   "version": "\${version}", | ||||||
|  | 
 | ||||||
|  |   "name": "Example Mod", | ||||||
|  |   "description": "This is an example description! Tell everyone what your mod is about!", | ||||||
|  |   "authors": [ | ||||||
|  |     "Me!" | ||||||
|  |   ], | ||||||
|  |   "contact": { | ||||||
|  |     "homepage": "https://fabricmc.net/", | ||||||
|  |     "sources": "https://github.com/FabricMC/fabric-example-mod" | ||||||
|  |   }, | ||||||
|  | 
 | ||||||
|  |   "license": "CC0-1.0", | ||||||
|  | 
 | ||||||
|  |   "environment": "*", | ||||||
|  |   "entrypoints": { | ||||||
|  |     "main": [ | ||||||
|  |       "net.fabricmc.example.ExampleMod" | ||||||
|  |     ] | ||||||
|  |   }, | ||||||
|  |   "mixins": [ | ||||||
|  |     "modid.mixins.json" | ||||||
|  |   ], | ||||||
|  | 
 | ||||||
|  |   "depends": { | ||||||
|  |     "fabricloader": ">=0.4.0", | ||||||
|  |     "fabric": "*" | ||||||
|  |   }, | ||||||
|  |   "suggests": { | ||||||
|  |     "flamingo": "*" | ||||||
|  |   } | ||||||
|  | } | ||||||
|  | """ | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | static String genModExampleFile() { | ||||||
|  | 	""" | ||||||
|  | package net.fabricmc.example; | ||||||
|  | 
 | ||||||
|  | import net.fabricmc.api.ModInitializer; | ||||||
|  | 
 | ||||||
|  | public class ExampleMod implements ModInitializer { | ||||||
|  | 	@Override | ||||||
|  | 	public void onInitialize() { | ||||||
|  | 		// This code runs as soon as Minecraft is in a mod-load-ready state. | ||||||
|  | 		// However, some things (like resources) may still be uninitialized. | ||||||
|  | 		// Proceed with mild caution. | ||||||
|  | 
 | ||||||
|  | 		System.out.println("Hello Fabric world!"); | ||||||
|  | 	} | ||||||
|  | } | ||||||
|  | """ | ||||||
|  | } | ||||||
|  |  | ||||||
|  | @ -0,0 +1,61 @@ | ||||||
|  | package net.fabricmc.loom | ||||||
|  | 
 | ||||||
|  | import org.gradle.testkit.runner.GradleRunner | ||||||
|  | import org.junit.Rule | ||||||
|  | import org.junit.rules.TemporaryFolder | ||||||
|  | import spock.lang.Specification | ||||||
|  | import spock.lang.Unroll | ||||||
|  | 
 | ||||||
|  | import static net.fabricmc.loom.BuildUtils.* | ||||||
|  | import static org.gradle.testkit.runner.TaskOutcome.SUCCESS | ||||||
|  | 
 | ||||||
|  | /** | ||||||
|  |  * Created by Mitchell Skaggs on 6/10/2019. | ||||||
|  |  */ | ||||||
|  | class SimpleBuildFunctionalTest extends Specification { | ||||||
|  | 	@Rule | ||||||
|  | 	TemporaryFolder testProjectDir = new TemporaryFolder() | ||||||
|  | 	File settingsFile | ||||||
|  | 	File buildFile | ||||||
|  | 	File propsFile | ||||||
|  | 	File modJsonFile | ||||||
|  | 	File modExampleFile | ||||||
|  | 
 | ||||||
|  | 	def setup() { | ||||||
|  | 		settingsFile = testProjectDir.newFile('settings.gradle') | ||||||
|  | 		buildFile = testProjectDir.newFile('build.gradle') | ||||||
|  | 		propsFile = testProjectDir.newFile('gradle.properties') | ||||||
|  | 
 | ||||||
|  | 		testProjectDir.newFolder("src", "main", "resources") | ||||||
|  | 		modJsonFile = testProjectDir.newFile('src/main/resources/fabric.mod.json') | ||||||
|  | 
 | ||||||
|  | 		testProjectDir.newFolder("src", "main", "java", "net", "fabricmc", "example") | ||||||
|  | 		modExampleFile = testProjectDir.newFile("src/main/java/net/fabricmc/example/ExampleMod.java") | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	@Unroll | ||||||
|  | 	def "simple build succeeds using Minecraft #mcVersion"() { | ||||||
|  | 		given: | ||||||
|  | 		settingsFile << genSettingsFile("simple-build-functional-test") | ||||||
|  | 		propsFile << genPropsFile(mcVersion, yarnVersion, loaderVersion, fabricVersion) | ||||||
|  | 		buildFile << genBuildFile() | ||||||
|  | 		modJsonFile << genModJsonFile() | ||||||
|  | 		modExampleFile << genModExampleFile() | ||||||
|  | 
 | ||||||
|  | 		when: | ||||||
|  | 		def result = GradleRunner.create() | ||||||
|  | 				.withProjectDir(testProjectDir.root) | ||||||
|  | 				.withArguments('build') | ||||||
|  | 				.withPluginClasspath() | ||||||
|  | 				.build() | ||||||
|  | 
 | ||||||
|  | 		then: | ||||||
|  | 		result.task(":build").outcome == SUCCESS | ||||||
|  | 
 | ||||||
|  | 		where: | ||||||
|  | 		mcVersion | yarnVersion       | loaderVersion     | fabricVersion | ||||||
|  | 		'1.14'    | '1.14+build.21'   | '0.4.8+build.155' | '0.3.0+build.184' | ||||||
|  | 		'1.14.1'  | '1.14.1+build.10' | '0.4.8+build.155' | '0.3.0+build.184' | ||||||
|  | 		'1.14.2'  | '1.14.2+build.7'  | '0.4.8+build.155' | '0.3.0+build.184' | ||||||
|  | 	} | ||||||
|  | } | ||||||
		Loading…
	
		Reference in a new issue