From 292366b310725f1b70d6f0e4c41c3f81cd1cb2cb Mon Sep 17 00:00:00 2001 From: Evgeny Goldin Date: Tue, 17 Jan 2012 01:19:10 +0200 Subject: [PATCH] Ant task - wrapper + "compilation-fail-tests" task testing fails if compilation fails --- build-tools/build.xml | 60 ++++++++++++++++---- build-tools/test/compilation-fail/Bottles.kt | 59 +++++++++++++++++++ 2 files changed, 109 insertions(+), 10 deletions(-) create mode 100644 build-tools/test/compilation-fail/Bottles.kt diff --git a/build-tools/build.xml b/build-tools/build.xml index 45b19aae2cb..8202b219f1d 100644 --- a/build-tools/build.xml +++ b/build-tools/build.xml @@ -42,6 +42,27 @@ + + + + + + + + + + + + + + + + + + + + + @@ -84,13 +105,10 @@ - - - - - - - + + + + @@ -111,9 +129,7 @@ - - - + @@ -122,6 +138,29 @@ + + + + + + + + + + + + + + + + + + + + + + + @@ -152,5 +191,6 @@ + diff --git a/build-tools/test/compilation-fail/Bottles.kt b/build-tools/test/compilation-fail/Bottles.kt new file mode 100644 index 00000000000..7e2e0f02c99 --- /dev/null +++ b/build-tools/test/compilation-fail/Bottles.kt @@ -0,0 +1,59 @@ +/** + * "Bottles.kt" that doesn't compile, see line 6. + */ +package bottles + +fun main(args : Array + if (args.isEmpty) { + printBottles(99) + } + else { + try { + printBottles(Integer.parseInt(args[0])) + } + catch (e : NumberFormatException) { + System.err?.println("You have passed '${args[0]}' as a number of bottles, " + + "but it is not a valid integral number") + } + } +} + +fun printBottles(bottleCount : Int) { + if (bottleCount <= 0) { + println("No bottles - no song") + return + } + + println("The \"${bottlesOfBeer(bottleCount)}\" song\n") + + var bottles = bottleCount + while (bottles > 0) { + val bottlesOfBeer = bottlesOfBeer(bottles) + print("$bottlesOfBeer on the wall, $bottlesOfBeer.\nTake one down, pass it around, ") + bottles-- + println("${bottlesOfBeer(bottles)} on the wall.\n") + } + println("No more bottles of beer on the wall, no more bottles of beer.\n" + + "Go to the store and buy some more, ${bottlesOfBeer(bottleCount)} on the wall.") +} + +fun bottlesOfBeer(count : Int) : String = + when (count) { + 0 -> "no more bottles" + 1 -> "1 bottle" + else -> "$count bottles" + } + " of beer" + +/* + * An excerpt from the Standard Library + */ + +// From the std.io package +// These are simple functions that wrap standard Java API calls +fun print(message : String) { System.out?.print(message) } +fun println(message : String) { System.out?.println(message) } + +// From the std package +// This is an extension property, i.e. a property that is defined for the +// type Array, but does not sit inside the class Array +val Array.isEmpty : Boolean get() = size == 0