Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alternative Travis build #71

Merged
merged 1 commit into from
Sep 28, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@ bin/configlet.exe
**/output
**/.psc*
**/.psa*

.work
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ sudo: false
install:
- nvm install 6
- nvm use 6
- npm install -g purescript@0.11.1 pulp@11.0.0 bower
- npm install -g purescript@0.11.6 pulp@12.0.1 bower

script:
- bin/fetch-configlet
Expand All @@ -15,4 +15,3 @@ script:
cache:
directories:
- $HOME/.cache/bower/
- $HOME/.exercise_cache/
58 changes: 0 additions & 58 deletions bin/test-one.sh

This file was deleted.

79 changes: 60 additions & 19 deletions bin/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,71 @@ xpurescript=$(dirname "$BASH_SOURCE")
xpurescript=$(readlink -f "$xpurescript/..")
cd "$xpurescript"

declare -i TEST_RESULT=0
FAILED_EXERCISES=''
# Prepare the work directory

cd exercises
work_dir="$xpurescript/.work"

for exercise_dir in *
do
"$xpurescript/bin/test-one.sh" "$exercise_dir"
mkdir -p $work_dir

if [[ $? == 0 ]]; then
TEST_RESULT=1
FAILED_EXERCISES+="$exercise_dir\n"
fi
# Clean up if this is used locally (not on Travis)

if [[ -z "$TRAVIS" ]]; then
rm $work_dir/bower.json
rm -f $work_dir/src/*.purs
rm -f $work_dir/test/*.purs
fi

for dir in src test; do
mkdir -p $work_dir/$dir
done

echo
if [[ $TEST_RESULT == 0 ]]; then
echo -e "\e[1;32mAll exercises passed\e[0;39m"
else
echo -e "\e[1;31mThe following exercises failed"
# Copy the exercises, tests and common bower.json

cp etc/bower.json $work_dir
cp exercises/*/examples/src/*.purs $work_dir/src

for exercise_full in exercises/*; do
exercise=$(basename $exercise_full)
module=$(basename $exercise_full/examples/src/*.purs)

cp exercises/$exercise/test/Main.purs $work_dir/test/$module
done

# List for troubleshooting purposes

cd $work_dir

for f in bower.json src test; do
echo
echo -e "\e[1;32m--- [ $f ]\e[0;39m"
echo

echo -e "\e[1;33m"
printf $FAILED_EXERCISES
echo -e "\e[0;39m"
ls --color -l $f
done

# Create Test.Main and update exercise test modules

cd $xpurescript

node etc/test-main-maker.js $work_dir/test
node etc/test-module-updater.js $work_dir/test

# Install bower dependencies, build and test

cd $work_dir

exit $TEST_RESULT
time bower install
time pulp test

test_result=$?

# Report the results

echo
if [[ $test_result == 0 ]]; then
echo -e "\e[1;32m[ All tests have passed ]\e[0;39m"
else
echo -e "\e[1;31m[ Some tests have failed ]\e[0;39m"
fi

exit $test_result
26 changes: 26 additions & 0 deletions etc/bower.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"name": "purescript-exercise",
"ignore": [
"**/.*",
"node_modules",
"bower_components",
"output"
],
"dependencies": {
"purescript-console": "^3.0.0",
"purescript-datetime": "^3.4.0",
"purescript-either": "^3.1.0",
"purescript-enums": "^3.2.1",
"purescript-integers": "^3.1.0",
"purescript-lists": "^4.10.0",
"purescript-maps": "^3.5.2",
"purescript-prelude": "^3.1.0",
"purescript-sets": "^3.0.0",
"purescript-strings": "^3.3.1",
"purescript-unicode": "^3.0.1"
},
"devDependencies": {
"purescript-psci-support": "^3.0.0",
"purescript-test-unit": "^13.0.0"
}
}
48 changes: 48 additions & 0 deletions etc/test-main-maker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
const fs = require('fs')
const os = require('os')
const path = require('path')

const testDir = process.argv[2]

const modules = fs
.readdirSync(testDir)
.map(f => f.replace(/.purs$/, ''))

const testMainFile = path.join(testDir, 'Main.purs')

const eol = os.EOL

const imports = modules
.map(m => 'import Test.' + m + ' as Test' + m)
.join(eol)

const calls = modules
.map(m => ' Test' + m + '.suites')
.join(eol)

const testMain = `
module Test.Main where

import Prelude
import Control.Monad.Eff (Eff)
import Control.Monad.Eff.AVar (AVAR)
import Control.Monad.Eff.Console (CONSOLE)
import Test.Unit.Console (TESTOUTPUT)
import Test.Unit.Main (runTest)

`
+ imports +
`

main :: forall eff
. Eff ( avar :: AVAR
, console :: CONSOLE
, testOutput :: TESTOUTPUT
| eff
)
Unit
main = runTest do
`
+ calls

fs.writeFileSync(testMainFile, testMain)
20 changes: 20 additions & 0 deletions etc/test-module-updater.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const fs = require('fs')
const os = require('os')
const path = require('path')

const testDir = process.argv[2]

const modules = fs
.readdirSync(testDir)
.forEach(f => {
const moduleFile = path.join(testDir, f)
const moduleName = f.replace(/.purs$/, '')

const module = fs.readFileSync(moduleFile, 'utf8')

const moduleMod = module.replace(
/module Test\.Main where/,
'module Test.' + moduleName + ' where')

fs.writeFileSync(moduleFile, moduleMod)
})
19 changes: 15 additions & 4 deletions exercises/accumulate/test/Main.purs
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,27 @@ module Test.Main where

import Prelude
import Control.Monad.Eff (Eff)
import Test.Unit (suite, test)
import Control.Monad.Eff.AVar (AVAR)
import Control.Monad.Eff.Console (CONSOLE)
import Test.Unit (TestSuite, suite, test)
import Test.Unit.Console (TESTOUTPUT)
import Test.Unit.Main (runTest)
import Test.Unit.Assert as Assert
import Data.List (List(Nil), fromFoldable)
import Data.String as String
import Accumulate (accumulate)


main :: Eff _ Unit
main = runTest do
main :: forall eff
. Eff ( avar :: AVAR
, console :: CONSOLE
, testOutput :: TESTOUTPUT
| eff
)
Unit
main = runTest suites

suites :: forall e. TestSuite e
suites = do
suite "Accumulate.accumulate" do
test "empty accumulation" $
let
Expand Down
17 changes: 14 additions & 3 deletions exercises/acronym/test/Main.purs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,23 @@ import Prelude
import Test.Unit.Assert as Assert
import Acronym (abbreviate)
import Control.Monad.Eff (Eff)
import Test.Unit (suite, test)
import Control.Monad.Eff.AVar (AVAR)
import Control.Monad.Eff.Console (CONSOLE)
import Test.Unit (TestSuite, suite, test)
import Test.Unit.Console (TESTOUTPUT)
import Test.Unit.Main (runTest)

main :: forall eff
. Eff ( avar :: AVAR
, console :: CONSOLE
, testOutput :: TESTOUTPUT
| eff
)
Unit
main = runTest suites

main :: Eff _ Unit
main = runTest do
suites :: forall e. TestSuite e
suites = do
suite "Acronym.abbreviate" do
test "acronyms from title case" $
Assert.equal
Expand Down
18 changes: 15 additions & 3 deletions exercises/all-your-base/test/Main.purs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,26 @@ module Test.Main where

import Prelude
import Control.Monad.Eff (Eff)
import Control.Monad.Eff.AVar (AVAR)
import Control.Monad.Eff.Console (CONSOLE)
import Data.Maybe (Maybe(..))
import Test.Unit.Assert as Assert
import Test.Unit (suite, test)
import Test.Unit (TestSuite, suite, test)
import Test.Unit.Console (TESTOUTPUT)
import Test.Unit.Main (runTest)
import AllYourBase (rebase)

main :: Eff _ Unit
main = runTest do
main :: forall eff
. Eff ( avar :: AVAR
, console :: CONSOLE
, testOutput :: TESTOUTPUT
| eff
)
Unit
main = runTest suites

suites :: forall e. TestSuite e
suites = do
suite "AllYourBase.rebase" do

test "single bit one to decimal" $
Expand Down
20 changes: 15 additions & 5 deletions exercises/allergies/test/Main.purs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,25 @@ module Test.Main where

import Prelude
import Control.Monad.Eff (Eff)
import Data.Maybe (Maybe(..))
import Control.Monad.Eff.AVar (AVAR)
import Control.Monad.Eff.Console (CONSOLE)
import Test.Unit.Assert as Assert
import Test.Unit (suite, test)
import Test.Unit (TestSuite, suite, test)
import Test.Unit.Console (TESTOUTPUT)
import Test.Unit.Main (runTest)
import Allergies (allergicTo, list)

main :: Eff _ Unit
main = runTest do

main :: forall eff
. Eff ( avar :: AVAR
, console :: CONSOLE
, testOutput :: TESTOUTPUT
| eff
)
Unit
main = runTest suites

suites :: forall e. TestSuite e
suites = do
suite "Allergies.allergicTo" do

test "no allergies means not allergic" $
Expand Down
Loading