Skip to content

Commit

Permalink
First commit
Browse files Browse the repository at this point in the history
  • Loading branch information
GMadorell committed Jul 16, 2017
0 parents commit 6f62383
Show file tree
Hide file tree
Showing 12 changed files with 192 additions and 0 deletions.
17 changes: 17 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
; This file is for unifying the coding style for different editors and IDEs.
; More information at http://editorconfig.org

root = true

[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true

[*.scala]
indent_size = 2
indent_style = space

[*.md]
trim_trailing_whitespace = false
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
target/
boot/
lib_managed/
src_managed/
project/plugins/project/
8 changes: 8 additions & 0 deletions .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
style = defaultWithAlign

maxColumn = 120

project.excludeFilters = ["target/"]

# Only format files tracked by git.
project.git = true
11 changes: 11 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
language: scala

scala:
- 2.12.2

jdk:
- oraclejdk8

script:
## This runs the template with the default parameters, and runs test within the templated app.
- sbt -Dfile.encoding=UTF8 -J-XX:ReservedCodeCacheSize=256M test
32 changes: 32 additions & 0 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/** ********* PROJECT INFO ******************/
name := "poker_api"
version := "0.0.1"

/** ********* PROJECT SETTINGS ******************/
Configuration.settings

/** ********* PROD DEPENDENCIES *****************/
libraryDependencies ++= Seq(
"com.github.nscala-time" %% "nscala-time" % "2.16.0",
"com.lihaoyi" %% "pprint" % "0.5.2"
)

/** ********* TEST DEPENDENCIES *****************/
libraryDependencies ++= Seq(
"org.scalatest" %% "scalatest" % "3.0.1" % Test,
"org.scalamock" %% "scalamock-scalatest-support" % "3.6.0" % Test
)

/** ********* COMMANDS ALIASES ******************/
addCommandAlias("t", "test")
addCommandAlias("to", "testOnly")
addCommandAlias("tq", "testQuick")
addCommandAlias("tsf", "testShowFailed")

addCommandAlias("c", "compile")
addCommandAlias("tc", "test:compile")

addCommandAlias("f", "scalafmt") // Format all files according to ScalaFmt
addCommandAlias("ft", "scalafmtTest") // Test if all files are formatted according to ScalaFmt

addCommandAlias("prep", ";c;tc;ft") // All the needed tasks before running the test
8 changes: 8 additions & 0 deletions doc/hooks/install-hooks.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/sh

cd "$(dirname "$0")/../.."

rm -rf .git/hooks

ln -s ../doc/hooks .git/hooks
sudo chmod -R 777 doc/hooks/*
50 changes: 50 additions & 0 deletions doc/hooks/pre-push
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/bin/bash

# Checks if locally staged changes are formatted properly ignoring non-staged changes.
# Install it with the `install-hooks.sh` script
# Based on: https://gist.github.com/cvogt/2676ed6c6d1abafa3d6a

PATH=$PATH:/usr/local/bin:/usr/local/sbin

echo ""
echo "Running pre-push hook… (you can omit this with --no-verify, but don't)"

echo "* Moving to the project directory…"
_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
DIR=$( echo $_DIR | sed 's/\/.git\/hooks$//' )

echo "* Stashing non-staged changes so we avoid checking them…"
git diff --quiet
hadNoNonStagedChanges=$?

if ! [ $hadNoNonStagedChanges -eq 0 ]
then
git stash --keep-index -u > /dev/null
fi

echo "* Checking pre push conditions ('prep' SBT task)…"
sbt prep > /dev/null
canPush=$?

if [ $canPush -ne 0 ]
then
echo " [KO] Error :("
fi

echo "* Applying the stash with the non-staged changes…"
if ! [ $hadNoNonStagedChanges -eq 0 ]
then
sleep 1 && git stash pop --index > /dev/null & # sleep because otherwise commit fails when this leads to a merge conflict
fi

# Final result
echo ""

if [ $canPush -eq 0 ]
then
echo "[OK] Your code will be pushed young Padawan"
exit 0
else
echo "[KO] Cancelling push due to test code style error (run 'sbt prep' for more information)"
exit 1
fi
31 changes: 31 additions & 0 deletions project/Configuration.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import sbt.{Tests, _}
import sbt.Keys._

object Configuration {
val settings = Seq(
organization := "com.lambtors",
scalaVersion := "2.12.2",
// Compiler options
scalacOptions ++= Seq(
"-deprecation", // Warnings deprecation
"-feature", // Advise features
"-unchecked", // More warnings. Strict
"-Xlint", // More warnings when compiling
"-Xfatal-warnings", // Warnings became errors
"-Ywarn-dead-code",
"-Ywarn-unused",
"-Ywarn-unused-import",
"-Xcheckinit" // Check against early initialization
),
scalacOptions in run in Compile -= "-Xcheckinit", // Remove it in production because it's expensive
javaOptions += "-Duser.timezone=UTC",
// Test options
parallelExecution in Test := false,
testForkedParallel in Test := false,
fork in Test := true,
testOptions in Test ++= Seq(
Tests.Argument(TestFrameworks.ScalaTest, "-u", "target/test-reports"), // Save test reports
Tests.Argument("-oDF") // Show full stack traces and time spent in each test
)
)
}
1 change: 1 addition & 0 deletions project/build.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sbt.version=0.13.15
1 change: 1 addition & 0 deletions project/scalafmt.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
addSbtPlugin("com.geirsson" % "sbt-scalafmt" % "0.6.6")
5 changes: 5 additions & 0 deletions src/main/scala/com/lambtors/poker_api/Poker_api.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.lambtors.poker_api

class Poker_api {
def greet(name: String): String = "Hello " + name
}
23 changes: 23 additions & 0 deletions src/test/scala/com/lambtors/poker_api/Poker_apiTest.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.lambtors.poker_api

import org.scalatest._
import org.scalatest.Matchers._

final class Poker_apiTest extends WordSpec with GivenWhenThen {
"Poker_api" should {
"greet" in {
Given("a Poker_api")

val poker_api = new Poker_api

When("we ask him to greet someone")

val nameToGreet = "CodelyTV"
val greeting = poker_api.greet(nameToGreet)

Then("it should say hello to someone")

greeting shouldBe "Hello " + nameToGreet
}
}
}

0 comments on commit 6f62383

Please sign in to comment.