Skip to content
This repository has been archived by the owner on Jan 27, 2025. It is now read-only.

Commit

Permalink
Merge remote-tracking branch 'origin/master' into 102-path
Browse files Browse the repository at this point in the history
  • Loading branch information
fsteeg committed Mar 4, 2022
2 parents 692b4f9 + 02652c9 commit bc59bf4
Show file tree
Hide file tree
Showing 606 changed files with 3,920 additions and 61 deletions.
5 changes: 4 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,8 @@ indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true

[*.{fix,gradle,sh,yml}]
[*.{fix,gradle,json,md,mwe2,sh,vim,xtext,yml}]
indent_size = 2

[*.tmLanguage]
indent_style = tab
2 changes: 2 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ jobs:
run: chmod +x gradlew
- name: Build with Gradle
run: ./gradlew build
env:
METAFIX_LOG_PASSED: true
- name: Install language server
run: ./gradlew installServer
- name: Install fix extension
Expand Down
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
.gradle/
bin/
build/
generated/
xtext-gen/
.project
.classpath
out/
node_modules/
xtext-server/
Expand Down
20 changes: 14 additions & 6 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,25 @@ plugins {

editorconfig {
excludes = [
'**/generated',
'**/xtext-gen',
'**/bin',
'**/*.out',
'**/*.vsix',
'**/.*',
'gradlew*',
'**/out',
'**/bin',
'**/generated',
'**/node_modules',
'**/*.vsix'
'**/out',
'**/output-*',
'**/xtext-gen',
'gradlew*'
]
}

task editorconfigChecker(type: Exec, group: 'Verification') {
executable 'misc/bin/editorconfig-checker'
args('-exclude', '/bin/|/\\.|^gradlew.*|^LICENSE$')
}

editorconfigCheck.dependsOn(editorconfigChecker)
check.dependsOn(editorconfigCheck)

subprojects {
Expand Down
4 changes: 3 additions & 1 deletion metafix/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ test {

task integrationTest(type: Exec, group: 'Verification') {
executable './integrationTest.sh'
if (project.hasProperty("args")) args project.getProperty("args").split()

if (project.hasProperty('args')) args project.getProperty('args').split()
environment.METAFIX_DISABLE_TO_DO = System.getProperty('org.metafacture.metafix.disableToDo')
}

task install(dependsOn: publishToMavenLocal, group: 'Publishing',
Expand Down
93 changes: 70 additions & 23 deletions metafix/integrationTest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ metafix_file=test.flux
catmandu_file=test.cmd

fix_file=test.fix
disabled_file=disabled.txt
todo_file=todo.txt

input_glob=input.*
expected_glob=expected.*
Expand All @@ -20,6 +20,12 @@ root_directory="$PWD"
data_directory="$root_directory/src/test/resources/org/metafacture/metafix/integration"
gradle_command="$root_directory/../gradlew"

function parse_boolean() {
[ "${1,,}" == true ]
}

parse_boolean "$METAFIX_DISABLE_TO_DO" && disable_todo=1 || disable_todo=

[ -t 1 -a -x /usr/bin/colordiff ] && colordiff=colordiff || colordiff=cat

function _tput() {
Expand Down Expand Up @@ -67,6 +73,27 @@ function run_catmandu() {
:
}

nanosecond_length=9
nanosecond_offset=-$nanosecond_length

function current_time() {
date +%s%N
}

function elapsed_time() {
local elapsed_time=$(($(current_time) - $1)) seconds=0 milliseconds

if [ ${#elapsed_time} -gt $nanosecond_length ]; then
seconds=${elapsed_time:0:$nanosecond_offset}
else
elapsed_time=$(printf "%0${nanosecond_length}d" "$elapsed_time")
fi

[ "$seconds" -lt 60 ] && milliseconds=".${elapsed_time:$nanosecond_offset:3}"

echo " ($(date "+%-Hh %-Mm %-S${milliseconds}s" -ud "@$seconds" | sed 's/^\(0[hm] \)*//'))"
}

function get_file() {
local test=$1 type=$2 reason; shift 2

Expand All @@ -91,13 +118,30 @@ function command_info() {

[ -s "$3" ] && log " ${color_info}${1^} command output$color_reset: $3" || rm -f "$3"
[ -s "$4" ] && log " ${color_info}${1^} command error$color_reset: $4" || rm -f "$4"

log
}

function skip_test() {
if [ -r "$2" ]; then
local message="$color_test$1$color_reset: ${color_skipped}SKIPPED$color_reset" reason=$(head -1 "$2")

[ -n "$reason" ] && message+=" ($reason)"
log "$message"

((skipped++)) || true

return 0;
else
return 1;
fi
}

function run_tests() {
local test matched=1\
test_input test_expected test_disabled\
metafix_command_output metafix_command_error\
metafix_exit_status metafix_output metafix_diff
test_directory test_fix test_input test_expected test_todo\
metafix_command_output metafix_command_error metafix_start_time\
metafix_exit_status metafix_output metafix_diff metafix_elapsed_time

cd "$data_directory"

Expand All @@ -117,16 +161,14 @@ function run_tests() {
get_file "$test" expected "$test_directory"/$expected_glob || { log; continue; }
test_expected=$current_file

test_disabled="$test_directory/$disabled_file"
test_todo="$test_directory/$todo_file"

if [ -r "$test_disabled" ]; then
log "$color_test$test$color_reset: ${color_skipped}SKIPPED$color_reset ($(<"$test_disabled"))"

((skipped++)) || true
else
if [ -z "$disable_todo" ] || ! skip_test "$test" "$test_todo"; then
metafix_command_output="$test_directory/metafix.out"
metafix_command_error="$test_directory/metafix.err"

metafix_start_time=$(current_time)

# TODO: catmandu (optional)

if run_metafix "$test_directory/$metafix_file" >"$metafix_command_output" 2>"$metafix_command_error"; then
Expand All @@ -136,16 +178,24 @@ function run_tests() {
metafix_output=$current_file
metafix_diff="$test_directory/metafix.diff"

metafix_elapsed_time=$(elapsed_time "$metafix_start_time")

if diff -u "$test_expected" "$metafix_output" >"$metafix_diff"; then
#log "$color_test$test$color_reset: ${color_passed}PASSED$color_reset"
if [ -r "$test_todo" ]; then
log "$color_test$test$color_reset: ${color_failed}FAILED$color_reset (Marked as \"to do\", but passed.)"

rm -f "$metafix_diff" "$metafix_command_output" "$metafix_command_error"
((failed++)) || true
else
if parse_boolean "$METAFIX_LOG_PASSED"; then
log "$color_test$test$color_reset: ${color_passed}PASSED$color_reset$metafix_elapsed_time"
fi

((passed++)) || true
((passed++)) || true
fi

#log
else
log "$color_test$test$color_reset: ${color_failed}FAILED$color_reset"
rm -f "$metafix_diff" "$metafix_command_output" "$metafix_command_error"
elif ! skip_test "$test" "$test_todo"; then
log "$color_test$test$color_reset: ${color_failed}FAILED$color_reset$metafix_elapsed_time"

log " Fix: $test_fix"
log " Input: $test_input"
Expand All @@ -158,24 +208,18 @@ function run_tests() {
command_info metafix "$metafix_exit_status" "$metafix_command_output" "$metafix_command_error"

((failed++)) || true

log
fi
else
command_info metafix "$metafix_exit_status" "$metafix_command_output" "$metafix_command_error"

log
fi
else
elif ! skip_test "$test" "$test_todo"; then
metafix_exit_status=$?

log "$color_test$test$color_reset: ${color_error}ERROR$color_reset"

command_info metafix "$metafix_exit_status" "$metafix_command_output" "$metafix_command_error"

((failed++)) || true

log
fi
fi
done
Expand All @@ -185,6 +229,8 @@ function run_tests() {
return $matched
}

start_time=$(current_time)

if [ $# -eq 0 ]; then
run_tests '*' || true
else
Expand All @@ -199,6 +245,7 @@ summary="${color_passed}$passed passed$color_reset"
summary+=", ${color_failed}$failed failed$color_reset"
summary+=", ${color_skipped}$skipped skipped$color_reset"
summary+=", ${color_invalid}$invalid invalid$color_reset"
summary+=$(elapsed_time "$start_time")

if [ $failed -gt 0 -o $invalid -gt 0 ]; then
log "${color_failure}FAILURE$color_reset: $summary"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"colors" : [ "Red is a nice color", "Green is a nice color", "Blue is a nice color" ]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"colors" : [ "red", "green", "blue" ]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
do list(path:"colors[]", "var": "$i")
append("$i", " is a nice color")
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FLUX_DIR + "input.json"
|open-file
|as-records
|decode-json
|fix(FLUX_DIR + "test.fix")
|encode-json(prettyPrinting="true")
|write(FLUX_DIR + "output-metafix.json")
;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
See issue #189
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"colors" : [ "red", "green", "blue" ],
"test" : [ "red", "green", "blue" ]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"colors" : [ "red", "green", "blue" ],
"test" : [ ]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
do list(path:"colors[]", "var": "$i")
copy_field("$i", "test[].$append")
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FLUX_DIR + "input.json"
|open-file
|as-records
|decode-json
|fix(FLUX_DIR + "test.fix")
|encode-json(prettyPrinting="true")
|write(FLUX_DIR + "output-metafix.json")
;
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"type" : "dog"
}
{
"type" : "video"
}
{
"type" : "book",
"test" : "test"
}
{
"type" : "stone"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"type" : "dog"
}
{
"type" : "video"
}
{
"type" : "book"
}
{
"type" : "stone"
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
if any_equal("type", "book")
add_field("test", "test")
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FLUX_DIR + "input.json"
|open-file
|as-records
|decode-json
|fix(FLUX_DIR + "test.fix")
|encode-json(prettyPrinting="true")
|write(FLUX_DIR + "output-metafix.json")
;
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"type" : [ "dog", "dog", "dog" ],
"test" : "test"
}
{
"type" : [ "video", "dog", "dog" ],
"test" : "test"
}
{
"type" : [ "book", "pc" ]
}
{
"type" : [ "human", "cat" ]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"type" : [ "dog", "dog", "dog" ]
}
{
"type" : [ "video", "dog", "dog" ]
}
{
"type" : [ "book", "pc" ]
}
{
"type" : [ "human", "cat" ]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
if all_contain("type[]", "o")
add_field("test", "test")
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FLUX_DIR + "input.json"
|open-file
|as-records
|decode-json
|fix(FLUX_DIR + "test.fix")
|encode-json(prettyPrinting="true")
|write(FLUX_DIR + "output-metafix.json")
;
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"type" : "dog"
}
{
"type" : "video",
"test" : "test"
}
{
"type" : "book"
}
{
"type" : "stone",
"test" : "test"
}
Loading

0 comments on commit bc59bf4

Please sign in to comment.