Verified Commit ecd561ca authored by Camil Staps's avatar Camil Staps 🚀

Several checks on Builtin.Syntax in CI

parent 6a5b5f37
Pipeline #18102 passed with stages
in 18 minutes and 45 seconds
......@@ -16,3 +16,5 @@ typetree.dot
cloogle.log
db/storage/
cache
test/builtin_syntax
variables:
GIT_SUBMODULE_STRATEGY: recursive
stages:
- check
- build
style syntax documentation:
stage: check
image: camilstaps/clean:nightly
only:
changes:
- backend/Builtin/Syntax.icl
script:
- cd backend
- ./install_clean.sh
- cd ../test
- make test
backend:
stage: build
image: camilstaps/clean:nightly
script:
- cd backend
......@@ -13,12 +30,14 @@ backend:
- backend/typetree.dot
frontend:
stage: build
image: php:apache
script:
- cd frontend
- ./build.sh
stats:
stage: build
image: debian:stretch
script:
- cd stats
......
This diff is collapsed.
Subproject commit 13dae5a9925385784d5dfd1a38d92cdfa6b7dc05
Subproject commit 6297f08b2b5dbd66face8a15f9df24c3a8d670b1
#!/bin/bash
set -ev
PATCHCLEANBUILD="sed -i 's:clean-compiler-and-rts compiler itask:cstaps compiler master:' clean-base/linux-x64/git-sources.txt; sed -i 's:compiler-itask:compiler-master:' clean-base/linux-x64/build.sh; sed -i 's:master:cloogle:' clean-lib-platform/linux-x64/git-sources.txt; sed -i 's:platform-master:platform-cloogle:' clean-lib-platform/linux-x64/build.sh" install_clean.sh 'base lib-platform lib-tcpip' 2018-12-28
./install_clean.sh
sed -i 's/cocl/cocl::-wmf/' /opt/clean/etc/IDEEnvs
PACKAGES="patch jq unzip z3"
......
#!/bin/bash
set -ev
PATCHCLEANBUILD="sed -i 's:clean-compiler-and-rts compiler itask:cstaps compiler master:' clean-base/linux-x64/git-sources.txt; sed -i 's:compiler-itask:compiler-master:' clean-base/linux-x64/build.sh; sed -i 's:master:cloogle:' clean-lib-platform/linux-x64/git-sources.txt; sed -i 's:platform-master:platform-cloogle:' clean-lib-platform/linux-x64/build.sh" install_clean.sh 'base lib-dynamics lib-platform lib-tcpip' 2019-01-27
CLM:=clm
CLMFLAGS:=-nr -nt\
-I ../backend\
-I ../backend/Cloogle\
-I ../backend/Cloogle/libcloogle\
-I ../backend/Cloogle/CleanRegex\
-IL Platform
BIN:=builtin_syntax
TEST:=$(addprefix test_,$(BIN))
test: $(TEST)
$(TEST): test_%: %
./$<
$(BIN): .FORCE
$(CLM) $(CLMFLAGS) $@ -o $@
.FORCE:
.PHONY: test .FORCE
module builtin_syntax
import StdEnv
import StdMaybe
import Clean.Types
import Clean.Types.Parse
from Data.Func import mapSt, seqSt
import Data.List
import System.CommandLine
import System.Directory
import System.File
import System.FilePath
import System.Process
import Text
from Cloogle.API import :: SyntaxExample{..}
import Cloogle.DB
import Builtin.Syntax
DOT_SUCCESS :== "\033[0;32m.\033[0m"
DOT_FAILURE :== "\033[0;31mF\033[0m"
DOT_SKIPPED :== "\033[0;33ms\033[0m"
MSG_SUCCESS :== "\033[0;32m OK\033[0m"
MSG_FAILURE :== "\033[0;31m failed!\033[0m"
DIRECTORY :== "examples"
CLMFLAGS =:
[ "-c"
, "-dynamics"
, "-IL", "Dynamics"
, "-IL", "Platform"
]
Start w
# (_,w) = ensureDirectoryExists DIRECTORY w
# (_,failed,w) = seqSt test builtin_syntax (0,0,w)
= case failed of
0
# (_,w) = recursiveDelete DIRECTORY w
-> w
_
# (_,w) = fclose
(stderr
<<< "Some tests failed. If test numbers are given, you can check the errors with:\n"
<<< "\tcd " <<< DIRECTORY <<< "\n"
<<< "\tclm " <<< join " " CLMFLAGS <<< " _example<number>\n")
w
-> setReturnCode -1 w
test :: !SyntaxEntry !*(!Int, !Int, !*World) -> *(!Int, !Int, !*World)
test se (i,failed,w)
# (comments_ok,i,w) = check_style se (i,w)
# failed = failed + if comments_ok 0 1
# err = stderr <<< "Checking syntax for '" <<< se.syntax_title <<< "': "
# (_,w) = fclose err w
# (results,(j,w)) = mapSt test_example se.syntax_examples (i,w)
# err = stderr
<<< if (and results)
MSG_SUCCESS
(MSG_FAILURE +++ " (" +++ join ", " [toString (n+i) \\ n <- [0..] & False <- results] +++ ")")
<<< "\n"
# (_,w) = fclose err w
= (j,failed + length [f \\ f=:False <- results],w)
check_style :: !SyntaxEntry !*(!Int, !*World) -> *(!Bool, !Int, !*World)
check_style se (i,w)
# err = stderr
# err = if comment_alignment_ok
err
(err
<<< "\033[0;31mComment alignment is inconsistent for '"
<<< se.syntax_title
<<< "' (at most two different levels may be used):\033[0m\n\t"
<<< join "\n\t" example_lines
<<< "\n")
# err = case no_spaces_around_comments of
[] -> err
ns -> err
<<< "\033[0;31mThese lines in '"
<<< se.syntax_title
<<< "' contain comments without spaces around the '//':\033[0m\n\t"
<<< join "\n\t" ns
<<< "\n"
# err = case missing_spaces of
[] -> err
ns -> err
<<< "\033[0;31mThese lines in '"
<<< se.syntax_title
<<< "' contain list comprehension elements without spaces around them:\033[0m\n\t"
<<< join "\n\t" ns
<<< "\n"
# (_,w) = fclose err w
= (True,i+1,w)
where
example_lines = concatMap (split "\n") [replaceSubString "\t" " " e.example \\ e <- se.syntax_examples]
comment_alignment_ok = length (removeDup comments) < 3
where
comments = filter ((<>) -1) [indexOf "//" l \\ l <- example_lines]
no_spaces_around_comments = filter bad example_lines
where
bad s = case indexOf "//" s of
-1 -> False
i -> s.[i-1] <> ' ' || s.[i+2] <> ' '
missing_spaces = filter bad example_lines
where
bad s
# s = replaceSubString "'\\\\'" "" s // special case for '\\' in basic_values
# (results,_) = mapSt check ["<|-","<-:","<-","\\\\"] s
= or results
check op s
# new = replaceSubString (" " +++ op +++ " ") "" s
= (indexOf op new >= 0, new)
test_example :: !SyntaxExample !*(!Int, !*World) -> *(!Bool, !*(!Int, !*World))
test_example {example,cleanjs_start,bootstrap,requires_itask_compiler} (i,w)
| requires_itask_compiler
|| indexOf "not allowed" (toLowerCase example) >= 0 // examples that are marked as not allowed by the compiler
|| startsWith "definition module " example // module headings
|| startsWith "implementation module " example
|| startsWith "system module " example
|| startsWith "module " example
# (_,w) = fclose (stderr <<< DOT_SKIPPED) w
= (True, (i+1,w))
# dcl = join "\n"
[ "definition module _example" <+ i
: [b \\ b <- bootstrap | startsWith "import " b]
++ case split "special" example of
[_]
| indexOf "(:==" example > 0
-> [example] // abstract synonym type
-> [l \\ l <- split "\n" example
| startsWith "derive " l && indexOf " with " l > 0
|| startsWith "generic " l]
[_:_]
-> [example]
]
# icl = join "\n"
[ "implementation module _example" <+ i
: bootstrap
++ case cleanjs_start of
Nothing -> complete_icl example
Just "macro" -> complete_icl example
Just "rhs" -> ["Start = " +++ example]
Just "macrorhs" -> ["Start = " +++ example]
Just s -> ["unknown cleanjs_start " +++ s]
]
# (_,w) = writeFile (DIRECTORY </> "_example" <+ i <+ ".dcl") dcl w
# (_,w) = writeFile (DIRECTORY </> "_example" <+ i <+ ".icl") icl w
# (Ok (h,_),w) = runProcessIO "clm" (CLMFLAGS ++ ["_example" <+ i]) (Just DIRECTORY) w
# (Ok r,w) = waitForProcess h w
# ok = r == 0
# (_,w) = fclose (stderr <<< if ok DOT_SUCCESS DOT_FAILURE) w
= (ok,(i+1,w))
where
complete_icl :: !String -> [String]
complete_icl example
| startsWith "foreign export " example =
[ name +++ " :: Int"
, name +++ " = 0"
] with name = example % (15, indexOfAfter 15 " " example)
| indexOf "(:==" example > 0 = // abstract synonym type
[replaceSubString "(:==" ":==" (example % (0,size example-2))]
# example = hd (split "special" example)
| example.[0] == '(' && indexOf ") =" example > 0 = // pattern
[ "tempfun = " +++ (example % (0,indexOf ") =" example + 1))
, "where"
, "\t" +++ replaceSubString "\n" "\n\t" example
]
# lines = split "\n" example
| length lines == 1
# line = hd lines
# line = case indexOf "//" line of
-1 -> line
i -> trim (line % (0, i-1))
# doublecolon = indexOf "::" line
| doublecolon > 0
&& not (startsWith "generic " line || startsWith "class " line)
// function without implementation
= case parseType [c \\ c <-: line & i <- [0..] | i > doublecolon+2] of
Just (Func is _ _) ->
[ line
, line % (0,indexOf " " line) +++ join " " ["_" \\ _ <- is] +++ " = undef"
, "from StdMisc import undef"
]
_ ->
[ line
, line % (0,indexOf " " line) +++ " = undef"
, "from StdMisc import undef"
]
= lines
= [l \\ l <- lines | not (startsWith "derive " l && indexOf " with " l > 0)]
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment