Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
bjuric committed Nov 5, 2024
1 parent 8caba11 commit cfe9bf5
Show file tree
Hide file tree
Showing 79 changed files with 169 additions and 187 deletions.
3 changes: 2 additions & 1 deletion .sbtopts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
-J-XX:MaxMetaspaceSize=1024M
-J-Djansi.passthrough=true
-J-Dpolyglot.engine.WarnInterpreterOnly=false
-J-Dpolyglot.engine.WarnInterpreterOnly=false
-J-Xshare:off
4 changes: 3 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,6 @@ Compile / packageBin / mappings ++= Seq(
file("CHANGELOG") -> "CHANGELOG.txt"
)

Test/ parallelExecution := false
Test / parallelExecution := false

Test / testOptions += Tests.Argument("-oF")
2 changes: 1 addition & 1 deletion src/main/scala/gwen/GwenInterpreter.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2014-2023 Branko Juric, Brady Wood
* Copyright 2014-2024 Branko Juric, Brady Wood
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
4 changes: 2 additions & 2 deletions src/main/scala/gwen/core/GwenErrors.scala
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ object Errors extends LazyLogging {
private def at(location: String): String = if (location.length > 0) s" [at $location]" else ""

/** Base exception\. */
class GwenException (msg: String, cause: Throwable = null) extends RuntimeException(msg, cause)
class GwenException (msg: String, cause: Throwable = null) extends RuntimeException(Formatting.stripZeroChar(msg), cause)

/** Signals a step that failed to execute. */
class StepException(step: Step, msg: String, cause: Throwable = null) extends GwenException(s"$msg${if(msg.endsWith(at(step.sourceRef))) "" else at(step.sourceRef)}", cause)
Expand Down Expand Up @@ -316,7 +316,7 @@ object Errors extends LazyLogging {
class CopyResourceException(msg: String) extends GwenException(msg)

/** Thrown when an assertion fails. */
class GwenAssertionError(val msg: String, val mode: AssertionMode) extends AssertionError(msg)
class GwenAssertionError(val msg: String, val mode: AssertionMode) extends AssertionError(Formatting.stripZeroChar(msg))

/** Thrown when an accumulated assertion error is raised. */
class AccumulatedAssertionError(error: GwenAssertionError) extends GwenAssertionError(error.msg, error.mode)
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/gwen/core/GwenInfo.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2015-2021 Branko Juric, Brady Wood
* Copyright 2015-2024 Branko Juric, Brady Wood
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/gwen/core/GwenOptions.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2014-2021 Branko Juric, Brady Wood
* Copyright 2014-2024 Branko Juric, Brady Wood
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/gwen/core/GwenSettings.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2014-2021 Branko Juric, Brady Wood
* Copyright 2014-2024 Branko Juric, Brady Wood
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/gwen/core/Interpolator.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2015-2022 Branko Juric, Brady Wood
* Copyright 2015-2024 Branko Juric, Brady Wood
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
10 changes: 6 additions & 4 deletions src/main/scala/gwen/core/Predefs.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2020-2023 Branko Juric, Brady Wood
* Copyright 2020-2024 Branko Juric, Brady Wood
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -69,7 +69,7 @@ extension [F <: File](file: F) {
file tap { f =>
f.newFileWriter(append) tap { fw =>
try {
fw.write(text)
fw.write(Formatting.stripZeroChar(text))
} finally {
fw.close()
}
Expand All @@ -87,7 +87,7 @@ extension [F <: File](file: F) {
new PrintWriter(fw) tap { pw =>
try {
line match {
case Some(l) => pw.println(l)
case Some(l) => pw.println(Formatting.stripZeroChar(l))
case None => pw.println()
}
} finally {
Expand Down Expand Up @@ -294,6 +294,8 @@ object Formatting {

val ZeroChar = '‎' // zero width space char

def stripZeroChar(s: String) = s.replaceAll(ZeroChar.toString, "")

/**
* Formats durations for presentation purposes.
*/
Expand Down Expand Up @@ -551,7 +553,7 @@ enum LocationType:
object Assert {
def apply(assertion: Boolean, message: => String): Unit = {
if (!assertion)
throw new java.lang.AssertionError(message)
throw new java.lang.AssertionError(Formatting.stripZeroChar(message))
}
def formatFailed(source: String, expected: String, actual: String, negate: Boolean, operator: ComparisonOperator): String = {
s"$source should ${if(negate) "not " else ""}$operator ${ValueLiteral.orQuotedValue(expected)}${if (operator == ComparisonOperator.be && actual == expected) "" else s" but ${if (operator == ComparisonOperator.be) "got" else "value was"} ${ValueLiteral.orQuotedValue(actual)}"}"
Expand Down
32 changes: 16 additions & 16 deletions src/main/scala/gwen/core/Settings.scala
Original file line number Diff line number Diff line change
Expand Up @@ -117,20 +117,15 @@ object Settings extends LazyLogging {
// store orphaned properties so we don't lose a.b=x if a.b.c=y is loaded
orphans.entrySet.asScala foreach { entry =>
val name = entry.getKey.toString
if (!name.contains("\"")) configProps.setProperty(name, entry.getValue.toString)
if (!name.contains("\"")) set(name, entry.getValue.toString)
}

names map { name =>
(name, name.replaceAll("\"", ""))
} foreach { (name, parsedName) =>
if (SensitiveData.isMaskedName(parsedName)) {
SensitiveData.parse(parsedName, get(name)) foreach { case (mKey, mValue) =>
configProps.setProperty(mKey, mValue)
}
}
else if (name != parsedName) {
configProps.setProperty(parsedName, resolve(config.getString(name)))
}
// store quoted or masked settings
names flatMap { name =>
val rawName = name.replaceAll("\"", "")
if (name != rawName || SensitiveData.isMaskedName(rawName)) Some((name, rawName)) else None
} foreach { (name, rawName) =>
set(rawName, getOpt(name).getOrElse(resolve(config.getString(name))))
}
}

Expand Down Expand Up @@ -172,7 +167,9 @@ object Settings extends LazyLogging {
Option(localSettings.get.getProperty(name)) orElse {
sys.props.get(name) orElse {
Option(configProps.getProperty(name)) orElse {
Try(config.getString(name)).map(v => Option(v)).getOrElse(None)
Try(config.getString(name)).map(v => Option(v)).getOrElse {
SensitiveData.maskedValue(name)
}
}
}
} map resolve
Expand Down Expand Up @@ -405,7 +402,9 @@ object Settings extends LazyLogging {
* @param value the value to bind to the setting
*/
def set(name: String, value: String): Unit = {
configProps.setProperty(name, value)
if (SensitiveData.parse(name, value).isEmpty) {
configProps.setProperty(name, value)
}
}

/**
Expand All @@ -416,8 +415,9 @@ object Settings extends LazyLogging {
*/
def setLocal(name: String, value: String): Unit = {
if (!name.startsWith("gwen.")) Errors.unsupportedLocalSetting(name)
val (n, v) = SensitiveData.parse(name, value).getOrElse((name, value))
localSettings.get.setProperty(n, v)
if (SensitiveData.parse(name, value).isEmpty) {
localSettings.get.setProperty(name, value)
}
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/gwen/core/ValueLiteral.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023 Branko Juric, Brady Wood
* Copyright 2023-2024 Branko Juric, Brady Wood
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/gwen/core/eval/EvalContext.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2015-2023 Branko Juric, Brady Wood
* Copyright 2015-2024 Branko Juric, Brady Wood
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
30 changes: 15 additions & 15 deletions src/main/scala/gwen/core/eval/EvalEngine.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2014-2021 Branko Juric, Brady Wood
* Copyright 2014-2024 Branko Juric, Brady Wood
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -123,7 +123,7 @@ abstract class EvalEngine[T <: EvalContext] extends NodeEventDispatcher with Uni
*/
override def translateStep(step: Step): UnitStep[T] = {
step.expression match {
case r"""my (.+?)$name (?:property|setting) (?:is|will be) "(.*?)"$value""" =>
case r"""my (.+?)$name (?:property|setting) is "(.*?)"$value""" =>
new SetProperty(name, value)
case r"""I reset my (.+?)$name (?:property|setting)""" =>
new ClearProperty(name)
Expand Down Expand Up @@ -177,31 +177,31 @@ abstract class EvalEngine[T <: EvalContext] extends NodeEventDispatcher with Uni
new CaptureBase64Decoded(name, attribute)
case r"""I base64 decode (.+?)$attribute""" =>
new CaptureBase64Decoded(attribute, attribute)
case r"""(.+?)$attribute (?:is|will be) defined by system process "(.+?)"$expression delimited by "(.+?)"$delimiter""" =>
case r"""(.+?)$attribute is defined by system process "(.+?)"$expression delimited by "(.+?)"$delimiter""" =>
new BindAsType(attribute, BindingType.sysproc, expression, None, Some(delimiter), step.isMasked)
case r"""(.+?)$attribute (?:is|will be) defined by (javascript|js|system process|unix system process|property|setting)$attrType "(.+?)"$expression""" =>
case r"""(.+?)$attribute is defined by (javascript|js|system process|unix system process|property|setting)$attrType "(.+?)"$expression""" =>
new BindAsType(attribute, BindingType.parse(attrType), step.orDocString(expression), None, None, step.isMasked)
case r"""(.+?)$attribute (?:is|will be) defined by file "(.+?)"$filepath""" =>
case r"""(.+?)$attribute is defined by file "(.+?)"$filepath""" =>
new BindAsType(attribute, BindingType.file, step.orDocString(filepath), None, None, step.isMasked)
case r"""(.+?)$attribute (?:is|will be) defined by (.+?)$enc file "(.+?)"$filepath""" =>
case r"""(.+?)$attribute is defined by (.+?)$enc file "(.+?)"$filepath""" =>
new BindAsType(attribute, BindingType.file, step.orDocString(filepath), Some(enc), None, step.isMasked)
case r"""(.+?)$attribute (?:is|will be) defined by (.+?)$function applied to "(.+?)"$args delimited by "(.*)"$delimiter""" =>
case r"""(.+?)$attribute is defined by (.+?)$function applied to "(.+?)"$args delimited by "(.*)"$delimiter""" =>
new BindAsType(attribute, BindingType.function, function, Some(args), Some(delimiter), step.isMasked)
case r"""(.+?)$attribute (?:is|will be) defined by (.+?)$function applied to "(.*)"$arg""" =>
case r"""(.+?)$attribute is defined by (.+?)$function applied to "(.*)"$arg""" =>
new BindAsType(attribute, BindingType.function, function, Some(step.orDocString(arg)), None, step.isMasked)
case r"""(.+?)$attribute (?:is|will be) defined by the (text|node|nodeset)$targetType in (.+?)$source by xpath "(.+?)"$expression""" =>
case r"""(.+?)$attribute is defined by the (text|node|nodeset)$targetType in (.+?)$source by xpath "(.+?)"$expression""" =>
new BindAsXPath(attribute, step.orDocString(expression), targetType, source, step.isMasked)
case r"""(.+?)$attribute (?:is|will be) defined in (.+?)$source by regex "(.+?)"$expression""" =>
case r"""(.+?)$attribute is defined in (.+?)$source by regex "(.+?)"$expression""" =>
new BindAsRegex(attribute, step.orDocString(expression), source, step.isMasked)
case r"""(.+?)$attribute (?:is|will be) defined in (.+?)$source by json path "(.+?)"$expression""" =>
case r"""(.+?)$attribute is defined in (.+?)$source by json path "(.+?)"$expression""" =>
new BindAsJsonPath(attribute, step.orDocString(expression), source, step.isMasked)
case r"""(.+?)$attribute (?:is|will be) defined by sql "(.+?)"$selectStmt in the (.+?)$dbName database""" =>
case r"""(.+?)$attribute is defined by sql "(.+?)"$selectStmt in the (.+?)$dbName database""" =>
new BindAsSQL(attribute, dbName, selectStmt, step.isMasked)
case r"""(.+?)$attribute (?:is|will be) defined in the (.+?)$dbName database by sql "(.+?)"$selectStmt""" =>
case r"""(.+?)$attribute is defined in the (.+?)$dbName database by sql "(.+?)"$selectStmt""" =>
new BindAsSQL(attribute, dbName, step.orDocString(selectStmt), step.isMasked)
case r"""(.+?)$attribute (?:is|will be) "(.*?)"$value""" =>
case r"""(.+?)$attribute is "(.*?)"$value""" =>
new BindAttribute(attribute, step.orDocString(value))
case r"""(.+?)$attribute (?:is|will be) (blank|empty|true|false)$literal""" =>
case r"""(.+?)$attribute is (blank|empty|true|false)$literal""" =>
new BindAttribute(attribute, ValueLiteral.valueOf(literal).value)
case r"""I update the (.+?)$dbName database by sql "(.+?)"$updateStmt""" =>
new UpdateBySQL(dbName, step.orDocString(updateStmt))
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/gwen/core/eval/GwenLauncher.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2014-2021 Branko Juric, Brady Wood
* Copyright 2014-2024 Branko Juric, Brady Wood
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/gwen/core/eval/GwenREPL.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2014-2023 Branko Juric, Brady Wood
* Copyright 2014-2024 Branko Juric, Brady Wood
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/gwen/core/eval/binding/Binding.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2021 Branko Juric, Brady Wood
* Copyright 2021-2024 Branko Juric, Brady Wood
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2021 Branko Juric, Brady Wood
* Copyright 2021-2024 Branko Juric, Brady Wood
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/gwen/core/eval/binding/BindingType.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2021 Branko Juric, Brady Wood
* Copyright 2021-2024 Branko Juric, Brady Wood
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2021 Branko Juric, Brady Wood
* Copyright 2021-2024 Branko Juric, Brady Wood
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2021 Branko Juric, Brady Wood
* Copyright 2021-2024 Branko Juric, Brady Wood
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023 Branko Juric, Brady Wood
* Copyright 2023-2024 Branko Juric, Brady Wood
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/gwen/core/eval/binding/FileBinding.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2021 Branko Juric, Brady Wood
* Copyright 2021-2024 Branko Juric, Brady Wood
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/gwen/core/eval/binding/JSBinding.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2021-2022 Branko Juric, Brady Wood
* Copyright 2021-2024 Branko Juric, Brady Wood
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2021-2022 Branko Juric, Brady Wood
* Copyright 2021-2024 Branko Juric, Brady Wood
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2021 Branko Juric, Brady Wood
* Copyright 2021-2024 Branko Juric, Brady Wood
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/gwen/core/eval/binding/RegexBinding.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2021 Branko Juric, Brady Wood
* Copyright 2021-2024 Branko Juric, Brady Wood
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/gwen/core/eval/binding/SQLBinding.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2021 Branko Juric, Brady Wood
* Copyright 2021-2024 Branko Juric, Brady Wood
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/gwen/core/eval/binding/SysprocBinding.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2021 Branko Juric, Brady Wood
* Copyright 2021-2024 Branko Juric, Brady Wood
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/gwen/core/eval/binding/XPathBinding.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2021 Branko Juric, Brady Wood
* Copyright 2021-2024 Branko Juric, Brady Wood
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/gwen/core/eval/engine/StepEngine.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2021-2023 Branko Juric, Brady Wood
* Copyright 2021-2024 Branko Juric, Brady Wood
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/gwen/core/eval/engine/UnitEngine.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2021 Branko Juric, Brady Wood
* Copyright 2021-2024 Branko Juric, Brady Wood
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2021-2023 Branko Juric, Brady Wood
* Copyright 2021-2024 Branko Juric, Brady Wood
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2021 Branko Juric, Brady Wood
* Copyright 2021-2024 Branko Juric, Brady Wood
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2021 Branko Juric, Brady Wood
* Copyright 2021-2024 Branko Juric, Brady Wood
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Loading

0 comments on commit cfe9bf5

Please sign in to comment.