Utilities

Provide some utility macros and functions for the ACTest toolkit.

Contents

Index

Color Constants

ACTest.COLORSConstant
COLORS

A global dict, which is used to specify the system colors.

ACTest.MODESConstant
MODES

A global dict, which is used to specify the mode for output characters.

Macros

ACTest.@cswitchMacro
@cswitch(constexpr, body)

Provides a C-like switch statement with the falling through behavior. This implementation was borrowed from the following github repository:

  • https://github.com/Gnimuc/CSyntax.jl

Examples

engine = get_d("engine")
@cswitch engine begin
    @case "vasp"
        just_do_it()
        break

    @default
        sorry()
        break
end
ACTest.@time_callMacro
@time_call(ex)

Evaluate a function call (ex), and then print the elapsed time (number of seconds) it took to execute.

This macro is a variation of the standard @elapsed macro.

ACTest.@pcsMacro
@pcs(x...)

Try to print colorful strings. Here x is a combination of strings and colors. Its format likes string1 color1 string2 color2 (repeat). For the supported colors, please check the global dict COLORS.

Examples

julia> @pcs "Hello world!" blue
julia> @pcs "Hello " red "world!" green

See also: COLORS, welcome.

Query Runtime Environment

ACTest.requireFunction
require()

Check the version of julia runtime environment. It should be higher than v1.6.x. One of the most important philosophies of the ACTest toolkit is minimizing the dependence on the third-party libraries as far as possible. Note that the ACTest toolkit relys on the TOML package to parse the *.toml file. Only in v1.6.0 and higher versions, julia includes the TOML package in its standard library.

Arguments

N/A

Returns

N/A

ACTest.setup_argsFunction
setup_args(x::Vararg{String})

Setup ARGS manually. This function is used only in REPL environment. We can use this function to update ARGS, so that the query_args() and the other related functions can work correctly.

Arguments

  • x -> Filename of configuration file.

Returns

  • ARGS -> Global variable.

Examples

julia> setup_args("act.toml")
1-element Array{String,1}:
 "act.toml"

See also: query_args.

ACTest.query_argsFunction
query_args()

Check whether the configuration file (case.toml) is provided.

Arguments

N/A

Returns

  • x -> ARGS[1], where ARGS is a global variable.

See also: setup_args.

Colorful Outputs

ACTest.welcomeFunction
welcome()

Print out the welcome messages to the screen.

Arguments

N/A

Returns

N/A

ACTest.overviewFunction
overview()

Print out the overview of ACTest to the screen.

Arguments

N/A

Returns

N/A

ACTest.goodbyeFunction
goodbye()

Print the goodbye messages to the screen.

Arguments

N/A

Returns

N/A

ACTest.sorryFunction
sorry()

Print an error message to the screen.

Arguments

N/A

Returns

N/A

ACTest.promptFunction
prompt(msg::String)

Print a stylized ACTest message to the screen.

Arguments

  • msg -> Message that need to be printed.

Returns

N/A

Input/output Operations

ACTest.line_to_arrayFunction
line_to_array(io::IOStream)

Convert a line (reading from an IOStream) to a string array.

Arguments

  • io -> An IOStream struct.

Returns

  • arr -> An array of String.
line_to_array(str::AbstractString)

Convert a string (AbstractString) to a string array.

Arguments

  • str -> A String.

Returns

  • ass -> An array of String.

Examples

julia> str = "Hello World!"
"Hello World!"

julia> line_to_array(str)
2-element Vector{SubString{String}}:
 "Hello"
 "World!"

Color Tools

ACTest.colorizeFunction
colorize(
    c::String,
    s::String;
    bg::String = "default",
    m::String = "default"
)

Return some escape sequences, which will be displayed as colorized texts in the terminal.

Arguments

  • c -> Color names.
  • s -> The string that want to be printed.
  • bg -> Background color.
  • m -> Output mode.

Returns

  • See above explanations.
colorize(
    c::Symbol,
    s::String;
    bg::String = "default",
    m::String = "default"
)

Return some escape sequences, which will be displayed as colorized texts in the terminal.

Arguments

  • c -> Color names.
  • s -> The string that want to be printed.
  • bg -> Background color.
  • m -> Output mode.

Returns

  • See above explanations.