|
| 1 | +#!/usr/bin/env bats |
| 2 | +# shellcheck disable=SC2164 |
| 3 | + |
| 4 | +load '../helper' |
| 5 | + |
| 6 | +sep="$JAVA_PATH_SEPARATOR" |
| 7 | +AGENT_JAR="$(find_agent_jar)" |
| 8 | +java_cmd="java -cp ${BATS_TEST_DIRNAME}/build -javaagent:'${AGENT_JAR}'" |
| 9 | + |
| 10 | +setup() { |
| 11 | + cd "${BATS_TEST_DIRNAME}" |
| 12 | + # Compile tests. Output to test/encoding so package structure 'pkg' works. |
| 13 | + # We need to compile both UnicodeTest.java and pkg/Target.java. |
| 14 | + javac -d ./build UnicodeTest.java |
| 15 | + |
| 16 | + # Compile ReadFullyTest, requiring the agent jar on the classpath |
| 17 | + javac -cp "${AGENT_JAR}" -d ./build ReadFullyTest.java |
| 18 | + |
| 19 | + rm -rf "${BATS_TEST_DIRNAME}/tmp/appmap" |
| 20 | + _configure_logging |
| 21 | +} |
| 22 | + |
| 23 | +@test "AppMap file encoding with Windows-1252" { |
| 24 | + # Run with windows-1252 encoding. |
| 25 | + # We assert that the generated file is valid UTF-8 and contains the correct characters, |
| 26 | + # even though the JVM default encoding is Windows-1252. |
| 27 | + local cmd="${java_cmd} -Dfile.encoding=windows-1252 -Dappmap.recording.auto=true test.pkg.UnicodeTest" |
| 28 | + [[ $BATS_VERBOSE_RUN == 1 ]] && echo "cmd: $cmd" >&3 |
| 29 | + |
| 30 | + eval "$cmd" |
| 31 | + |
| 32 | + # Verify the output file exists — it should be the only AppMap file generated, with random name |
| 33 | + # so glob for tmp/appmap/java/*.appmap.json |
| 34 | + appmap_file=$(ls tmp/appmap/java/*.appmap.json) |
| 35 | + [ -f "$appmap_file" ] |
| 36 | + |
| 37 | + # Verify it is valid JSON |
| 38 | + jq . "$appmap_file" > /dev/null |
| 39 | + |
| 40 | + # Verify it is valid UTF-8 |
| 41 | + iconv -f UTF-8 -t UTF-8 "$appmap_file" > /dev/null |
| 42 | + |
| 43 | + # Verify it contains the expected Unicode characters |
| 44 | + grep -q "Euro: €, Accent: é, Quote: „" "$appmap_file" |
| 45 | +} |
| 46 | + |
| 47 | +@test "Recording.readFully works with Windows-1252 default encoding" { |
| 48 | + # Run ReadFullyTest with windows-1252 default encoding. |
| 49 | + # We also need to add the agent jar to the classpath so it can find the Recording class. |
| 50 | + local cmd="java -cp ${BATS_TEST_DIRNAME}/build${sep}${AGENT_JAR} -Dfile.encoding=windows-1252 test.pkg.ReadFullyTest" |
| 51 | + [[ $BATS_VERBOSE_RUN == 1 ]] && echo "cmd: $cmd" >&3 |
| 52 | + |
| 53 | + run eval "$cmd" |
| 54 | + |
| 55 | + [ "$status" -eq 0 ] |
| 56 | + [[ "$output" == *"Check: ⚠️ Привет"* ]] |
| 57 | +} |
| 58 | + |
| 59 | +teardown() { |
| 60 | + rm -rf tmp |
| 61 | + rm -rf build |
| 62 | +} |
0 commit comments